You are on page 1of 2

ANALOG SENSOR INTERFACING

What is Sensor
Sensors are those electronic components which convert physical data into
electronic data. This data is in analog format and is fed to the microcontroller on the
Arduino board. The microcontroller has inbuilt ADCs (Analog-2-Digital Converter)
which processes this data and converts it into digital format.

And once you have received the (electronically converted) physical data, you can
make your Arduino perform as you want.

How To Interface LDR With Arduino


Arduino Distance Measurement Using Ultrasonic Sensor

On your Arduino board, there are analog pins named as A0, A1, A2, A3, A4, A5. The
number of these pins may vary depending on your Arduino board. For UNO, there
are only 6 analog pins while for MEGA there are 16. And remember this thing, any
sensor (or other components) that gives analog data and you wish to process it,
you'll have to connect it to your analog pins only. For now, I would say SENSORS
would always be connected to analog pins.

Connection of Analog Sensor with Arduino


All sensors have their own method to connect with Arduino. Some of them need
pull-up resistors, some need a certain power supply to use them.  But any sensor
has generally 3 pins to connect to Arduino or other development board. These pins
are. 
1. +Vcc
2. Signal
3. Gnd
Hook up the +Vcc to 5v (or 3.3v if sensor demands it) on your Arduino board.
Connect the Gnd pin to Ground pin on your Arduino.
Connect the Signal pin to any of your Arduino's analog pins. In our case, say A1.

Code for Interfacing Analog Sensor with Arduino


Below code is general code for interfacing analog sensors with Arduino. Write this
code in your Arduino IDE to start playing with analog sensors.
void setup()
 {
  Serial.begin(9600);                            // initialize serial communication at 9600
bits per second:
 }

void loop() 
{
  int sensorValue = analogRead(A1);            // read the input on analog pin 1:
  Serial.println(sensorValue);                       // print out the value you read:
  delay(1);                                                      //this  delay in between reads for
stability 
}

After burning this code to your Arduino, open the serial monitor and see the analog-
2-digital converted data on your serial terminal. Basically, it is 10-bit data since the
inbuilt ADC of your Arduino is a 10bit ADC.You will get the reading on your serial
monitor.

You might also like