You are on page 1of 10

ANALOG INPUT

Analog Input

Arduino can recognize analog voltage by


converting it into a digital output
The Atmel chip has an onboard 6 channel, 10bit analog-to-digital converter
Analog pins also have the same functionality of
general purpose input/output (GPIO) pins

analogRead() returns a number between 0 and 1023


that is proportional to the amount of voltage being
applied to the pin (0V would read as 0 and 5Vwould
read as 1023.)

analogRead()

Function to perform ADC


Returns value from 0-1023

Syntax:
analogRead(channel)
channel: ADC channel used
Ex: analogRead(0)

A potentiometer is a simple knob that


provides a variable resistance, which we
can read into the Arduino board as an
analog value

Example: Blinking
int sensorPin = A5;
int ledPin = 5;
int sensorValue = 0;
void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop()

const int analogInPin = A5;


const int analogOutPin = 5;
int sensorValue = 0;
int outputValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);

map()

This function re-maps a number fromone


range to the other. It is called like
map(value, fromLow, fromHigh, toLow,
toHigh).
This is useful because the analogRead
returns a value in the range of 0-1023. But
analogWrite can only take a value from 0255.

Analog Output

Reverse method of
analog read: from a
specific value from a
range, produce the
equivalent analog
voltage.
Range: 0 255
Pin is turned on and
off very fast
achieves an
averaged effecton

Analog Output

analogWrite()

Supported pins: 3, 5, 6, 9, 10 and 11


value: ranges from 0 - 255

Syntax:

analogWrite(pin, value)
pin:

the pin to write to


Ex: analogWrite(9, 255);

Seatwork

Make the two inputs a gas and


brake button. The gas button should
speed up the blinking rate of the LED,
and the brake button should slow it
down

You might also like