0

Hi I am attempting to read from an rc transmitter using an Arduino Uno board, I have a signal pin connected from the receiver to pin 9 on the Arduino. Here is the code I would really appreciate some help all I am trying to achieve is the read the pmw from the receiver. I am able to plug a servo into the receiver and that works fine along with a motor I am just struggling when I try and use the Arduino with the receiver. When I run my program all I get in the Serial monitor are values such as 9991,9972,10030,10050 that are completely unrelated.

I want to have a pmw value that I can map to 0-255 in order to control a motor

My Circuit: battery -> ESC(for BEC to regulate five volts back to receiver)-> receiver -> ch3 signal pin -> Arduino uno (pin9)

void setup() {
  Serial.begin(9600);
}

void loop() {
  int pwm = pulseIn(9, HIGH, 25000);
  Serial.println(pwm);
  delay (5);
}
Oliver M
  • 13
  • 3

1 Answers1

0

You are using pulseIn which returns a time (in ms). The time being how long it waited for a HIGH signal. If you want the actual value, use analogRead. You can still use pulseIn, just don't use the return value

void setup() {
  Serial.begin(9600);
}

void loop() {
  byte pwm = analogRead(A5) / 4;
  Serial.println(pwm);
  delay(5);
}
Rojo
  • 2,749
  • 1
  • 13
  • 34
  • Thanks for the help however this still does not return a value that has anything to do with the signal from the controller have you got anymore suggestions? – Oliver M Mar 29 '21 at 15:43
  • @OliverM Try omitting pulseIn completely – Rojo Mar 29 '21 at 15:44
  • Hi thanks again for the help however i completely cut out the pulseIn line however i am now just getting different random values such as 370 but nothing changes as i move the sticks – Oliver M Mar 29 '21 at 15:47
  • Could you edit your question and include your wiring? It would also help if you included what exactly you are expecting. – Rojo Mar 29 '21 at 15:49
  • I have included the wiring and what i want to finally be able to achieve is to have the Arduino receiving values from the receiver in order to later control a motor or a servo ect. – Oliver M Mar 29 '21 at 15:55
  • If you want a value from 0-255, just divide pwm by 4. Also, an actual picture of the circuit would be better. – Rojo Mar 29 '21 at 16:12
  • I have now included a picture of the circuit and if i divide the value by four i will again just get random numbers as the value is just consistently around 400 which does not change when i move the stick. The current problem is that i cannot read the pwm value – Oliver M Mar 29 '21 at 16:31
  • You need to plug the yellow wire into the analog pins (A0 - A5) and I will update the code using A5. – Rojo Mar 29 '21 at 16:57
  • Thanks again for the help but it still isn't working once i have plugged to yellow wire into A5 have you got any more suggestions – Oliver M Mar 29 '21 at 17:10
  • Are you sure that the receiver is on? – Rojo Mar 29 '21 at 17:11
  • Yup if I plug the signal pin into the servo it works perfectly so that means the only problem is reading form the arduino – Oliver M Mar 29 '21 at 17:15
  • With the receiver plugged into the servo, does moving the joysticks on the controller have any effect? – Rojo Mar 29 '21 at 17:23
  • Yes when I plug the signal pin into the servo it moves as it should – Oliver M Mar 29 '21 at 17:37
  • So what do you need the Arduino for? – Rojo Mar 29 '21 at 17:38
  • Because I am attempting to be able to use the arduino to be able to override the servos to make an auto avoidance system – Oliver M Mar 29 '21 at 17:39
  • I don't see the problem. Remember: copy and paste my exact code into Arduino IDE, Receiver output pin to Analog Pin A5. If that doesn't work, try posting on [the Arduino forums](https://forum.arduino.cc/) or [Arduino stackexchange](https://arduino.stackexchange.com/) – Rojo Mar 29 '21 at 17:53