Tinkermill’s TinkerScouts will install a decorated train at Roosevelt Park in Longmont. Steve Elliott would like to have a motion detector to turn on a LED lamp which is controlled by a relay. In this post, we show how to hook up everything.
The items we need are pcDuino3, motion detector, linker base shield and a relay. Relay module is connected to the slot [D0 D1 V S] of the linker base shield which is installed on pcDuino3. The VCC of motion detector is connected to +5V of pcDuino3, GND of the motion detector is connected to ground of pcDuino, and the S of motion detector is connected to digital 2 of pcDuino3.
The whole setup is shown below:
The sketch for the Arduino-ish program is shown below, please copy and paste to the built-in Arduino IDE on pcDuino:
int PIR=2; int relay=0; void setup() { // put your setup code here, to run once: pinMode(PIR, INPUT); pinMode(relay, OUTPUT); } void loop() { // put your main code here, to run repeatedly: if ( digitalRead(PIR)==HIGH) { digitalWrite(relay, HIGH); printf("%s\n", "high"); } else digitalWrite(relay,LOW); }
We can make this code start automatically everytime we turn on pcDuino by following this post.
Leave a Reply
You must be logged in to post a comment.