-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);
}
  • is there a problem of some kind? – jsotola Dec 30 '19 at 20:21
  • @jsotola yes, I've put comments in the code explaining it – Valkor Simpson Dec 30 '19 at 20:23
  • Try doing the pinMode in setup method. This is where it's supposed to be. – Filip Franik Dec 31 '19 at 9:01
  • @FilipFranik I've tried that, it still doesn't work – Valkor Simpson Dec 31 '19 at 17:29
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);
}
  • 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. – chrisl Jan 1 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.