This is a repost of a post from about 6 months ago. I forgot about the project when I couldn't get it to work and am trying to pick it up again. Any help would be greatly appreciated!
Hi Everyone!
I'm trying to make a wireless follow focus system for a DSLR using two Arduino boards linked with XBEE modules.
Parts List:
2x Arduino Duemilanove
2x XBEE Series 2 Modules with XBEE Shields
1x 10K Potentiometer
1x HiTec HS-422 Servo
I have managed to get the two Arduinos connected and I used the physical pixel application to confirm they were transmitting/receiving data.
I've written/bodged code to transfer the potentiometers position wirelessly to the second Arduino. However, although the transmitter is sending the potentiometers position correctly, the servo usually just jitters rather than responding to the position changes (although it will occasionally complete a full rotation).
I was wondering if anyone had any experience of this? Or if there are any glaring mistakes in my code?
Thanks
Sender:
int potpin = 0; // analog pin used to connect the potentiometer
int sensorReading; // variable to read the value from the analog pin
int lastSensorReading;
int threshold = 1;
int message;
void setup()
{
Serial.begin(9600); // Open serial Port
}
void loop()
{
sensorReading = analogRead(potpin); //Read Pot Position
sensorReading = map(sensorReading, 0, 1023, 0, 179); //Map Pot Position to 180 degrees
if (abs(sensorReading - lastSensorReading) > threshold)
{
message = sensorReading; // Only send serial data if change in position is significant
Serial.print(message);
lastSensorReading = sensorReading;
}
delay(15);
}
Reciever:
#include <Servo.h>
Servo myservo;
int servovalue;
void setup() {
Serial.begin(9600); //Open Serial Port
myservo.attach(9); // Servo - Digital Pin 9
}
void loop() {
if (Serial.available() > 0) //Check if data is being recieved
{
servovalue = Serial.read();
myservo.write(servovalue); //send recieved value to Servo
delay(15);
}
}