Ok, so the other day I wrote this code to read the PWM outputs from an RC receiver. I have done a bunch of trouble shooting on it and I still don't see the problem. Normally on an RC receiver the pulse width is between 1000 and 2000 microseconds. For a few days the code worked. When the throttle was full, the serial monitor read 2000, at half throttle it read 1500, and a full reverse it read around 1250. Now no matter the location of the throttle, the serial monitor gives a reading upwards of 4000 microseconds, even reading 11000 microseconds at times. Obviously the problem is hidden in the code, yet no parts of the code or electrical setup have changed. I greatly appreciate some help.
Here is the code:
// controller pins
const int CH_2_PIN = 11;
void setup() {
Serial.begin(9600);
}
void loop() {
int ch_2 = pulseIn(CH_2_PIN, HIGH, 25000);
Serial.println(ch_2);
delay(5);
}