Hi,
Scott from Salem.
I want to control a servo with two xbee series 1 radios. I started trying to to control the brightness of an led first as I want to understand what is happening, but alas, after several hours and internet searching, could not get the led brightness working. First the LED, then I’ll just substitute it with a servo using the servo.h library. I am sure the xbees are transmitting. I have power and association and recieve lights (xbee pins 13,15,6) all working fine. Can someone please help? Thanks
Here is my code:
// SENDER
int potPin = 0;
int val = 0;
int mapVal = 0;
void setup()
{
Serial.begin(9600);
pinMode(potPin, INPUT);
}
void loop()
{
val = analogRead(potPin);
mapVal = map(val,0,1023,0,255);
Serial.println(mapVal, BIN);
}
and receiver
//RECEIVER
byte incomingByte = 0; //initializes incoming Byte data from pot
int Led = 11;
void setup()
{
Serial.begin(9600);
pinMode(Led, OUTPUT);
}
void loop()
{
if(Serial.available() > 0);
{incomingByte = Serial.read();
analogWrite(Led,incomingByte);
}
}
What micros are your xbees hooked to?
Hello,
I am using Arduino rev3. Can you please help? thanks so much!!
Scott
http://www.jsjf.demon.co.uk/xbee/xbee.pdf
These are two separate problems.
- The LED
I would use the XBee’s analog feature for this.
-
Transmitting end. Requires arduino+xbee Have the arduino feed the xbee’s analog I/O a voltage such as if the LED were directly connected to the arduino.
-
Receiving end. Requires xbee The xbee analog i/o will output the voltage via pwm. You will need to filter this with a capacitor. This will be the voltage you will feed to the LED. Put an appropriate resistor in series as you normally would for an LED.
- The servo.
-
Transmitting end. Requires arduino + xbee. Pulse the DIO output of the xbee at 50 Hz with the appropriate PWM for your servo direction.
-
Receiving end. Requires xbee and possibly some transistor drive circuitry depending on the load of the servo. The Xbee DIO will output the same PWM that you fed it on the transmitting end.
…
To make this all happen you will need to configure the xbees such that the analog and digital I/O is set up appropriately. This is just an overview of how it will work. Also, I don’t know how well the DIO timing works. I’m not sure if it will work properly or not. If that doesn’t work there are other ways to tackle this problem too.
HI Groggory,
Thanks for responding. I am struggling with the code to get the LED working. I have the pot plugged into Analog 0. and to send it i use Serial.print(mapVal).
For the receiver I am using PWM pin 11 with the code:
if(Serial.available() > 0);
{incomingByte = Serial.read();
analogWrite(Led,incomingByte);
I can’t get the LED to change brightness. It is on but not changing. I thought I can Serial.write to the other xbee just like a wire. Can you please help me with the code, plus an explanation? I am trying to learn it but don’t have computer or electronic background. I can’t find a clear example and explanation.
Thanks so much.
Scott
Sorry, not enough energy to fully answer this question.
But go read up on xbee DIO. I think if you understand that you’ll figure out this problem.
https://www.google.com/webhp?sourceid=c … 80&bih=925
OK, Thanks. I’ll keep reading. I think I got it…