Skip to content

PIR Motion Sensor with Chainable LED

This sensor allows you to sense motion, usually any human movement in its range.

Simply connect it to the Grove and upload the sketch below while connecting the RGB LED ,when the sensor senses movement in its detecting range, the sensor will output HIGH signal on its SIG pin which will set the LED on.

Specification

Parameter Value/Range
Operating Voltage 3Vā€“5V
Operating Current(VCC = 3V) 100uA
Operating Current(VCC = 5V) 150uA
Measuring Range 0.1 ā€“ 6m
Default detecting distance 3m
Holding Time 1 ā€“ 25s
Working Wave Length 7 ā€“ 14um
Detecting Angle 120 degrees

Wiring

pir wiring

Sketch

We use this library for RGB Chainable LED, while we simply use the digital read without any additional libraries for sensing the movement of the PIR motion sensor.

// Include the library of the RGB LED
#include <ChainableLED.h>
// Number of RGB LED in the chain
#define NUM_LEDS  1

// Use digital pin 2 to receive the signal from the module
#define PIR_MOTION_SENSOR 2

// Connect CI -> D4 pin and DI -> D5 pin.
// Instantiate an object of class ChainableLED taking parameters CI,DI and Number of LED in the chain.
ChainableLED leds(4, 5, NUM_LEDS);

void setup(){  
SerialUSB.begin(9600);  
SerialUSB.println("Starting...");  
pinMode(PIR_MOTION_SENSOR, INPUT);  
leds.init();
}

void turnOnLED(){
// Flash RED for 0.1 sec
leds.setColorRGB((byte)0, 255, 0, 0); // RED Color
delay(100);
}
void turnOffLED(){
// Turn the LED OFF
leds.setColorRGB((byte)0, 0, 0, 0); // BLUE Color
delay(100);
}

// Detecting motion around.
boolean isPeopleDetected(){  
int sensorValue = digitalRead(PIR_MOTION_SENSOR);  
if(sensorValue == HIGH)  {
 return true;  
 }  else  {
 return false;  
 }
}

void loop() {
// Flash LED if motion is detected else the LED is turned off  
if(isPeopleDetected())
 turnOnLED();
else
 turnOffLED();
}
Back to top