reading pwm


I have done a bit of googleing, and read a bit around the forum, trying to find out how i can read a pwm signal, i would like to read the pwm output on an rc channel, and then control a fan when the output is lower than 1100 say, in order to stop a motor getting hot when there is no airflow, it would be cool to use an arduino to do this based on the fact i have a few lying around, and that i could easily make up some funky throttle curves etc for an old rc handset that doenst have that ability.

I have found that pulseIn can be used, but i havent been able to find any example code or anything related to RC gear, does anyone have any pointers?


Generally this is not a thing people do. But the pulse in will work for you. Just do it, you don't need for some one to have done it first.

you´re right about not needing someone to have done it first, but being a rooky, it helps, heh heh ,

I assume i could do something like count the millis between the HIGH of the pulse in and work out the position of the RC stick from that,

i just dont know how

Just read the values and then print them out. Then you can see the range you get and you know what numbers to use in the map statement to convert it to the values you want.

This -

or this -

or like mike says, if you want to keep it simple use pulse in

Duane B

The better way to decode a R/C servo pulse is using an interrupt pin rather the pulsein.


looks good,

going to do some reading , thanks


thanks a lot man , that first link prints out my rc ranges from approx 1000 to 1900 ,

now time to get fiddling to see how to make it react to those ranges without screwing it all up,

then i will check out reading more than one signal at a time,

i think this will be a fun project,

Well the led on pin 13 is now being successfully controlled by channel one on my RC set without noticebly slowing the code,
I think I have the bug, this is going to be one of those projects that will take a lot of sleepy time out of my nights,

This car is controlled through Arduino, using more or less the same code. The arduino listens to what I want the car to do, then reads a gyroscope and decides whether to let me control the car or intervene if its rotating faster than the code thinks it should be i.e. spinning out. It does this about 100 times per second you should recognise most of the code from the other links.

Duane B

i will take a look , thanks,

i have another question which might be resolved in your code, but how can i control the servo via the arduino? i mean i have a led, with a 0-255 pwm signal based on stick position, so i have effectivly got a dimmer ,its all nice an all, but i want to know if i can manipulate the original servo pwm signal and then send it out to the servo, i know its possible with arduino because there are arduino based UAV´s all over the show,

A little late may be, but thought, as you need only a is it above / below a speed signal,

convert the PWM to analog, with a R/C, and use an alog input to read the resultant voltage.

just a thought,

You need the servo library, it does exactly what you want.

Here is a little intro - might be more complicated than you need, the library is very simple and easy to use -

Duane B

well , i have read through the servo library notes, and it looks pretty easy to use,

Im assuming that with the last bit of code the prints out the pwm signal to serial, i cna just put that value onto the write statement and get direct control over the servo based on the stick position,

i think thats a good way to startout experimentation.

I was going to try and build some acceleration curves into the programming to allow less wheel spin in loose ground or rain, but i just ordered an Rx for my good handset, so that plan is probly not worth persuing anymore,

I am however incredibly interested in your example of the ESP for the rc car. did you get it working well ?

well, I have the servo moving according to the stick position, and my pwm controlled led working at the same time, so that prooves that i can do more than just split the servo signal with a y cable and control other stuff accodringly, now i can try my hand at amking some crude throttle curves etc,

do you have a good link to how to use the gyro ? i have a wii motion plus iic gyro sat around after taking it out of a cuad build, maybe i can use that,