EVERYTHING IS ABOUT SWITCHING :
Let's look at this picture:
YOU switch INPUTS to HIGH or LOW (1 or 0)
ARDUINO switches OUTPUTS to HIGH or LOW (1 or 0)
Think about that:
- The things YOU wire up (like switches, thermostats, light sensors) switch INPUTS to HIGH or LOW (1 or 0)
- ARDUINO switches OUTPUTS to HIGH or LOW (1 or 0)
BUT: How does Arduino KNOW when to switch outputs? YOU tell it by writing software called "Sketches".
WAYS OF INPUT SWITCHING:
OK, Let's look at hooking up switches. We have some choices.
Because most switches just make a connection between two terminals, the usual way of connecting switches to INPUTS is to use a resistor to "Pull" the input HIGH or LOW, and then have the Switch "Pull" the input the other way when it is pushed (or the thermostat clicks, etc etc). Look at this picture:
Here, a resistor (Little Resistor-Speak details) is use to "pull the input LOW" so Arduino sees it as a 0 (zero). The switch is connected from HIGH to the INPUT and when it switches, it "pulls the input HIGH" and Arduino sees it as 1.
The "switch" can be a pushbutton, a Thermostat, a Pressure Switch, an Air Flow Sensor, and Window or Door Switch, etc etc.
[Let's hook up our Arduino to a switch now, like in the picture, and run some software that tells us what Arduino is "seeing" when the switch is pushed..]
But it's easy to simply reverse the location of the resistor and switch. Look at the picture below. Now, the resistor "pulls the Input HIGH" and the switch "pulls the Input LOW" and Arduino sees that as 0 (zero).
(box) It's easy to just "Fix" anything that seems "upside down" by either re-arranging the circuit, or simply tell Arduino (in the software Sketch you write) to look for a 0 instead of a 1. Remember: "Fix It In Software"..
A FEW SWITCH-TYPE INPUT DEVICES:
Here are just a few of many Input Devices that act as switches, that you can connect to Arduino:
A FEW SENSORS AS INPUT DEVICES:
Let's look at a simple light sensor (Below). Hook up a "Light Dependent Resistor" and a regular fixed resistor as shown here. In room light the "LDR" is a low resistanceand so it "pulls the input HIGH". In the dark it is high resistance and the fixed resistor "pulls the Input LOW. This is fine, when the change of light is large, as when room lights are turned on and off, etc.
BUT, there's a BUT! (We will encounter quite a few "BUTs" in the next sessions, and that's why Engineers get paid to figure things out and make them work.)
[We need to talk about Inputs, here: What's a ?? What's a 0?? Noise. Hysterisis. ]
TO BE CONTINUED...