Movement Sensor

Hi, today I will explain how can you make a movement sensor with the arduíno. The steps are very easy and im sure you will be done in a few minutes!

Step 1: The Materials You Need to Make the Project-

step 1- These are the materials you need to build this project:

1x PIR Motion Sensor (HC-SR501)

Arduino UNO – read Best Arduino Starter Kits

1x LED

Jumper Cables

USB with type A and B connectors

I used a computer as a material to join the USB with type A and B connectors, but you can finish the project without them.

Step 2: Schematics

Step 2- As you can see in the image above, first of all you join 1x LED in the two holes "GND" and "13". Following that, you join the jumper cabels to the arduíno. In our image it shows that the red jumper cabel connected to the hole "5V" and on the Pir motion sensor it is connected to the pin in the left corner. The black jumper cabel needs to be connected in the "GND" in the "power'' section of the arduíno next to the red jumper cabel, and it has to be connected to the pin in the right corner of the Pior motion sensor. Finishing the jumper cabels, you have to join the yellow one to the hole "2" of the arduíno and connect it in the middle pin of the Pir motion sensor. Finishing our project, you connect the USB to the computer and with the code that is on the next slide it will work.

Step 3: Code

Step 3-

/*  
Arduino with PIR motion sensor For complete project details, visit: http://RandomNerdTutorials.com/pirsensor Modified by Rui Santos based on PIR sensor by Limor Fried */ int led = 13; // the pin that the LED is atteched to int sensor = 2; // the pin that the sensor is atteched to int state = LOW; // by default, no motion detected int val = 0; // variable to store the sensor status (value)
void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(9600);        // initialize serial
}
void loop(){
  val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH
    digitalWrite(led, HIGH);   // turn LED ON
    delay(100);                // delay 100 milliseconds 
    
    if (state == LOW) {
      Serial.println("Motion detected!"); 
      state = HIGH;       // update variable state to HIGH
    }
  } 
  else {
      digitalWrite(led, LOW); // turn LED OFF
      delay(200);             // delay 200 milliseconds 
      
      if (state == HIGH){
        Serial.println("Motion stopped!");
        state = LOW;       // update variable state to LOW
    }
  }
}




Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • First Time Author

      First Time Author
    • Toys Contest

      Toys Contest

    Discussions