Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
In this project, we will learn how to make a home security system using an Infrared (IR) sensor.
An IR Sensor is a type of sensor that detects infrared radiation emitted by objects as heat. The Infrared Obstacle Avoidance IR Sensor is widely used in robotics and automation applications to enable obstacle detection and navigation for robots or automated systems.
Visit Understanding Infrared Sensor: What Is An IR Sensor and How Does It Work? for more information.
For more information, visit Getting to Know Your Arduino Uno: A Beginner’s Guide to Its Components.
1. Connect IR Sensor to Arduino
IR Sensor | Arduino |
VCC | 5V |
GND | GND |
OUT | D2 |
2. Connect Buzzer to Arduino
Buzzer | Arduino |
Negative terminal | GND |
Positive terminal | D11 |
3. Connect Switch to Battery Connector
4. Connect Arduino to your computer using a USB cable and upload the program to Arduino through the Arduino IDE software. Visit Getting Started with Arduino IDE: A Beginner’s Guide to Coding and Creating for more information.
5. Connect Battery to Arduino
Battery | Arduino |
Negative terminal | GND |
Positive terminal | Vin |
Warning: Disconnect the USB cable or adapter before connecting the battery to the Vin pin.
Warning: The Vin pin does not have built-in reverse polarity protection. If you accidentally connect a power source with reversed polarity to the Vin pin, it can damage your Arduino board.
The IR sensor is an ‘Active Low’ output sensor. The sensor’s output is High when it detects an obstacle and Low when no obstacle is caught.
byte ir_sensor = 2; //Digital pin connected to the IR sensor
byte buzzer = 11; //PWM pin connected to buzzer
void setup()
{
pinMode(ir_sensor, INPUT); //IR sensor is an input device
pinMode(buzzer, OUTPUT); //Buzzer is an ouput device
}
void loop()
{
int sensor_state = digitalRead(ir_sensor); //Read digital IR sensor pin
if(sensor_state == HIGH)
{
analogWrite(buzzer, 200); //Set the voltage to 200 and make a noise
delay(110); //Wait for 110 milliseconds
analogWrite(buzzer, 100); //Set the voltage to 100 and make a noise
delay(110); //Wait for 110 milliseconds
}
else
{
digitalWrite(buzzer, LOW); //Set the voltage to low and make no noise
}
}