This will show my inexperience again. I looked at a simple tutorial to power an LED on or off using the Arduino Uno R3 push button switch in my kit. Before anybody replies please understand I don't need to know how the pull up/down circuit WORKS. I have seen those explanations and I can follow them. My problem is more basic. At first I thought this is just like a flashlight. Take a wire from the positive terminal of 2x3 volt batteries to one contact of the switch; a 2nd from the 2nd switch contact to one lead of the bulb; the last from the 2nd lead of the bulb back to the -ve battery terminal. Swtich contact & current flows: light on. No contact & no flow: light off. Here the Arduino is the battery (5v) and the LED is the bulb. Not so. I made the pull up/down sketch work but WHY do I need it? I am missing something. Perhaps a good example of a real project with realistic products might help. In both my "flashlight" circuit and the pull-up sketch, a PERSON is still needed to activate the switch. What's the difference? Are we protecting the Arduino circuitry as we often to using high power relays to turn on something? Still a human operator, not a micro.
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Your explanation of what you have done is confusing
Please post your sketch and a schematic of your circuit. A 'photo of a hand drawn circuit is good enough
With a flashlight circuit the switch effectively completes the circuit. Once the circuit is compete the electricity can flow and the bulb lights up... like this:
With a push button connected to a micro-controller it is not quite the same. There is no direct connection between the switch and the bulb. You actually have 2 seperate circuits, as follows:
The micro-controller sits in the middle. When it "detects" the switch has been closed by looking for 5v (HIGH) (as in the circuit above), it then supplies electricity to the LED circuit.
The reason pull-up/pulldown resistors are required is because in the switch circuit, when the switch is NOT pressed, then without the resistor, the micro-controller pin (pin 8 above) is connected to nothing... and therefore the micro-controller doesn't know if it should be HIGH or LOW (the pin is said to be "floating").
To drive an LED the internal pullup/down does not need to be set.
The outputs of the GPIO pins can be
On the other hand are you referring to the current limiting resistor used to limit the current through the diode so that the MCU is not fried?
Hi again red_car. Guess I am not explaining my confusion.. One of the first sketches most people are taught is how to illuminate an LED in by wiring a 330 ohm limiting resistor in series with one of the 5v Arduino pins and ground. You issue a digitalWrite HIGH to the appropriate pin and the LED goes on. No big deal. A subsequent tutorial asked to light the LED but incorporate a pushbutton. I found one of the push button switches and added it in series in the same circuit on my breadboard between the LED and ground with no change to the sketch. It worked fine. With the button UP the LED was off. Push the button and it went on. You have accurately pictured a simple battery circuit with a contact switch to power a bulb. That is exactly what I did except the battery was replaced by a 5v Arduino source and the bulb was the LED/330ohm resistor. The switch was the tiny Arduino push button. Then I reviewed the author's solution along with the explanation of how a pull up resistor works with this switch. My reaction was: why would I want to do that when my simple circuit worked? In both cases you push the button to illuminate an LED. Give me a practical example where you NEED the pull up or down circuit because mine would be no good. The load is a very low power LED. When I turn on a 12v light in my car (more amps) there is nothing sensing the voltage across the switch before letting the current flow to illuminate the lamp. The switch simply makes or breaks continuity (there is a fuse somewhere as well.). So again WHY is this type of switch needed on a microcontroller? Don't know how else to put it.
If you are just using the switch to turn on an LED... then yes you are correct... you don't need a pullup/pulldown resistor... if fact you don't need a micro controller at all. You just put everything in series with a power supply, and closing the switch will turn on the LED.
But what if you wanted to do something a little harder?
Let's say instead of just turning the LED on you wanted to blink the LED, when you press the button once, and stop it blinking when you press it again? To do that you are better to use the 2nd circuit above.
- You power the LED from one pin (an OUTPUT pin)
- You get the value of the button from a different pin (an INPUT pin).
Then the micro-controller can do all the smarts required to do the blinking.
Because the button circuit is a digital INPUT to the micro controller, then its value always needs to be either 5v OR GND. This is why you need a pullup/pulldown resistor... so the even when the button is NOT pressed the pin receives one of the expected values.
In the picture above an external pullup is used. When the button is pressed the input pin will see 0v (GND)... AND when it is NOT press it will see Vcc (usually 5v).
Examples
-
You want the LED to blink
-
You want the LED to automatically turn off after 5 minutes
-
You want the LED to slowly fade from fully on to half brightness over 10 seconds
-
You only want to turn the LED on if it's dark
-
You only want to turn the LED if 2 or more buttons are pressed
-
You only want to turn on the LED if motion is detected
-
etc, etc, etc...
Plus the internal pullup may be too weak to handle a loads current requirements.
Thanks for all replies. I am starting to see some of the uses. I was never an electronics guy, hobby or otherwise. It just seemed to me that a lot of these little projects were already solved with traditional electronics, especially after transistors, diodes etc. - solid state you might say. I gues combining discreet events to make a decision before triggering an output is another way to look at it.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.