hello, I am currently having trouble with another seemingly simple project.
my project is supposed work a relay at pin 8 which is activated by a pushbutton at pin 13 with a 1k resistor (formerly a 10) . after 1 hour and several youtube tutorials, I have found that everything is wired correctly, the problem is the button is always reading high,( and it surprisingly isn't bounce),keeping the relay permanently on. here is my code
int relay=8;
int button=13;
int buttonread;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(button,INPUT);
pinMode(relay,OUTPUT);
}
void loop() {
delay(10);
buttonread= digitalRead(button);
// put your main code here, to run repeatedly:
ahahaha (I am laughing)
we all made this same mistake !
you must put a pullup resistor on any input pin, when your button is connected to ground (0v); you can put a real resistor, or the internal one, as the instruction INPUT_PULLUP does
Ah, but you see he is probably using a UNO since that is what the Arduino project wishes to sell you as its generally inconvenient and impractical "flagship" product.
In which case pin 13 is either INPUT or OUTPUT and the op-amp does not interfere with the operation in either case. If not connected and not otherwise specified in the code, it is common to notice the LED randomly flickering.
Yes, I know. But for those who are new to the uno, it is better to get into the habit of keeping this pin to use the led as a means of testing a program under development, for example. That's what I usually do.