×

Hello there friend! SparkFun will be closed on 8/17/2018 @2pm for a company event. We will not be offering our normal Friday tour or Local Pickups during this time. We will resume normal operations on Monday 8/20/2018. Any orders placed after 2pm MT on 8/17/2018 will be processed when we resume normal operations. Have a great day!

Adventures in Science: Using an RC Hobby Controller with Arduino

Let's learn how to read PWM signals from an RC receiver!

Favorited Favorite 1

The first step in creating a combat bot is to get something driving! Without the ability to move, you can’t compete. Even with just a couple of gearmotors, wheels and a receiver, you can create a simple rammer or wedge bot capable of pushing opponents into hazards. On this episode of “Adventures in Science,” we look at reading signals from an RC transmitter and receiver set.

Most RC controllers, like the one shown in the video, send out wireless signals to a receiver. When you buy a transmitter/receiver set, the receiver can be used with a whole host of applications and is often used to control servos and motors. You really only need two channels (forward/backward and left/right) to make a drivable robot, but if you’re looking to control a weapon on your bot, getting something with a third channel is advisable.

Specialized modules, called Electronic Speed Control (ESC) units, can be purchased that accept the Pulse-Width Modulated (PWM) signals from a variety of RC receivers. However, we can measure these pulse widths using the pulseIn() function in Arduino and use it to control motors.

In the video, we read the pulse width from one channel, which can range from 1000 μs to 2000 μs and set the speed and direction of the motor accordingly. Note that we’re using a control stick that returns to center, so full back is supposed to be 1000 μs, center is 1500 μs, and full forward is 2000 μs. In reality, back is around 1100 μs, center is close to 1500 μs, and forward is near 1800 μs. We use a bit of math to convert that number to a PWM signal intended for motors (0 to 255).

We demonstrate this technique using one channel, so you can only drive back and forth. Not really useful for a combat bot, but it’s a start. Next time, we’ll look at mixing in a second channel for steering!

The demo code in the video can be found here.

What other tips can you offer for wiring up a receiver in a combat bot? I know, leaving everything on a breadboard isn’t ideal.


Comments 2 comments

  • Mr. Ben / last year / 1

    Great post Shawn! My plastic bot still uses an Arduino mini from code I borrowed from Sparkfun Nick several years ago.

  • sailer / last year / 1

    This is certainly a good intro, but using a pin for every pwm signal is a bit of a waste. Most receivers offer an extra servo header used to program the receiver to accept a transmitter. What would normally be the signal pin here usually carries a PPM stream with all the PWM values smashed into one channel with slightly different timings. I wrote a (probably inefficient) interrupt driven decoder a few years ago for a few robotics competitions. It’s stable as is, but could really use some TLC to get it into a library. Here’s a link if anybody wants to use it: https://github.com/RetrieverRobotics/resources/blob/master/personal_RX.h

    Right now it needs to be used on an actual interrupt pin (in limited supply on boards like the UNO), but since it’s tracking a CHANGE interrupt, could probably be adapted to use one of the PinChangeInterrupt libraries.

    Usage:

    #include "whatever_you_name_the_file.h"
    OrangeRX instance_name(interrupt_pin);
    void a_unique_handler(void) {
       instance_name.isr();
    }
    
    void setup() {
       instance_name.begin(a_unique_handler);
    }
    
    void loop() {
       if(instance_name.packetAvailable()) {
          instance_name.channelValue( _channel_ );
       }
       //instance_name.debug() // assumes that Serial.begin() has been called
    }
    

    P.S. I have trouble writing short comments. Oh well. : p

Related Posts

Recent Posts

Liquidation Sale

Tags


All Tags