RC Control

Hello i've recently made a rc project using the L298N H Bridge motor controller. I'm confused on how to connect the L298N to the rc receiver. So I was hoping I could get help

Please tell us what you mean by "rc receiver" - a link or a picture would help.

Ultimately - you can't hook up the L298 directly - you need to have something in between to translate the signal from the receiver into the proper speed (pwm) and direction signals for the L298. This can be done with an Arduino.

Without knowing what the receiver is (and what signals it is outputting), it's not possible to help you further.

im using a futaba r2004GF receiver

Ok - so we're talking hobby grade, standard PPM servo signals.

So - basically you need to measure the PPM timing (1000 to 2000 uS, 1500 uS centered/neutral) - convert that into a number, then use that to drive the L298.

I'm going to describe how you would do it the "naive" way (which is a blocking method - something you don't want to do - but it will be ok for a single servo):

  1. Route the output for a servo from the receiver to a digital pin on the Arduino; be sure to connect the ground wire too.

  2. To the L298, you'll need to hook up three other pins from the Arduino to the enable pin and input pins for the L298; make note of what pins you use.

  3. In your setup() function, set the enable pin and input pins LOW (so the motor doesn't spin).

Steps 4 - 10 happen in the loop() function:

  1. Read the digital pin using the pulseIn() function - https://www.arduino.cc/en/Reference/PulseIn

  2. You will get a number between 1000 to 2000 - the number of uS of the pulse (the pulse length).

  3. If the number is less than 1500, you're going to tell the L298 to spin the motor one way, otherwise, tell it to spin the other way (by setting the proper IN0 and IN1 input pins to HIGH/LOW or LOW/HIGH).

  4. Take the number, and subtract 1500 from it - to get a value between -500 and 500.

  5. Take the number from step 7, and get the absolute value of the number with the abs() function - https://www.arduino.cc/en/Reference/abs

  6. Take the number from step 8, and map it to 0 - 255 using the map() function - https://www.arduino.cc/en/Reference/map

  7. Use analogWrite() on the pin connected to enable to send that value from step 10 as a PWM signal, to vary the speed - https://www.arduino.cc/en/Tutorial/PWM

Those are the basic steps - you may need to fiddle with the logic in step 6 to introduce a "dead band" - depending on how accurate the receiver outputs the PPM signal (and how accurate pulseIn() reads it). It would only take a couple of different if-then constructs to add such functionality.

You could, of course, expand this to more channels (in which case, you would want to create the steps as functions you could call for each needed input and output pin, to make the code easier to debug and use), but as I noted before, this current code is blocking (actually, the pulseIn() function is the one that does the blocking). As long as you can keep the loop running fast enough, it may or may not be a huge issue.

If it does become an issue - or you need to do other stuff where blocking would be a problem - then if you google "arduino radio control library" - you will find a few projects out there which are designed to solve this (while adding a lot of other features); the goal behind those libraries is ultimately to allow you to build your own RC transmitter and receiver (that you can customize and program, for instance). They are somewhat overkill for just reading the pulse timings from a standard RC receiver, but they do have functionality for that which is non-blocking.

Essentially, they work something like the blink-without-delay() sketch (but I think they also use timer interrupts or something like that, too - I haven't delved into the code of those libraries much) - so that the timing of the signal isn't blocking to the rest of the system, unlike the pulseIn() function.

For more information on the naive method I proposed as well, look up the code for something called the "Dagu Wild Thumper" - this is a robot chassis (and controller) made by a company called "DFRobot" - one of the regulars on this forum, named "Oddbot" - works for them, too (or at least, he did). The controller board, called the T'REX, is based around the ATMega168 and is compatible with the Arduino:


Here's the controller - and you can get the code and manual from links there:


...and some more information:


I hope this helps!


The pulseIn() function is an easy way to do this sort of thing and for a ground based robot, it would work well enough not to be a problem.

If the delay caused by pulseIn becomes an issue, then you might want to try the PinChangeInt library. I posted an example of using this library here.