Rajat Gera
Published © GPL3+

Motion Sensor

If motion is detected, this will light one LED, and if not, it will light the other.

BeginnerShowcase (no instructions)3,998
Motion Sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
LED (generic)
LED (generic)
×2

Software apps and online services

Arduino IDE
Arduino IDE

Code

Arduino Code

Arduino
void setup() {
  // put your setup code here, to run once:
pinMode(sensor, INPUT);
pinMode(4,OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
sensor_value=digitalRead(sensor);
Serial.println("    ");
 Serial.println(    sensor_value);
 if(sensor_value==0)
{
  digitalWrite(4,HIGH);
  digitalWrite(8,LOW);
 Serial.println("Motion detected");
 else if(sensor_value==1)
{
  digitalWrite(8,HIGH);
  digitalWrite(4,LOW);
  Serial.println("Motion not detected");
}

Credits

Rajat Gera

Rajat Gera

6 projects • 2 followers

Comments