Arduino detect a hand gesture by using PIR sensor (hc-sr501).

Mr.ElectroUino
1


                                            Tutorial  @Mr ProjectsoPedia

Hello again,
In this blog, We will learn about how PIR sensor(HC-sr501) work and we can control 230v bulb with hand gesture by using PIR sensor, relay, and Arduino. Using Arduino to get a signal from the PIR sensor and then send a signal to relay to switch a load and turn on the 230v blub.

In the Arduino project, We start with basic whenever PIR sensor detect a hand gesture or motion then the LED is blinking and beep a Buzzer.



Component requirements:

1. Arduino uno. - Buy
2. Pir sensor ( Hc-sr501 ). - Buy
3. Buzzer. - Buy
4. Resistor 220ohm.
5. LED.
6. Breadboard. - Buy
7. Jumper wire.

CIRCUIT DIAGRAM:

PIR sensor circuit
PIR sensor circuit

Pin connection:

1. Connect PIR signal pin to arduino digital pin 13
2. Connect PIR V+ pin to arduino 5v pin.
3. Connect PIR GND pin to arduino GND pin.

4. Connect arduino digital pin 12 to 220ohm resistor and connect the resistor to LED V+ pin
5. Connect LED GND pin to arduino GND pin.

6. Connect Buzzer V+ pin to arduino digital pin 11
7. Connect Buzzer GND pin to arduino GND pin.



CODE:
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 7;    //the digital pin connected to the PIR sensor's output
int ledPin = 5;    //the digital pin connected to the LED output
int Buzzer = 6;    //the digital pin connected to the BUZZER output

/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       tone(Buzzer,500);
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec"); 
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){       
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state
       noTone(Buzzer);
       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

In the second Arduino project, Whenever PIR sensor detect a hand gesture or motion detect the 230v bulb should be on by using relay for switch a load.

Warning!!: Before proceeding with this project, I want to let you know that you’re dealing with mains voltage. Please do not touch any wires that are connected to mains voltage, otherwise you may shock yourself. This is a serious topic, and we want you to be safe. If you’re not 100% sure what you are doing, do yourself a favor and don’t touch anything.
Ask someone who knows!




Component requirements:

1. Arduino.
2. PIR sensor ( Hc-sr501 ).
3. 5v Relay module
4. 230v bulb.
5. Breadboard.
6. Jumper wire.

CIRCUIT DIAGRAM:




Pin connection:

1. Connect PIR signal pin to arduino digital pin 13
2. Connect PIR V+ pin to arduino 5v pin.
3. Connect PPIR GND pin to arduino GND pin.

4. Connect 5v relay signal pin to arduino digital pin 12
5. Connect 5v relay V+ pin to arduino 5v pin.
6. Connect 5v relay GND pin to arduino GND pin.

7. Connect relay normal close ( NC ) to 230v bulb.
8. Connect relay common ( C ) to 230v socket.
9. Connect bulb to 230v socket. 




CODE:
int lamp = 12; // choose the pin for the RELAY
int inputPin = 13; // choose the input pin (for PIR sensor)
int val = 0; // variable for reading the pin status

void setup() {
pinMode(lamp, OUTPUT); // declare lamp as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
Serial.println(val);
	if( val== 1) {
		digitalWrite(lamp,HIGH); // turn ON the lamp
	} else {
		digitalWrite(lamp,LOW); // turn OFF the lamp
	}
}

Arduino with PIR sensor LED and Buzzer | Arduino alarm system with HC-sr501.


TAGS: arduino PIR sensor, arduino motion detector, arduino hand gesture, arduino PIR project, arduino pir sensor led, arduino pir sensor 230 bulb, arduino pir sensor code, pir motion sensor arduino, arduino pir motion sensor.

Post a Comment

1Comments

  1. Question :
    Can i used a 5v battery pack 2xAA to power the installation 1

    Also can i increased the amound of led with a serie circuit using the already program port ?

    Ty

    Sign : a guy who should have paid more attention to his basic circuit course to become a tech��

    ReplyDelete
Post a Comment