Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By jairbj
#41200 Hi friends, I'm trying to read a pwm signal from my RC Receiver but anything is wrong with the results.

I tryed to run this code:

Code: Select allbyte PWM_PIN = D2;
int pwm_value;

void setup() {
  pinMode(PWM_PIN, INPUT);
  Serial.begin(115200);
}
 
void loop() {
  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
}


But it gives me so many random values:
1
10
467
2
1
2
1
2
1
1
1
1
1
2
1
2
1
2
1
4834
44
4873
41
106
76
42
623
1
1
2
393

If I plug an servo to this receiver it works great.

According to this picture this should be the values I need to get.
Image

Could you help me?
User avatar
By scanboostar
#49054 Hello,

I'm using the following code:

Code: Select all#define PWM_Source 2 // Pin GPIO2 of ESP01
#define Output_PIN 0 // Pin GPIO0 of ESP01

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(PWM_Source, INPUT_PULLUP);
  pinMode(Output_PIN, OUTPUT);
}

int pwmin;
int pwmhist = 1500;

void loop() {
  // put your main code here, to run repeatedly:
 pwmin = pulseIn(PWM_Source, HIGH, 20000);
  delay(30);

 if (pwmin == 0){     // filter out the "0" values
    pwmin = pwmhist;
 } else {
    pwmhist = pwmin;
 }

 Serial.println((String)pwmin); // for debugging

 if (pwmin < 1475 || pwmin > 1515 ){
    digitalWrite(Output_PIN, HIGH);
 } else {
    digitalWrite(Output_PIN, LOW);
 }
 
}