Thursday 24 May 2018

PIR Motion Sensor with led and a buzzer

Arsal Arduino

 PIR Motion Sensor with led and a buzzer code:

//define the pins
int LED = 4;
int PIR = 7;
int Buzzer = 2;

void setup() {
  //define the LED and Buzzer pin as output
  pinMode(LED, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  //define the sensor pin as input
  pinMode(PIR, INPUT);
}

void loop() {
  //using the digitalRead function we will read the signal of the sensor
  int value = digitalRead(PIR);
  //if its high or if an any object is detected it will activate the LED and Buzzer
  if (value == HIGH){
    digitalWrite(LED, HIGH);
    digitalWrite(Buzzer, HIGH);
  }
  else {
    digitalWrite(LED, LOW);
    digitalWrite(Buzzer, LOW);
  }
}

PIR Motion Sensor using Relay module code:

//define the pins
int Relay = 4;
int PIR = 7;


void setup() {
  //define the Relay pin as output
  pinMode(Relay, OUTPUT);
  //define the sensor pin as input
  pinMode(PIR, INPUT);
}

void loop() {
  //using the digitalRead function we will read the signal of the sensor
  int value = digitalRead(PIR);
  //if its high or if an any object is detected it will activate the Relay Module
  if (value == HIGH){
    digitalWrite(Relay, LOW); //For activating the Relay we will send a LOW as the Relay input pin works inversely.
  }
}

The video link:

No comments:

Popular Posts