IR sensor with Arduino, LCD, Buzzer and LED

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.


In the above IR proximity sensor interfacing with arduino diagram above, we have used a 10KOhm potentiometer for LCD brightness control. A separate 5V supply was used for LCD, Buzzer and LED. The ground of this supply should be connected to the ground of the Arduino.

Program Code for IR sensor with Arduino, Buzzer, LCD and LED

The following is the program code that was used in this work.

#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);
}

Recommended Tutorials

16 Comments

  1. Aliop Kevin

    Thank you for this comprehensive information.

    Reply Delete April 16, 2021 at 12:24 PM
  2. petterson

    Thanks for the valuable post!!

    Reply Delete May 2, 2021 at 11:35 AM
  3. Unknown

    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

    Reply Delete June 4, 2021 at 12:59 AM
    1. ee-diary

      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.

      Reply Delete June 4, 2021 at 9:58 PM
  4. Carmilina

    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 !

    Reply Delete June 5, 2021 at 11:56 AM
  5. Carmilina

    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.

    Reply Delete June 5, 2021 at 12:01 PM
Previous Post Next Post