IR proximity sensors or Infrared sensors are useful in different kinds of projects. They can be used as obstacle detection in Robotics, for parts detection in automated conveyors in industrial production line, for intrusion detection, opening and closing of doors and many others.
Here we will show how to interface IR sensor with Arduino, LCD, Buzzer and LED. In this project when the proximity IR sensor detects presence of nearby object, the LCD will display a warning message, the Buzzer will sound alarm and the LED will turn on. Thus giving us both visual and audio signals to indicate that the sensor has detected something. The LCD, IR sensor with buzzer Arduino code is provided at the end.
Video Demonstration of IR sensor with Arduino, Buzzer, LCD & LED
First watch the video demo so that you know what you can expect from this tutorial. In the video, intially when there is no object in-front of the IR sensor a message "No Obstacle!" on the LCD is displayed. When hand is brought is near the IR proximity sensor, the LCD display the warning message "Warning!" "Somebody there!", and also the buzzer turns on sounding the alarm and the LED also turns on.
Interfacing IR sensor with Arduino, LCD Buzzer & LED
The wiring diagram of interfacing IR sensor with Arduino, LCD, Buzzer and LED is as shown in the figure. The IR sensor, the LED, the Buzzer are connected to the pin 2, pin 3 and pin 4 of the Arduino. The LCD is connected to the pins 13,12,11,10,9 and 8.
Below is Circuit Simulation in Proteus Software
The above schematic diagram was realized on a breadboard and is shown below.
Program Code for IR sensor with Arduino, Buzzer, LCD and LED
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
int irPin = 2; // IR pin
int LED = 3; // LED pin
int buzzerPin = 4; //Buzzer pin
int sensorOut = LOW; // Initialize
void setup () {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(irPin, INPUT);
pinMode(LED, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorOut = digitalRead(irPin);
if (sensorOut == LOW)
{
Serial.println("No Obstacle!");
lcd.clear();
lcd.print("No Obstacle!");
digitalWrite(LED, LOW);
digitalWrite(buzzerPin, LOW);
}
else
{
Serial.println("Somebody there!");
lcd.clear();
lcd.print("Warning!");
lcd.setCursor(0,1);
lcd.print("Somebody there!");
digitalWrite(LED, HIGH);
digitalWrite(buzzerPin, HIGH);
}
delay(200);
}
Thank you for this comprehensive information.
Thanks for the valuable post!!
I have tried running the code and I am getting an error “expected ‘,’ or ‘;’ before ‘int’ “ beginning on line 5 where there is int irPin = 2; // IR pin
check your code again, i think you have typing mistake. i don't see any missing ; before that statement. or email me your code exactly.
Hi, i have questions. How the coding will be if I'm using lcd touchscreen to display the QR code? Really want to know to proceed my final year project. Notice me please !
In details, i want to create system that can display the QR code when parcel come in which detected by IR sensor. QR code is about personal confirmation for currier.
Notify me please..
I have not worked with QR code system. So I am not able to help you.
is it possible to get reading on an lcd screen as a count as to how many obstacles pass through the IR sensor? also can it be done using the same bread board?
yes, just create a variable and increment it whenever IR detects an object. You can add interrupt routine also but not required. Then just send the count value to LCD.
glad to hear that
is it possible that if the LCD shows specific number, the buzzer will make a sound?
this is not possible because the IR sensor module outputs digital signal(LOW or HIGH) and so we cannot measure specific number of distance, only on or off.
Try using Ultrasonic Sensor for distance measurement.
hi what should i do if my 16x2 lcd have a IC2 connected to it
you need to remove the LCD wires and reconnect the I2C LCD pins to pins according to your program. there are lots of program which explains how to make I2C work. Just comment out the settings and insert your LCD connection pins.