The purpose of this project was to create something that would alert me when there were people in another room. So if I was upstairs something would let me know if there were people downstairs and vice versa. Therefore, this Arduino makes a noise and lights an LED when motions is detected in front of the sensor. Great project for beginners and people just starting out with using Arduino.
Inspiration from: Arduino with PIR motion Sensor, LED and buzzer (Code)
The materials needed:
Arduino
Breadboard
JumperWires
LED
220 Ohm resistor
Buzzer
PIR motion Sensor
Code:
const int motionpin=A0;
const int ledpin=13;
const int buzzpin=12; // ledpin,motionpin and buzpin are not changed throughout the process
int motionsensvalue=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(motionpin,INPUT);
pinMode(buzzpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
motionsensvalue=analogRead(motionpin); // reads analog data from motion sensor
if (motionsensvalue>=200){
digitalWrite(ledpin,HIGH);
tone(buzzpin,100); //turns on led and buzzer
}
else {
digitalWrite(ledpin,LOW); //turns led off led and buzzer
noTone(buzzpin);
}
}
Code from: Arduino with PIR motion Sensor, LED and buzzer (Code)