• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramGPIOUse Motion Detector to Control a relay on pcDuino3
Previous Next

Use Motion Detector to Control a relay on pcDuino3

Posted by: admin , October 28, 2014

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:

1028_1 (2)

 

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.

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors