This is my second tutorial of Arduino tutorial series. This is mainly video tutorial in Hindi/ Urdu or subtitled English.
In this tutorial I am going to show you how to Interface Analog Sensor with Arduino and how to read the analog data in serial Monitor. In this tutorial i am going to interface Temperature sensor LM35 and read the data on serial Monitor.
Step 1: What Is LM35
LM 35 is a Temprature sensor, but it looks like a transistor. There are total 3 pins in this sensor pin discription of this sensor is shown in fig.
Pin 1: This pin is connected with Vcc of arduino, sensor can work from 2.7 volt to 5.5 volt.
Pin 2: This is output pin so it is connected to analog pin of arduino, in this tutorial I am connecting with A0 pin.
Pin 3: This is GND pin so this connected to GND of arduino.
Step 2: Circuit
Circuit connection of this is very simple, this sensor does not need any extra components. just connect VCC, GND and OUT pin with arduino.
Step 3: Code
Just Copy and Paste this code and Upload.
after upload click on serial monitor, now you can see the analog value on Serial Monitor.
Line 1: int sensorpin = A0;
This Int defines the analog input pin of arduino, LM35 sensor connected by this pin.
Line 2: int sensorval;
This is the sensor value which is read by analog input pin A0.
Line 5: pinMode(sensorpin,INPUT);
Function pinMode is used to define the any pin as INPUT or OUTPUT, in the circuit sensor LM35 is connected to arduino so it is works as INPUT.
Line 6: Serial.begin(9600);
Function Serial.begin is begin function of serial Monitor, 9600 is the baud rate.
Line 10: sensorval=analogRead(sensorpin);
In this function analog value is read by sensor pin and saved into int sensorval.
Line 11 Serial.println(sensorval);
By using this function value of sensorval is written on serial Monitor
Step 4: Testing
Just upload this code and click on serial monitor, serial Monitor is opens now set the baud rate equal to 9600.
Code is ready you can measure the temperature, if heat is given to sensor using lighter value on serial monitor will increase, this is clearly visible in video.
Step 5: Watch My Video