BNSS - IoT & Robotics Training

OBJECTIVE

Sensing the object movements and learn how PIR Sensor works.

MODULES REQUIRED

SCHEMATIC DIAGRAM

Following connection are made in inbuilt circuit, so there no need made these connection:

ARDUINO CODE
JavaScript
int led = 12; // the pin that the LED is atteched to
int sensor = 3; // 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
digitalWrite(led, LOW);
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
delayMicroseconds(250);
val = digitalRead(sensor); // read sensor value
if (val == LOW) { // check if the sensor is HIGH
digitalWrite(led, LOW); // turn LED ON
delay(100); // delay 100 milliseconds
if (state == HIGH) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
//delayMicroseconds(200);
}
}
else {
digitalWrite(led, HIGH); // turn LED OFF
delay(100); // delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
} }}

INSTRUCTIONS

WORKING

IOT Projects

PIR MOTION DETECTION

/ /

PIR MOTION DETECTION

OBJECTIVE

Sensing the object movements and learn how PIR Sensor works.

MODULES REQUIRED

SCHEMATIC DIAGRAM

Following connection are made in inbuilt circuit, so there no need made these connection:

ARDUINO CODE
JavaScript
int led = 12; // the pin that the LED is atteched to
int sensor = 3; // 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
digitalWrite(led, LOW);
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
delayMicroseconds(250);
val = digitalRead(sensor); // read sensor value
if (val == LOW) { // check if the sensor is HIGH
digitalWrite(led, LOW); // turn LED ON
delay(100); // delay 100 milliseconds
if (state == HIGH) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
//delayMicroseconds(200);
}
}
else {
digitalWrite(led, HIGH); // turn LED OFF
delay(100); // delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
} }}

INSTRUCTIONS

WORKING