INPUT THE INPUTS ON THE ARDUINO READ VOLTAGE. ALL INPUTS NEED TO - - PowerPoint PPT Presentation
INPUT THE INPUTS ON THE ARDUINO READ VOLTAGE. ALL INPUTS NEED TO - - PowerPoint PPT Presentation
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
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
POTENTIOMETER WITH BLINKING LED
1 1 5 5 10 10 15 15 20 20 25 25 30 30 A A B B C C D D E E F F G G H H I I J J 13 12 11 10 9 8 7 6 5 4 3 2 L 5V A0 ANALOG IN AREF 1 GND TX RX RESET 3V3 A1 A2 A3 A4 A5 VIN GND GND DIGITAL (PWM= ) Arduino TM IOREF ICSP ICSP2 ON POWER 1 TX0 RX0 RESETREAD ANALOG VALUES AND BLINK LED
analogRead() gives values in a range from 0-1024.
POTENTIOMETER WITH PWM LED
1 1 5 5 10 10 15 15 20 20 25 25 30 30 A A B B C C D D E E F F G G H H I I J J 13 12 11 10 9 8 7 6 5 4 3 2 L 5V A0 ANALOG IN AREF 1 GND TX RX RESET 3V3 A1 A2 A3 A4 A5 VIN GND GND DIGITAL (PWM= ) Arduino TM IOREF ICSP ICSP2 ON POWER 1 TX0 RX0 RESETREAD 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 (Vin) is called R1, and the resistor closest to ground R2. The voltage drop across R2 is called Vout, 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
Light Level R2 (Sensor) R1 (Fixed) Ratio R2/(R1+R2) Vout Light 1kΩ 5.6kΩ 0.15 0.76 V Dim 7kΩ 5.6kΩ 0.56 2.78 V Dark 10kΩ 5.6kΩ 0.67 3.21 V
PHOTOCELL WITH VOLTAGE DIVIDER
Light Level R2 (Sensor) R1 (Fixed) Ratio R2/(R1+R2) Vout Light 1kΩ 5.6kΩ 0.15 0.76 V Dim 7kΩ 5.6kΩ 0.56 2.78 V Dark 10kΩ 5.6kΩ 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 R1.
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.