So i am trying to test out a linear potentiometer on one arduino, communicating it through serial to the other arduino via XBEE. I have the receiving arduino connected to an LED to simulate the motor for a quadcopter; as this is what i am using the xbees for. But while i move the potentiometer up, i see that the led goes to fullest brightness, then goes of when i get about 1/3rd the way up, then goes back down to no light and then as i approach 2/3rd way up, it goes back to the fullest brightness as it should, but then at the 2/3rd mark, it go off and does the same thing until i reach the top.
so as i am moving upwards on the potentiometer, the led goes through 3 cycles of being low then brightest.
here is the code:
//XBEE SENDING CODE
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.write(sensorValue);
delay(1); // delay in between reads for stability
}
///////////////////
//XBEE RECIEVER CODE
const int ledPin = 11; // the pin that the LED is attached to
int PotData; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0)
{
PotData = Serial.read();
int brightness = PotData;
analogWrite(ledPin, brightness);
}
}