Space In HIndi

 


Pages

Popular

ARDUINO INTERFACING WITH DIGITAL SENSOR

 Digital sensors generate 'Discrete Signal'.

 This means that there is a range of values that the sensor can output, but the value must increase in steps. There is a known relationship between any value and the values preceding and following it. 

The simplest examples of digital sensor is push switch and IR sensor, because they output two discrete values i.e. HIGH/LOW or 0/1. There are so many digital sensor in electronics. 

IR sensor interfacing with Ardiuno UNO

 Components Required: 

1. Arduino UNO 

2. IR sensor 

3. Connecting wires 



IR stands for Infra-Red. IR waves are not visible to our naked eye.
 This sensor has two LEDs. Out of which one acts as transmitter and continuously emits Infra-Red waves. Other LED acts as InfraRed receiver commonly known as photodiode. 
Whenever any obstacle comes in front of the IR  transmitter LED, IR waves get reflected back and photodiode/receiver LED receives IR waves and at the output pin of sensor we get HIGH / 1 value.

Basic interfacing of IR sensor

Interfacing: Vcc pin of sensor is connected to 5V of Arduino. 
GND pin of sensor is connected to GND of Arduino. 
Output pin of sensor could be connected to any digital pin. 
Here we have used pin 2.


Programming: First we need to declare the pin we are using to sense the output of sensor. 
Here we need to use pin 2 as input pin, because it is going to take input from sensor. 
To observe the changes on obstacle detection, we will use Serial Terminal in Arduino IDE.
 For this we also need to initialize Serial port in void setup().
 Now we need to write code to be executed in loop in void loop().
 We need to continuously read input at digital pin 2 and print on Serial terminal. 
We will use delay of 1 second for readable output.

int value; // variable to store value read on digital pin 
void setup() 
{
 pinMode(2, INPUT); // initialize digital pin 2 as an 
 input Serial.begin(9600);
 }
 void loop()
 { 
value = digitalRead(2); // read value on pin 2 
Serial.println(value); // print value on serial terminal
 delay(1000); // wait for 1 second 
}


No comments: