Datasheet
7
void setup() {
pinMode(PIR_MOTION_SENSOR, INPUT); /* declare the sig pin as an INPUT */
pinMode(RED_LED, OUTPUT); /* declare the red_led pin as an OUTPUT */
_handle_led(OFF);
}
/* the loop() method runs over and over again */
void loop() {
if(isPeopleDetected()) {
_handle_led(ON); /* if we detect a people, turn on the led */
} else {
_handle_led(OFF); /* found nobody, turn off the light */
}
}
/* judge if there is a people around */
boolean isPeopleDetected() {
int sensor_val = digitalRead(PIR_MOTION_SENSOR); /* read sig pin */
if(HIGH == sensor_val) {
return true; /* people detected */
} else {
return false; /* people un-detected */
}
}
3.3 With Raspberry Pi
1. You should have got a raspberry pi and a grovepi or grovepi+.
2. You should have completed configuring the development enviroment, otherwise follow here.
3. Connection
Plug the sensor to grovepi socket D8 by using a grove cable.
4. Navigate to the demos' directory:
cd yourpath/GrovePi/Software/Python/
To see the code
nano grove_pir_motion_sensor.py # "Ctrl+x" to exit #
import time
import grovepi