Dr.Duino's Reactive Lighting Engine for RC Vehicles

Many, many moons ago I used to race my RC car every weekend. I loved everything about it, but then... you know... adult hood.

Well, over the summer I decided to reignite my inner child hood passion for RC car racing and started the hunt to buy something beefy.

Something which has the speed of a cheetah,  turning grace of a ballerina, and could take and dish out a beating like randy macho man savage!

After consulting with the great oracle (google) it began to whisper back to me

GET A Slash from traxxas, it said to me, it said...

After doing what us engineers do, (research until your eyes bleed), I traded my credit card digits for the sweet ride you see below!

This thing is no joke, when I tell you it's fast... I'm not kidding this thing has a max cruising speed of around 30 MPH!

That's a three, with a zero miles to said hour after it. While that may not seem fast as compared, to say, a space-x rocket, it is lighting quick on the ground.

When this little bugger is on flat pavement it chews through it like that giant worm thing from the movie tremors.

(Ridiculous side note* - Post writing of this blog, I realized those worms in the movie are called graboids... just thought you might like to know.)

BUT Alas It was missing something...

As I was playing with it, my inner enginerd began to rev its engine way into the red (see what I did there? One... One bad joke ah, ah, ah...)

Any who, I began to wonder what it would look like if I could light up not only the under carriage, but the entire car itself!

But the truck body I had on mine isn't transparent so that wouldn't do.

Luckily, traxxas does sell both a totally clear body and one with some parts blacked out.

I liked the latter as it would help diffuse the copious amounts of lighting I was going to strap to this thing.

However, strapping lights to this, just didn't seem like enough, I mean... come on... this is a huge opportunity to do something epic.

I realized I must do something with those lights which would do more than simply light up my ride.

What if I could tie the motion of the vehicle AND correlate it to various lighting patterns?


In order to do this, I knew I'd need an accelerometer/gyro. I love the MPU-6050 IMU, they are super simple to use and scarily accurate.

This module measures not only acceleration in XYZ directions but also outputs gyroscope data in XYZ.

This is where it gets its 6 Axis IMU from by the way, 3 from acceleration, and 3 from the gyro.

But the problem I had with using this module was I couldn't quite wrap my brain around which axis did I need to actually measure.

As the truck is zipping and bumping along, would it be clear which axis was actually reacting, and would I be able to translate that into a repeatable lighting sequence?

With that, I knew I was going to need to build a test rig so that I could test out the various directions in a reliable fashion.

I was going to need 2 things in order to accomplish my mission. 

1) A mechanical contraption of sorts to give me reliable and repeatable data.

2) An electronics platform which would allow me collect and react to the data.

Hand Me My Drill Please

What you see here is my trusty drill mounted to the shell of my see through slash body. This would allow me to spin the body so that I could monitor the data being spewn out at a few 10's of RPM's.

More on this in a bit.

Next I needed to figure out how I would actually collect the data so I could develop an algorithm for it.

Allow me to introduce what I now call my Reactive Lighting Engine! This would be the basis of my electronic platform!

Reactive Lighting Engine™

One immediate issue I hit was where would I all of the electronics needed in the vehicle itself?

Inside the chassis itself wouldn't work, just too much stuff there. I realized that inside the plastic body itself is plenty of room for 6 to 7 metric tons of electronics and lights.

So I reached for my recently released Dr.Duino shields called the Pioneer and Explorer Editions. You can see more here.

Since I needed to pack tons of electronics into my RC truck, the Pioneer was the natural choice. 

It runs on an Arduino Uno, its compact, has a few buttons which would be critical to helping me debug the axis issues I had (more on that soon), the MPU6050 and tons of LED sticks like the one you see on the Pioneer below.


Spewing Data

In order to make the most of the data, I had 2 ways in which to acquire it. The first would be with using the memory on the Arduino Uno itself.

I could do a bunch of test runs and store the data from the MPU-6050 to the internal EEPROM storage and then read it out on my PC.

But there were 2 problems with that. First, I didn't' know how much data I was going to need and I could potentially run out of room very fast.

Secondly, it was just too cumbersome. I wanted, nay, needed to see the data in real time.

So the only other way to make sense out of the data was to fling it out from a BLE module (bluetooth low energy).

