INPUT
THE INPUTS ON THE ARDUINO READ VOLTAGE. ALL INPUTS NEED TO BE THOUGHT OF IN TERMS OF VOLTAGE DIFFERENTIALS. THE ANALOG INPUTS CONVERT VOLTAGE LEVELS TO A NUMERICAL VALUE.
PULL-UP (OR DOWN) RESISTOR
Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pullup or pulldown resistor.
PUSH BUTTON WITH PULL-DOWN RESISTOR When the button isn’t pressed, the voltage going to pin 7 is “pulled down” to 0 because it is connected, via the resistor, to ground. When the button is pressed, the resistance going to ground is higher than that going to the input pin so the full voltage is sent to the pin.
CONTROL AN LED WITH A BUTTON
USING THE INTERNAL PULL-UP RESISTOR When the button isn’t pressed, the voltage going to pin is “pulled up” to HIGH. When the button is pressed, the connection to ground is completed so the pin is LOW.
CONTROL AN LED WITH A BUTTON
TOGGLE AN LED WITH A BUTTON Only change the state of the LED when there is a change from LOW to HIGH on the button. The “old_val” variable holds the state of the button the last time through loop.
TOGGLE AN LED WITH A BUTTON + DEBOUNCING Only change the state of the LED when there is a change from LOW to HIGH on the button. The “old_val” variable holds the state of the button the last time through loop.
ANYTHING CAN BECOME A SWITCH
ANALOG INPUT
POTENTIOMETER
RESET ICSP2 AREF RX TX L GND 13 IOREF 12 RESET Arduino 11 3V3 10 5V 9 GND 8 POWER GND TM DIGITAL (PWM= VIN 7 6 A0 5 A1 4 A2 3 ANALOG IN A3 2 ) A4 TX0 1 ICSP 1 ON A5 RX0 0 A B C D E F G H I J 1 1 5 5 WITH BLINKING LED POTENTIOMETER 10 10 15 15 20 20 25 25 30 30 A B C D E F G H I J
READ ANALOG VALUES AND BLINK LED analogRead() gives values in a range from 0-1024.
RESET ICSP2 AREF RX TX L GND 13 IOREF 12 RESET Arduino 11 3V3 10 5V 9 GND 8 POWER GND TM DIGITAL (PWM= VIN 7 6 A0 5 A1 4 A2 3 ANALOG IN A3 2 ) A4 TX0 1 ICSP 1 ON A5 RX0 0 A B C D E F G H I J 1 1 5 5 WITH PWM LED POTENTIOMETER 10 10 15 15 20 20 25 25 30 30 A B C D E F G H I J
READ ANALOG VALUES AND FADE LED analogRead() gives values in a range from 0-1024. analogWrite() can only write values from 0-255. To account for this we divide the value received from analogRead() by 4.
VOLTAGE DIVIDER
VOLTAGE DIVIDER The resistor closest to the input voltage ( V in ) is called R 1 , and the resistor closest to ground R 2 . The voltage drop across R 2 is called V out , that’s the divided voltage our circuit exists to make.
THE EQUATION
IF R2 AND R1 ARE EQUAL THEN THE OUTPUT VOLTAGE IS HALF THAT OF THE INPUT. IF R2 IS MUCH LARGER THAN R1 (AT LEAST AN ORDER OF MAGNITUDE) THEN THE OUTPUT VOLTAGE WILL BE VERY CLOSE TO THE INPUT. IF R2 IS MUCH SMALLER THAN R1 THEN OUTPUT VOLTAGE WILL BE TINY COMPARED TO THE INPUT.
PHOTOCELL WITH VOLTAGE DIVIDER
PHOTOCELL WITH VOLTAGE DIVIDER R 2 (Sensor) R 1 (Fixed) Ratio R 2 /(R 1 +R 2 ) V out Light Level 1k Ω 5.6k Ω Light 0.15 0.76 V 7k Ω 5.6k Ω Dim 0.56 2.78 V 10k Ω 5.6k Ω Dark 0.67 3.21 V
PHOTOCELL WITH VOLTAGE DIVIDER R 2 (Sensor) R 1 (Fixed) Ratio R 2 /(R 1 +R 2 ) V out Light Level 1k Ω 5.6k Ω Light 0.15 0.76 V 7k Ω 5.6k Ω Dim 0.56 2.78 V 10k Ω 5.6k Ω Dark 0.67 3.21 V What the input pin gets
VOLTAGE DIVIDER You can “tune” the output of the sensor by changing the value of R 1 .
READ ANALOG INPUT VALUES
READ ANALOG VALUES AND CONTROL LED analogRead() gives values in a range from 0-1024. analogWrite() can only write values from 0-255. To account for this we divide the value received from analogRead() by 4.
PRESSURE SENSOR WITH VOLTAGE DIVIDER
PRESSURE SENSOR WITH VOLTAGE DIVIDER
READ ANALOG INPUT VALUES
READ ANALOG VALUES AND CONTROL LED analogRead() gives values in a range from 0-1024. analogWrite() can only write values from 0-255. To account for this we divide the value received from analogRead() by 4.
Recommend
More recommend