Arduino with IR Sensor Project with LED

Arduino with IR Sensor Project with LED

This project shows you how to automatically turn ON and OFF a Light using an Arduino with IR Sensor.

IR technology is used for various purposes in daily life as well as in industry.  It can be used extensively in line follower obstacle avoidance robot , avoidance car, line count, tracking black and white lines, and many others. The main aadvantages of IR sensors are their low power consumption, simple design and convenience.

Components Required  for the Arduino with IR Sensor Project

Arduino Uno× 1Amazon
IR Sensor× 1Amazon
LED and Resistor Kit× 1Amazon
Breadboard× 1Amazon
Jumper wires× 2Amazon
USB cable type A/B× 1Amazon

Disclosure: These are affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Software

Arduino IDE

What is IR Sensor or Inferad Sensor?

An IR sensor or infrared sensor is a type of electronic device that emits light in order to detect certain aspects of its surroundings.

The sensor module is ambient light-adaptable, with a pair of infrared emitting and receiving tubes. At a specific frequency, the transmitting tubes emit infrared. When the direction of an obstacle is detected (reflective surface), the receiving tube receives the infrared reflected. After a comparator circuit processing, the green light turns on. And the signal output interfaces a digital signal (a low-level signal). The sensor’s effective distance range is 2 ~ 30cm. The sensor’s detection range can be adjusted by adjusting the potentiometer. 

IR Sensor Specifications

Voltage3.3V –  5V DC
Supply Current20mA
RangeUp to 20cm
Sensing rangeAdjustable via potentiometer
Cost Check Price

Application of IR Sensor

  1. Detecting obstacles
  2. Safety devices for industry
  3. Encoder for shaft
  4. Fixed detection of frequency
  5. Encoder of wheels

For more information, you can check out the IR Sensor Datasheet below:

Arduino with IR Sensor Circuit Diagram

Arduino with IR Sensor Circuit Diagram
Arduino with IR Sensor Circuit Diagram

IR Sensor’s  D0 connected to digital pin 2. LED connected from digital pin 13 to ground through a 220ohm resistor.

Arduino with IR Sensor Project Code

By clicking the button in the top right corner of the code field, you can copy the code. Copy and paste it into Arduino IDE. 

/*** www.arduinopoint.com ***/
/*** Arduino with IR Sensor ***/

int SensorPin = 2;
int OutputPin = 13;

void setup() {
  pinMode(OutputPin, OUTPUT);
  pinMode(SensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int SensorValue = digitalRead(SensorPin);
  
  Serial.print("SensorPin Value: ");
  Serial.println(SensorValue);
  delay(1000);
   if (SensorValue==LOW){ // LOW MEANS Object Detected
    digitalWrite(OutputPin, HIGH);
  }
  else
  {
    digitalWrite(OutputPin, LOW); 
  }
}

Result

 You should see your LED turn ON, when a object comes in the range of the IR Sensor. If you cannot see the desired output, ensure the circuit has been properly assembled, and verified and uploaded the code to your board.

Applications:
  1. Make automated Light system that will ON presence of object in the range of IR Sensor.
  2. You can make smart street light using IR Sensor with Arduino.

Leave a Reply