Hello, I'm a beginner in electronics and in arduino too.
I'm trying to understand this circuit:
At the beginning the Led is off but,
when i push the blue wired button (A) the Led stays on, when i push the yellow wired button (B) the Led turns off.
When I press another time button (A) led lights up again, when i push the yellow wired button (B) the Led turns off again.
Here's the code:
int ledPin = 5;
int buttonApin = 9;
int buttonBpin = 8;
byte leds = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(buttonApin) == LOW)
{
digitalWrite(ledPin, HIGH);
}
if (digitalRead(buttonBpin) == LOW)
{
digitalWrite(ledPin, LOW);
}
}
My question is why when i single push the button A the led stays on? It's like i make the current flows for just an istant, and the circuit "become" a close circuit, in fact when I pull off the blue wire after i lighted on the led, nothing happened.
But my question is why? because the moment i left the button the circuit should return the same of the schematic and so the led should be off.
The second question is the similar to this: Why clicking the button B turns off the led?
The only thing different i can see in the schematic is that there'is a little point in the connection of the button A.
How the current is going in this circuit? Thank You
The circuits that you showed included a microprocessor. The circuits will do whatever the microprocessor is programmed to do, including ignoring the buttons completely and blinking the LED at some rate. Without knowing the program on the microprocessor, many things are possible.
If you plan to post the program, please read the appropriate locked topics at the top of this forum, and anything that they link to, so that you can properly autoformat the code and properly post it using code tags.
You should have explained how the LED got turned on in the first place. Also, you should have explained what can happen (using the buttons) after the LED turns off.
My question is why when i single push the button A the led stays on?
if (digitalRead(buttonApin) == LOW)
{
digitalWrite(ledPin, HIGH);
}
digitalWrite() to an output pin sets an output voltage level, which is "persistent" until you change it with another digitalWrite() command. There is no code related to the state of button A which turns the led off.
If you want to see the output change with the state of the input, you can do something like this
Improperly changing the content of a post can make a hash of the history of the post. I do not think that the original post included code, in which case the code should have been posted in a subsequent reply.