-1

I'm just lighting up an LED through a TIP31C, pin 0 goes through a 560kohm resistor to the tip's input pin pin 1 goes through a 750 ohm resistor to the tip's input pin ^i'm not sure this information is really relevant

The reason I am doing this is so i can sleep the attiny85 while having pin 0 set to HIGH to have the led at a very low brightness, kind of like a standby function

void setup() {

}

void loop() {
  digitalWrite(0, HIGH);//works ONLY the first time
  delay(500);
  digitalWrite(0, LOW);
  delay(500);

  analogWrite(1, 15);//always works
  delay(500);
  analogWrite(1, 0);
  delay(500);
  /*it's like as soon as i've used an analogWrite, i can no
    longer output with digitalWrite
  */

  //pinMode(0, OUTPUT);//didn't help
  digitalWrite(0, HIGH);//never works
  delay(500);
  digitalWrite(0, LOW);
  delay(500);
}
4
  • is there a problem of some kind? Commented Dec 30, 2019 at 20:21
  • @jsotola yes, I've put comments in the code explaining it Commented Dec 30, 2019 at 20:23
  • Try doing the pinMode in setup method. This is where it's supposed to be. Commented Dec 31, 2019 at 9:01
  • @FilipFranik I've tried that, it still doesn't work Commented Dec 31, 2019 at 17:29

1 Answer 1

1

There are a number of issues here:

  1. You state you have a 560kohm resistor, this is too high a value. With 5V it will restrict the current to 8.9uA.

    • This is too low to drive the LED, which probably requires up to 20mA (5V / 0.02A = 250Ohm at least)
    • This is also too low for for the base of the transistor (I'm not completely sure if my understanding of transistor gain is correct, but I think if you feed 1mA into the base of the TIP31C, it's gain of 25 will allow upto 25mA between the collector and emitter.) Based on this, 5V / 0.001A = 5kOhm.
  2. You do need pinMode(0, OUTPUT); and pinMode(A1, OUTPUT); in setup. It will work, except you won't notice the effect with your 560kOhm resistor.

  3. You also need to check the pins of the atTiny85. AtTiny85 pinout

As you can see, the only analog outputs are on physical pins 2, 3 and 7. You need to refer to these (for connection to pin 7) as:

pinMode(A1, OUTPUT);
analogWrite(A1, 15);

Below is a rough idea of what the schematic should look like

schematic

simulate this circuit – Schematic created using CircuitLab

And below is an (untested) example of the code:

void setup() {
  pinMode(A1, OUTPUT);
}

void loop() {
  analogWrite(A1, 15);
  delay(500);
  analogWrite(A1, 0);
  delay(500);
}
1
  • I think you confused the "analog output" (actually the Attiny85 does not have a real analog output, meaning DAC, Digital to Analog Converter. It can only output PWM voltages to mimick analog signals) with the pins of the ADC (Analog Digital Converter), which is basically an analog input. Commented Jan 1, 2020 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.