Ir sensor using Arduino
An IR sensor project with Arduino Uno can be used for obstacle detection, line following, or remote control applications. Here's a simple guide:
Components Needed
- Arduino Uno
- IR Sensor Module (e.g., VL53L0X or simple IR sensor)
- Breadboard and jumper wires
- LED (optional)
Circuit Setup
1. Connect the IR sensor module to the Arduino:
- VCC to 5V pin
- GND to GND pin
- Signal pin to a digital pin (e.g., pin 2)
Code
For simple IR sensor:
const int irPin = 2;
void setup() {
pinMode(irPin, INPUT);
Serial.begin(9600);
}
void loop() {
int irValue = digitalRead(irPin);
Serial.println(irValue);
delay(100);
}
For obstacle detection with LED:
const int irPin = 2;
const int ledPin = 13;
void setup() {
pinMode(irPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int irValue = digitalRead(irPin);
if (irValue == LOW) {
digitalWrite(ledPin, HIGH); // Obstacle detected
} else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
How it Works
1. The IR sensor detects obstacles or reflects IR signals.
2. The Arduino reads the sensor value and can trigger actions (e.g., turning on an LED).
Applications
- Obstacle detection in robotics
- Line following robots
- Remote control systems
Do you have any specific questions about this project or would you like to explore more advanced IR sensor applications?