Components and supplies
PIR Motion Sensor (generic)
Arduino Nano R3
5v DC Relay
Jumper wires (generic)
Box Enclosure
Prototype PCB
Tools and machines
Soldering iron (generic)
Cutting and Drilling Tools
Apps and platforms
Arduino IDE
Project description
Code
PIR + Relay
arduino
PIR + Relay
arduino
Downloadable files
Schematics
Schematics
Schematics
Schematics
5v DC Relay and Extension Cord Diagram
5v DC Relay and Extension Cord Diagram
Comments
Only logged in users can leave comments
Anonymous user
3 years ago
Thanks for sharing this information. EComponentz is a platform to feature the largest collection of Made in India Electronic products & embedded solutions online ecomponentz.com. https://ecomponentz.com/the-reasons-for-the-global-shortage-of-electronic-components-2/
arodelo
3 years ago
I modified a little bit. So i can turn a lamp for90 seconds, and then turn it off automatically. 1. lamp connected to common and nc (normally close), so lamp assumed to be off at the beginning this is the code: /* * PIR sensor tester */ int relayPin = 3; // choose the pin for the relay int pirSensorPin = 7; // choose the input pin (for PIR sensor) int val = 0; // variable for reading the pin status long unsigned int maxSecsHighForActive = 90000; // keep light on during this time long unsigned int timer=0; // more than this time, then assume no activity long unsigned int timeHigh; boolean takeHighTime=false; //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); digitalWrite(relayPin, LOW); // turn LED OFF //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"); } void loop(){ if ( takeHighTime ) { //Serial.println("mode waiting:"); timer = millis() - timeHigh; //Serial.print("initial timer:"); //Serial.println(timer); while ( timer < maxSecsHighForActive ) { //do nothing just wait......but not sleeping.but aware. //Serial.print("Counting:"); timer= millis() - timeHigh; //Serial.println(timer); } takeHighTime = false; Serial.println("Motion ended!"); digitalWrite(relayPin, LOW); // turn LED OFF delay(50); }else { val = digitalRead(pirSensorPin); // read input value if (val == HIGH) { // check if the input is HIGH Serial.println("movment detected."); digitalWrite(relayPin, HIGH); // turn LED ON delay(50); takeHighTime = true; timeHigh = millis(); } } }
arodelo
2 years ago
I modified a little bit. So i can turn a lamp for90 seconds, and then turn it off automatically. 1. lamp connected to common and nc (normally close), so lamp assumed to be off at the beginning this is the code: /* * PIR sensor tester */ int relayPin = 3; // choose the pin for the relay int pirSensorPin = 7; // choose the input pin (for PIR sensor) int val = 0; // variable for reading the pin status long unsigned int maxSecsHighForActive = 90000; // keep light on during this time long unsigned int timer=0; // more than this time, then assume no activity long unsigned int timeHigh; boolean takeHighTime=false; //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); digitalWrite(relayPin, LOW); // turn LED OFF //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"); } void loop(){ if ( takeHighTime ) { //Serial.println("mode waiting:"); timer = millis() - timeHigh; //Serial.print("initial timer:"); //Serial.println(timer); while ( timer < maxSecsHighForActive ) { //do nothing just wait......but not sleeping.but aware. //Serial.print("Counting:"); timer= millis() - timeHigh; //Serial.println(timer); } takeHighTime = false; Serial.println("Motion ended!"); digitalWrite(relayPin, LOW); // turn LED OFF delay(50); }else { val = digitalRead(pirSensorPin); // read input value if (val == HIGH) { // check if the input is HIGH Serial.println("movment detected."); digitalWrite(relayPin, HIGH); // turn LED ON delay(50); takeHighTime = true; timeHigh = millis(); } } }