ATTINY project working in tinkercad not in reality

Hi trying to get this project to work in reality works fine on tinkercad must be missing something! Have 2 switches controlling 2 outputs if either 1 of inputs are high then switch on both outputs. If both outputs low both outputs off. This only switches on outputs when both switches high. This coding is all new to me and i guess i'm missing something simple that tinkercad isnt picking up.
Thanks

// C++ code
//
void setup()
{
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
}

void loop()
{
  if (digitalRead(4) == HIGH || digitalRead(5) == HIGH) {
    digitalWrite(2, HIGH);
    digitalWrite(1, HIGH);
  } else {
    digitalWrite(2, LOW);
    digitalWrite(1, LOW);
  }
  delay(10); // Delay a little bit to improve simulation performance
 

Did you add pullup resistors?
At least use INPUT_PULLUP if your switches connect to GND.

What does the malfunction look like? How does it differ from the decired action?

Which AtTiny are you using and with which core ? GPIO nrs, do not match up with IC-pin nrs


And on the 8 pin AtTiny, pin 5 is the reset pin.

yes i have

I only get outputs when both inputs are high.
thanks

Attiny85-20PU is what i am using. Could that be my issue using pin 1 as in input.
Thanks

Pinout is the same as a 13a,
GPIO 5 / pin 1 should be above 2.5v or the AtTiny will reset.
You can set the fuses to use it as a normal IO pin, but thereafter you will not be able to upload any code to it anymore, so that is not recommended.
Basically you don't need it at all for this project, you have 5 digital GPIO pins available, and you only need 4. PB5/Reset should be pulled up for a stable system (use a 10K resistor)
edit:
The PB5/reset can be used as an analog input though and is reference by A0, but still only as long as the voltage stays above 2.5v (on a 5v powered chip), a few extra resistors can help you out with this.

I am using 1k pull up resistors i will try with 10k thanks

Supply a full circuit diagram (not fritzing).

1 Like

that's also OK, main thing is that if you ground out PB5, you will reset the board/chip

That was my problem as i had an input to pb5 which was either 0v or 5v depending on switch on or off. swapped my switches to pb3&pb4 and left pb5 at 5v it now functions correctly. Thanks
`// C++ code
//
void setup()
{
pinMode(4, INPUT);
pinMode(3, INPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
}

void loop()
{
if (digitalRead(4) == HIGH || digitalRead(3) == HIGH) {
digitalWrite(2, HIGH);
digitalWrite(1, HIGH);
} else {
digitalWrite(2, LOW);
digitalWrite(1, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}`

If i wanted to add a delay of say 10 seconds before switching output on and off

can't add attachments as new member

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.