1

my goal is to read a pwm signal from a rc receiver. For that i tried to use an arduino.

i ran this code on the arduino:

#define Pin 3

int pwm_value;

void setup() {
  pinMode(Pin, INPUT);
  Serial.begin(9700);
}

void loop() {
  pwm_value = pulseIn(Pin, HIGH);
  Serial.println(pwm_value);
}

Now i connected the 3rd pin with the output of the receiver. But instead of printing the correct pwm values they get printed completely crazy. Sometimes they are under 10 and sometimes they are over 10000. The receiver outputs the correct signal.

I also noticed that if i just touch the pin with my finger or if i only connect a single jumper cable without anything at the end, the arduino will read a pwm signal.

I have realy no idea to solve that. Can you please help me?

Thank you!

  • Are you sure it's PWM and not PPM? – Majenko May 9 '16 at 17:50
  • Did you also connect the GND of the Arduino to the GND of the receiver? In case you did you could try using pinMode(pin, INPUT_PULLUP); – Gerben May 9 '16 at 17:57
1

check if the problem is the fact you have set 9700 baud rate on your sketch while the commonly used 9600 is supported from arduino IDE.


I slightly modified your code and it works for me. Check if this works for you:

#define Pin 3
#define Source 5
unsigned long  pwm_value;

void setup() {
    pinMode(Source,OUTPUT);
    pinMode(Pin, INPUT);
    Serial.begin(9600);
    analogWrite(Source,500);
}

void loop() {
    pwm_value = pulseIn(Pin, HIGH);
    Serial.println(pwm_value);

}

when you connect pin3 with pin 5 you should get a consistent value on Serial(=967).

About getting signal on floating pins

Getting a signal on a floating pin is normal. When you have a cable attached it acts like an antenna. When you touch it, you are the antenna!

  • the serial connection over 9700 was the problem. with 9600 everything worked just fine. Thanks so much for the answer! – CarringDO May 9 '16 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.