Saturday, October 22, 2011

Servo Turns When RF Trigger is Tripped

This example shows how you could integrate an actuator with the original sender/receiver system.

To achieve this you will have to wire up a servo to ground, power and a control pin. Such as;
This fritzing diagram is from an old project of mine where we were controlling a servo from a switch via a web feed.

To integrate the Xbee with this system, using the proximity RF trigger instead of switch and web feed seemed an appropriate application for the Xbee trigger system. This could be useful in a number of situations such as an automatic garage door, which opens when you drive your car in range.

You will need to wire any extra components you are trying to integrate, into the breakout pins on the Xbee shield, in the same relative position as if you were plugging it straight into the pins on your Arduino.

To trigger the state of the servo with Xbee, the sender should remain as usual;

void setup(){
Serial.begin(9600);
}

void loop(){
Serial.write('d');
delay(100);
}


The receiver/actuator sketch will look something like this;

The possibilities for integration with your own systems are vast so I thought I'd go one step further, showing you how to add a sensor to the pictured sketch above. This will give the example system a new layer of complexity, adding new variables to test against and use in system function;

#include

Servo myservo;

int pos = 0;
int potpin = 0;
int val;

void setup(){
myservo.attach(9);
Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop(){
val = analogRead(potpin);
//val = map(val, 0, 1023, 0, 179);

if(Serial.available() > 0 && val > 500){
digitalWrite(13,HIGH);

for(pos = 0; pos < 180; pos += 1) { myservo.write(pos); delay(15); } for(pos = 180; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
delay(500);
Serial.flush();
}
else {
digitalWrite(13,LOW);
//delay(1000);
}
}

No comments:

Post a Comment