Hi everyone,
I'm a beginner on arduino and I can't get any output from a "Momentary Self Reset Switch" (that's how it's called on aliexpress).
I made a schematic to let you know my wiring.
What Im' trying to do is :
Push switch once
make built-in led blink let's say 1 or 2 seconds max
No action needed when you push switch 2nd time
-> Basically just start a loop if switch is pressed
Your resistor is in series, instead of a pull-up or pull-down.
Remove that resistor.
Instead, you can put a resistor from D2 to GND (for pull-down) or from D2 to +5V (for pull-up). Also, the Arduino Uno has builtin pull-ups, so in your code, you would do pinMode(switch, INPUT_PULLUP); instead of pinMode(switch, INPUT);, that way you wouldn't need a pull-up at all.
So I switched common to gnd.
And my Serial monitor shows "Flag value: 1" when I press the switch !
But when I press it again nothing happens... (it only shows "Flag value: 1" once in the monitor)
EDIT:
I commented this :
And it seems to have fixed it, I can push multiple times and it shows output everytime I push the button.
You tried to but....
It's a picture, not a schematic. Most of the surface is empty, white surface, not used for useful information. It's completely uninteresting to see the physical shape of the UNO, the breadboard and an unknown third device.
It's very interesting too see pin designations, pin names etc.
The pictured stuff will not show any life. There's no powering of the kit. Insufficient powering is very often the reason for failure, therefore my "attack".
Yeah I tried, was my first time using Fritzing and I just wanted to make it easy to understand (and I didn't find the same component as the switch that I have that's why I edited it in Photoshop)
Powering is done via USB, but I have a DC Adapter if needed.
I added that line to prevent the flag being changed multiple times for one button press. Try pressing the button for ~2 sec and I'm pretty sure that the flag will toggle several times.
And I make it easy for me as I don't spend time on members easyness, to step aside. Spending time in helping members create the basic question has limits.
You can use the "L" light as a logic probe to tell if you are getting a signal--put one end of a temporary jumper on your pin 13 and the other on pin 2 or the switch and see if the LED turns off and on with the switch. If you get a bright/dark led "L" when 13 is connected to 2 and yoou toggle the switch, then you know you have good wiring and logic levels to 2.
Yes it is toggling several times, but at least it catches the press on the button !
To improve it I would need to store the button state and check if button state is not equal to last button state or something like this no ?
Oops-- I didn't click through to the code. If LED_BUILTIN is left in default, then the pin is tri-state, and the LED is driven by an op-amp and makes a good logic probe that works without code.