Hi there, I am new to Arduino. My project is to turn on a servo motor once a motion sensor detects a nearby person. I've done my homework to search similar project tutorials like openhomeautomation.net and http://www.instructables.com/id/Cheap-Wireless-Motion-Sensor-Device/. they are quite helpful to let me know my project is doable. I figured out that this project needs a PIR motion sensor, wireless transceiver (a pair of transmitter and receiver), a servo motor, and of course two Arduino boards.
The two modules in my project,
A PIR sensor >> Arduino_1 >> Transmitter: this is the motion detection module, which produces and sends RF signals to the second module
A receiver >> Arduino_2 >> A servo motor: this is the servo motor control module. the size of the second module should be as small as possible as I am going to fit the whole thing in a tiny space. There are many Arduino boards to choose from (e.g. Arduino Uno R3, Pro, Due, Fio, etc.), I want to know which two Arduino boards should I buy.
Module 1 is positioned close to Module 2, say 1.5 meters, but there is no direct line-of-sight, so IR is not acceptable for this project.
Two modules are not wired, because I want module 1 mounted on a wall, and module 2 fit in a tiny space (100 mm x 100 mm x 100 mm). PIR should be mounted on a wall, and detect anyone who enters the room from entrance (the room has no door).
the servo supposed to control a shaft to turn 45 degree once the receiver got RF signals. there is only one position required, turning 45 degree slowly and then turn back slowly to initial its position.
Do I need a sensor shield and a motor driver shield? I know my questions are silly, but you can tell I am kinda confused cos in these tutorial they are using different Arduino boards and electronic components. So, it will be great if someone give me a list of required electronic components. I literally have nothing to start with, so some accessories like jumper wires are also needed.
#include <VirtualWire.h>
char *controller;
int pir = 2 // connect the output pin of the pir to pin 2
void setup() {
pinMode(13,OUTPUT);
pinMode(pir, INPUT); // set the pir as input pin
digittalWrite(pir, LOW); // set the pir pin as LOW, when motion is detected the pin will go high, pull-down activated
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
int sensorReading = digitalRead(pir); // check if motion is detected
if(sensorReading == HIGH){ //If motion detected then send 1 to the RX
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(2000);
}
else {
controller="0" ; // If motion not detected then send 0 to the RX
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(2000);
}
}
RX Sketch
#include <VirtualWire.h>
void setup()
{
vw_set_ptt_inverted(true);
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if(buf[0]=='1'){
// control your servo & all
digitalWrite(13,1);
}
if(buf[0]=='0'){
digitalWrite(13,0);
}
}
}
#include <VirtualWire.h>
char *controller;
int pir = 2 // connect the output pin of the pir to pin 2
void setup() {
pinMode(13,OUTPUT);
pinMode(pir, INPUT); // set the pir as input pin
digittalWrite(pir, LOW); // set the pir pin as LOW, when motion is detected the pin will go high, pull-down activated
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
int sensorReading = digitalRead(pir); // check if motion is detected
if(sensorReading == HIGH){ //If motion detected then send 1 to the RX
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(2000);
}
else {
controller="0" ; // If motion not detected then send 0 to the RX
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(2000);
}
}
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if(buf[0]=='1'){
// control your servo & all
digitalWrite(13,1);
}
if(buf[0]=='0'){
digitalWrite(13,0);
}
}
}
Hope it helps. All the best.
Thanks a lot. I think these codes would be helpful later.
But any suggestion on purchasing list? like the model of two Arduino boards
Sorry, I've seen your other thread but I don't know Tiny-GPS and (now that I've looked at your code) I don't know C/C++ Strings either. I try to learn as little C as possible.
My own approach to that sort of problem is to write the shortest possible sketch that allows me to experiment with the problem and show results in the Serial Monitor.