Project tutorial
PIR Motion Controlled Relay Using Arduino Nano!

PIR Motion Controlled Relay Using Arduino Nano! © GPL3+

As the title says, this is a pretty simple PIR motion controlled relay using an Arduino Nano.

  • 1,993 views
  • 0 comments
  • 8 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
Cutting and Drilling Tools

Apps and online services

About this project

A little bit of back story.

This project was actually built before my Motion Activated Door Display aka. Arduino Project #8.

Because, I was still waiting for the WS2812B boards that time and remembered and asked my self "Hey! I have a couple of PIR motion sensors in my Arduino Arsenal. Now, what can I do with it?".

So, I came up with this one.

I guess that's it.

Just watch the video if you want to know more.

Thanks!

Here are some helpful Images and links on how to connect and setup things.

PIR Motion Calibration: http://helpdesk.txplore.com/support/solutions/articles/35000024880-how-to-calibrate-your-pir-infrared-sensor-

******************************************************************************

Social Media Links To Follow (I mean, if you want to):

Facebook - https://fb.me/HeathenHacks

Twitter - https://twitter.com/HeathenHacks

Instagram - https://instagr.am/HeathenHacks

******************************************************************************

Code

PIR + RelayArduino
/*
* PIR sensor tester
*/
 
int relayPin = 3; // choose the pin for the relay
int pirSensorPin = 2; // choose the input pin (for PIR sensor)
int pirState = true; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int minimummSecsLowForInactive = 5000; // If the sensor reports low for
// more than this time, then assume no activity
long unsigned int timeLow;
boolean takeLowTime;
 
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;
 
void setup() {
pinMode(relayPin, OUTPUT); // declare LED as output
pinMode(pirSensorPin, INPUT); // declare sensor as input
 
Serial.begin(9600);
 
//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);
}
 
void loop(){
  
val = digitalRead(pirSensorPin); // read input value
if (val == HIGH) { // check if the input is HIGH
  
digitalWrite(relayPin, HIGH); // turn LED ON
if (pirState) {
// we have just turned on
pirState = false;
Serial.println("Motion detected!");
// We only want to print on the output change, not state
delay(50);
}
takeLowTime = true;
} 

else {
digitalWrite(relayPin, LOW); // turn LED OFF
 
if (takeLowTime){
timeLow = millis();
takeLowTime = false;
}
 
if(!pirState && millis() - timeLow > minimummSecsLowForInactive){
pirState = true;
Serial.println("Motion ended!");
delay(50);
}
 
}
}

Schematics

Schematics
Pir relay 9pmhqhojzu
5v DC Relay and Extension Cord Diagram
Untitled 1 7hzyafmbfn

Comments

Similar projects you might like

Arduino Nano and Visuino: Infrared Remote Controlled Relay

Project tutorial by Boian Mitov

  • 3,370 views
  • 0 comments
  • 15 respects

LED Matrix + Motion Sensor Door Display [Arduino Holiday]

Project tutorial by Heathen_Hacks-v2

  • 1,878 views
  • 2 comments
  • 12 respects

Nano Relay Module

Project showcase by Boaz Lawnce

  • 7,637 views
  • 0 comments
  • 9 respects

Arduino Motion Controlled Electronics!

Project tutorial by Arduino “having11” Guy

  • 3,957 views
  • 0 comments
  • 15 respects

RobotGeek PIR Motion Sensor Night Light

Project tutorial by Team RobotGeek Projects Team

  • 1,597 views
  • 1 comment
  • 6 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 13,590 views
  • 12 comments
  • 51 respects
Add projectSign up / Login