|
ARDUINO_NANO |
x 1 | |
|
ir sensor |
x 1 |
|
arduino IDEArduino
|
Interfacing IR Sensor Module with Arduino Nano
In this project, we will learn how to interface an Infrared (IR) sensor module with an Arduino Nano. IR sensors are widely used in various applications, such as obstacle detection, line following robots, and remote control systems.
What is IR Sensor?
An Infrared (IR) sensor consists of an IR transmitter and an IR receiver. The IR transmitter emits infrared light, which is reflected by objects in front of the sensor. The reflected light is then detected by the IR receiver. Depending on the intensity of the reflected light, the sensor determines the presence or absence of an object. The Arduino Nano can be used to process the sensor's output and perform actions based on the detected object.
Working of IR Sensor
The IR sensor module typically consists of an IR LED (transmitter), a photodiode (receiver), and a signal processing circuit. Here's a step-by-step explanation of how it works:
The IR LED emits infrared light continuously. This light travels through the air and hits any object in its path. When an object comes in front of the sensor, the emitted IR light is reflected back towards the sensor. The photodiode detects the reflected IR light. The intensity of the reflected IR light is converted into an electrical signal by the photodiode. The signal processing circuit amplifies and filters this signal to make it suitable for interfacing with microcontrollers like the Arduino Nano.
The sensor module provides a digital or analog output based on the detected IR light intensity. This output can be read by the Arduino Nano to determine the presence of an object.
IR Sensor Pinout
The IR sensor module typically has three pins:
VCC: This pin is used to power the sensor module. It is connected to the 5V supply from the Arduino Nano.
GND: This pin is connected to the ground of the Arduino Nano to complete the circuit.
OUT: This pin provides the output signal from the sensor. It is connected to a digital input pin on the Arduino Nano to read the sensor's output.
Wiring IR Sensor Module with Arduino Nano
Here is a step-by-step guide to interface the IR sensor module with the Arduino Nano:
Pin connections:
5V: Connected to the VCC pin of the IR sensor module to provide power.
GND: Connected to the GND pin of the IR sensor module to complete the circuit.
D3 (Digital Pin 3): Connected to the OUT pin of the IR sensor module to read the sensor's output.
Code
Connect Arduino Nano with PC and upload below code.
#include <LiquidCrystal_I2C.h> // Library to Run I2C LCD LiquidCrystal I2C Library by Frank de Barbander 1.1.2
// We are using I2C 16x2 alphanumeric LCD with HD44780 controller
LiquidCrystal_I2C lcd(0x27, 16, 2); // Format -> (Address,Columns,Rows )
int SensorInputPin = 3; // Output for IR sensor input for controller
int sersorReturn = 0;
void setup() {
// initialize the lcd
lcd.init();
// Turn on the Backlight
lcd.backlight();
// Clear the display buffer
lcd.clear();
// setup code here, run once
pinMode(SensorInputPin, INPUT); // declare sensor pin as input pin
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print("IR Sensor Demo");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Object");
}
// below function checks sensor return value as well as signal debouncing
bool checkSensor(int* sensorReturnValue) {
int PreviousValue, CurrentValue;
bool boolReturn;
PreviousValue = digitalRead(SensorInputPin); // read input value
delay(20);
CurrentValue = digitalRead(SensorInputPin); // read input value
if (PreviousValue == CurrentValue) {
boolReturn = true;
*sensorReturnValue = PreviousValue;
} else {
boolReturn = false;
}
return boolReturn;
}
void loop() {
bool boReturn = 0;
// main code here, run repeatedly
boReturn = checkSensor(&sersorReturn);
if (boReturn == true) {
if (sersorReturn == LOW) { // When object is near then LOW is received at out pin
// write column, row and counting starts from zero so 0th Colum and 1st row
lcd.setCursor(0, 1);
lcd.print("Detected ");
} else {
// write column, row and counting starts from zero so 0th Colum and 1st row
lcd.setCursor(0, 1);
lcd.print("Not Detected ");
}
}
delay(100);
}
Output:
Image Credit: https://playwithcircuit.com/interfacing-ir-sensor-module-with-arduino/
Interfacing IR Sensor Module with Arduino Nano
- Comments(0)
- Likes(1)
- Van Noten Johan Jul 28,2024
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Rachana Jain
- Ultrasonic Sensor HC-SR04 Interfacing with Arduino The HC-SR04 Ultrasonic Sensor is a widely used and easy-to-implement sensor for distance measurement...
- Interfacing IR Sensor Module with Arduino Nano In this project, we will learn how to interface an Infrared (IR) sensor module with an Arduino Nano....
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
122 0 0 -
DIY Laser Power Meter with Arduino
172 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
162 0 2 -