As I drove the car around or as is spun around on my ryobi drill head, I would be able to collect the data wirelessly.

Break Out The Glue GUN!

Given the fact that I would inadvertently be performing barrel rolls through the air, and bashing into things at high speed, I needed to make sure the Pioneer would stay put.

So I whipped out my favorite tool next to my soldering iron, my glue gun. I began applying heavy beads of hot glue to the Arduino Uno (under the Pioneer) and the LED sticks.


MPU-6050 Data

As I eagerly started testing, the amount of data coming from the RC car was voluminous and I just couldn't make heads or tails of it.

I needed a way to easily control and monitor just 1 axis at a time. Using the Pioneer's built in push buttons and some fancy coding, I was able to send out only 1 axis worth of data at a time.

So for example, I would default to spewing out X data at power up, then accelerate the RC vehicle at light speed in just one direction. First forward, then reverse, left and right.

At the same time, someone would be monitoring the data from the BLE module on board via an app.

If we saw a rapid change in the acceleration data, we knew we had the right axis and more importantly were able to characterize what "Forward" looked like in the data.

We would then press the button the pioneer, and try another direction (Reverse) so on and so forth until we were clearly able to see changes in the data which were tied to motion.

This all worked great for the X and Y directions but Z that was the difficult part.

Pitch, Roll and Yaw

For the purposes of this project I really only needed to care about two axis, X and Z.

Where X is referred to as Pitch. Think of this like a seesaw, every time it moves up and down, its pitch is changing.

In the RC car, a positive pitch was when the nose of the car lifts up and the back of the car sinks down a bit.

A negative pitch is the opposite.

The other axis is the Yaw, this is spinning about the Z axis, in the RC car example yaw is when the car turns left or right.

 Making Sense Of The Data

Above is the data which was collected from the car in motion separated by axis. As you can see the X /Y (Pitch & Roll) data is easily differentiated, but the Z data (Yaw)... yeah... not so much.

This is when I broke out my ryobi test rig I mentioned earlier. This easily allowed me to collect data exclusively in the Z (Yaw) direction which simulated turning right or left.

As soon as I did this the data became very easy to discern and became cyclical just like the X and Y data you saw earlier.

 Putting It All Together

Now that all of the pieces came together, it was time to write the code to collect and react to the motion.

I wanted very clear indicators of the 4 directions so I assigned the following color scheme.

Green = accelerating

Red = Braking

Left = Yellow

Right = Blue

The first few attempts at the code didn't quite work right. When I was collecting the data I was very careful about only looking at one axis at a time and throwing out everything else.

Well... as soon as I enabled all of the code to work together, the positive and negative pitch values seemed to be fighting one another.

So even though it was accelerating and turned the shell of the body green, if I hit a bump the RC car would ever so slightly pitch backwards for a moment.

This in turn signaled to the code to turn the red leds on. However, since it was happening so fast, the colors mixed together creating a flashing orangish color.

While cool, its just not what I wanted.

So... what to do?

Setting Some Limits

The easiest way to address this was to set upper and lower limits which would only get triggered if certain motion was clearly detected.

After combing through the data, it was clear that while accelerating the numbers which came back from the MPU6050 were in the low 1000's. Even at max acceleration.

However, if I hit a bump or the car just bounced around a little during acceleration I would see numbers like 4500 or so.

Also, if I was performing a hard brake, the numbers were around 5000+.

So armed with that knowledge, I built a rudimentary filter to only turn on the RED led's when the number was above 5000.

This worked pretty well but I needed just one more tweak.

Moving Fast While Standing Still

For the times when the RC car was just sitting there, I wanted to put on a light show. So if the Arduino Uno noticed that there wasn't motion for 5 seconds, it would enter rainbow mode which looks pretty cool if you ask me!

The picture below is my traxxas slash sitting still for more than 5 seconds, but if you ask me, it looks like its moving really fast!

Well that's it, that my reactive lighting engine using the Dr.Duino Pioneer shield for its electronic heart and brain.

If you're interested in getting into Arduino the Pioneer platform is definitely for you. However if you are more of a power user, you may want to look at the Explorer Edition. Its has all the same components as the Pioneer, but can do much, much more.

For more information on both the Pioneer and Explorer Editions, click here.