Programmable Headlights on an RC Car

Experimenting with smart LEDs on an RC Car…

These are Adafruit Pixie Chainable Smart LEDs and an Arduino Uno.  On the car I replaced both channel’s servo cables with Y-harnesses.   Plugging one end of each harness back in to the servo/ESC, the other end is used to connect to Arduino PWM input pins.  Reading those values and using that information to  control the LEDs.  Adafruit Pixie LEDs are chained together but individually assignable to any color by the program.  This allows for making turn signals when turning the vehicle and also being able to do other things with the lights when the car is throttled or neutral.  I only have two LEDs in this example, but you could string more than that together.

Source code for the video demo:

  This sketch is for two Smart LEDs on an RC car as programmable headlights.
     - Neutral position = "demon eye" red transition
     - Left turn        = left turn signal
     - Right turn       = right turn signal
     - Throttle         = blue, variable brightness
     - Full throttle    = white flashing

     Author:  John Reed

#include "SoftwareSerial.h"
#include "Adafruit_Pixie.h"

#define NUMPIXELS 2 // Number of Pixies in the strip
#define PIXIEPIN  6 // Pin number for SoftwareSerial output
#define UP        1
#define DOWN      2
#define INCREMENT 2
#define OFF       0
#define LEFT_LED  0
#define RIGHT_LED 1
#define BRIGHTNESS     200
#define MAX_BRIGHTNESS 255
#define FLASH_DELAY    100

byte SERVOPIN    = 3;
int servoPWM;
int throttlePWM;

#define MAX_RED 254
#define MIN_RED 20
int currentRed = 0;

// Servo signal PWM values
int leftThreshold     = 1400;
int rightThreshold    = 1600;
int throttleThreshold = 1550;
int fadeDirection     = UP;

SoftwareSerial pixieSerial(-1, PIXIEPIN);
Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &pixieSerial);

void setup() {

  pinMode(SERVOPIN,    INPUT);


  pixieSerial.begin(115200); // Pixie REQUIRES this baud rate

  // brightness is 0 to 255


void loop() {

  // Measure servo values and then map them to the lights
  servoPWM    = pulseIn(SERVOPIN, HIGH);
  throttlePWM = pulseIn(THROTTLEPIN, HIGH);

  if(throttlePWM > throttleThreshold){
  if( servoPWM < leftThreshold ){ turnSignal(LEFT_LED); } else if( servoPWM > rightThreshold ){

 * Slow fading red.
 * Since this is a slow light sequence, I needed to make it interruptable
 * so there isn't a delay changing to another light sequence.  I did this by maintaining the
 * current light value.  Once per loop I inc/dec the current light value(depending on whater it's fading in or out) 
 * and display it.  This gives the loop a chance to decide to do something else.
 * The fade rate is entirely dependent on the speed of the main loop.  If the loop is very busy, for example, demonEyes  
 * wont refresh as often.  Thus, the INCREMENT value can be changed to compensate.
void demonEyes(){
    if( fadeDirection == UP ){

        if( currentRed < MAX_RED ){ currentRed += INCREMENT; strip.setBrightness(currentRed); strip.setPixelColor(LEFT_LED, 255, 0, 0); strip.setPixelColor(RIGHT_LED, 255, 0, 0);; } else{ fadeDirection = DOWN; } } else { if( currentRed > MIN_RED ){
            currentRed -= INCREMENT;
            strip.setPixelColor(LEFT_LED, 255, 0, 0);
            strip.setPixelColor(RIGHT_LED, 255, 0, 0);

          fadeDirection = UP;


 * Flashes amber once.  Takes a NUMPIXELS(the LED number in the chain) that will flash.
void turnSignal(int ledNum){

    int otherLed;
    if( ledNum == 0 ){
        otherLed = 1;
        otherLed = 0;

    strip.setPixelColor(ledNum, 255, 125, 0);
    strip.setPixelColor(otherLed, 0, 0, 0);;

 * Bright white double flash.
void whiteDoubleFlash(){

    // Loop twice.  Two flashes
    for( int i = 0; i < 2; i++ ){
        strip.setPixelColor(LEFT_LED, 255, 255, 255);
        strip.setPixelColor(RIGHT_LED, 255, 255, 255);;


Autonomous Long Distance Test

1.1 Mile Autonomous Drive on the UC Davis campus


Took Bitzero out today on the UC Davis campus during the early morning hours for a long distance autonomous test drive.  It was a success.  A total of 1.1 miles driven.


Around KDVS and the Coffee House


The most valuable observation was around waypoint resolution.  The further away a GPS waypoint was, the more likely it would brush against the sidewalk on the way.  I believe this is happening because the calculated heading angle is much smaller at longer distance, and the less correction the vehicle thinks it needs.  The solution is a higher density of GPS points.   It will be particularly important on water when other forces come in to play, like wind and current.  This is why we test.

Problem Connecting DJI Drone to Android

Connecting my DJI Phantom 3 Standard to my Android(v7) phone has always been painful.  You connect to the drone’s Wi-Fi, and nothing happens.  You load up your DJI app and still nothing happens, you don’t get the usual Camera mode.

I’ve finally figured out how to do it reliably, and I’m writing it down because I did not find the answer online.  And right now, you’re standing in a field somewhere, looking for this information.

The key is to forget the Wi-Fi network before each and every flight.  Hopefully you did not change the password and forgotten it because it will ask you for it.



But if you didn’t change the password, then add the network WiFi again.  The default password is 12341234.  Don’t tell anybody I told you, ok?

Enter the secret password.



After 5 to 10 seconds you get the Magic Screen.  This is the screen of joy.   It makes me happy, it will make you happy too:

This the place to be.


Tap the “Wi-Fi has no Internet Access” notification.   This is it!  The Final Checkpoint.  Ankh.  Sanctuary.  Choose YES.

But don’t bother selecting the checkbox to “Don’t ask again for this network”.   It would seem reasonable that all would be well to check it.  But it won’t.  This is the source of much unhappiness and ultimate suffering.  The problem with doing that is the next time you try to fly, it doesn’t detect Internet and assumes there’s no reason to connect.  Worse, it’s not even going to ask you about it anymore.  And the key to fixing the problem is already described:  Forget the Wi-Fi network before every flight.

Don’t do it!



Open Water Test Three – Final Conclusion

Is this Lake Berryessa or Myst Island?


Today marks the conclusion of testing the airboat platform.  And the result is:  I will stop prototyping with it. The wind was a little higher today and the boat was unable to steer autonomously at the speed I intend to build a rover.   The rudders attempted to steer the craft, but the wind kept it from making the turn.  It appeared to be incorrectly sailing the wrong GPS point, but really it was in a state of balance with the wind.  When I switch to manual mode, I was able to overcome the force and drive normally, but that’s because i’m using a lot more throttle.  And that’s not how I intend for the drone ship to sail.  So that pretty much is the end of this boat type and I will need to do some brainstorming on what ship to buy or build next to get us to the next phase of this project.

Open Water Test Results – 1/20/18

Today I took AquaBitsTwo out for its second test in open water.  These are the results, notes, and lessons I learned…

Markley Canyon at Lake Berryessa
  • Wind.  I was unaffected by this during the first test and didn’t need to deal with it.  Today there was some wind.  Not very much, just a few miles per hour.  But my motor mount and rudder acted like sails and the boat wanted to align with the wind.  Boat bottom is flat.  I guess that’s what fins and keels are for, eh?  Couldn’t solve that problem on the water, but I did increase the propeller speed to mitigate it.  In general, I might be driving the boat too slowly.  Would probably be easier to do my initial tests and tuning at higher speeds to overcome things like wind or rudders not pushing the boat with enough force for a proper turn.
  • Before I increased the propeller speed, the boat was sailing as if it were going to the wrong waypoint.  Right now I can’t say if it was a problem of GPS code, or if it was simply trying and failing to overcome the wind.  This would have been obvious with a terrestrial rover.  Interesting problem.
  • I spent a lot of time trimming and tuning.
  • Realized I have no way of telling if the Arduino servo controls are correct, what if I had placed the servo horn on backwards?  I will be adding a test sequence during startup, maybe turn right for a few seconds so I have positive confirmation it is correct.
  • Something is triggering the boat to go in to automatic mode and run it’s “drive straight to get a heading” function.  I’m pretty sure the transceiver’s trim button is doing this and possibly something else.
  • I chose boats as a robotic platform because I didn’t think it would have as many obstacles as land based rovers do.  But I’m seeing wind now as an obstacle.  It’s just not as obvious visually as lampposts and mailboxes.  Someday(hopefully), current will be an obstacle to overcome as well.
  • My drone won’t fly if the battery is less than 15 degrees Celsius.  I did not know that.  No fun aerial photos.  Next time I’ll leave it in the car until I am ready.
  • Lots of boaters on the water at dawn on Saturdays.  There were at least six nearby.  Don’t they know it’s robot season?

Project Update: AquaBitsTwo

After the lessons learned building and launching AquaBitsOne, I’ve begun to scope out ideas for the next version, hereby named AquaBitsTwo.  Rather than custom build something out of foam or wood, I ended up deciding to just try out a body board.  Found this at Leslie’s Pool Supply:  a Big Lizard 24/26 Inch Small.   It was only nine dollars.

Size comparison photo shows it’s a near identical replacement. Except that it will lack one critical flaw of the previous version:  it cannot leak.

AquaBitsOne and Next Version Comparison.  Ribbit!


It looked like it was covered in fabric so next it was stripped to bare foam.  Setting the motor and rudder back on top and it sure looks like we are back in action!

The beginning of AquaBitsTwo

I might install the electronics in a waterproof case, though I don’t think this necessary yet for where I’m at in the project.  It is driven slowly and the lake surface is pretty stable.  I have a lot of testing I need to do before I worry about making it sea worthy.  Any old storage container will probably be fine for now. We’ll see.  I estimate that I should have a working version ready for launch this  weekend.

Lessons on the First Open Water Test

It’s never too early to go out and play with robots.

Just returned from Lake Berryessa for my first ever autonomous boat test on open water.  Some notes so I don’t forget the lessons learned.

  • I managed to get three test runs in for trimming and adjusting the turn rates.  Unfortunately,  it turned out the boat leaks and that was all I could do.  I did test it in a tub and in a creek, but I should have let it soak for a long time to determine if any issues would arise by longer periods of time in the water.  I was about to send it off on a longer journey so thankfully I checked, I don’t think I would have gotten it back.
  • I set a GPS point too close to shore.  I didn’t have the confidence to set it way out in the open water as I have no means of retrieving it(like say, if it started leaking).  A couple of times during a test I had to take manual control since it was going to run ashore.  This didn’t allow me to determine if it was actually going to the waypoint or not, and what might have been going wrong.
  • Think I’m going to need some type of recovery vessel.  I have a wet suit, perhaps I should have brought that for worst case scenarios.
  • A headlamp flashlight would have been ideal.
  • It was a steep hike to the shore, all my gear should have fit in one backpack.
  • Obviously, cheap DIY foam board boats are out.  It’s time to brainstorm a new craft.
Lake Berryessa 1/15/18

Not quite a success.  Not quite a failure.  Of all things to happen, it was actually  pretty good.  Some important lessons learned without any losses.  And some nice pictures.  Got to experiment with robots, see nature, take some pictures.  Maybe it was a success.

How to use a Spektrum DX4C’s Switches in Arduino

These are my notes on how to use a remote control’s switches to control extra features of a robot.  In my case, I have an autonomous rover and would like to build a switch to press on the remote control to stop the rover and take manual control over it.

I used a Spektrum DX4C transceiver.

Switch Channel 3 is highlighted in red.

First, I configured the Spektrum  DX4C profile model in memory so that Channel 3 will be used as a switch.  To do this:

  1. Press the scroll wheel and select your Model to configure
  2. Next, scroll down to Switch
  3. For menu selection “A:”, choose Aux1 SP2

Next I connected a pin wire from the receiver.  On my Spectrum SR3100, this was labelled Aux.   I connected the wire to an Arduino PWM capable pin(5).  Make sure the receiver has power.  You can get it from the Arduino board’s 5v and ground pins.

The following sketch allowed me to read the values of the switch:

 * To read the values go to Tools | Serial Monitor

byte pin = 5;
int value;
void setup() {
  pinMode(pin, INPUT);
void loop() {
  value = pulseIn(pin, HIGH);


Pressing the switch gave me approximately the following PWM values:

Switch On:  1900

Switch Off: 1100

Radio Off:  1500

In conclusion, these values would be used in an Arduino sketch to control a robot’s behavior.  Use code logic to determine if the switch is on/off and use that to display a light, play a sound, or any behavior altering characteristic you can imagine.


Lessons Learned Making My First Boat

Just got the boat on the water for the first time and I wanted to jot down my thoughts while they’re still fresh.  This was the first time I’ve ever made a boat, or an RC model of any kind.   When I realized I could make them from Dollar Store foam and hot glue I was very impressed and happy to do so since I could get on the water for free, essentially.  As the build progressed though, I started to feel like it was a lot of work for a temporary boat.  Once on the water it snagged in some tree limbs and now has a small hole poked in it.  So the foam board build is out for sure.   Not sure I even want to do more testing, it’s not very robust.  Possibly on a lake it might work.  Possibly.  On the plus side, if something goes wrong and I lose the craft, I wouldn’t have lost much.  So there’s that.  If I were to do this again, for the effort, I would use a kit or spend on a pre-made boat.  But then you have the consequence of losing something more valuable(money, time, effort to build).

The boat did float very well.  The hull was made two inches high and it barely sank below the water line but a quarter of an inch.  This shape will tolerate quite a bit of weight, like extra batteries, solar cells, sensors, radio.  Probably also means it’s more than I need and I could go with a catamaran style with less friction that will go a little faster for the same energy.

It’s not an easy platform to test.  You need water and if something goes wrong, retrieving it is not simple.  I was testing in a creek and navigation was weird.  I’m so used to thinking of boats with rudders that an airboat is something to get used to.  I suppose it would be fine in large open space, but since the end goal is the ocean, I really doubt I would use an airboat so I’m at a bit of a loss on what to do next.  The boat sailing at minimum speed has a very low current draw(240mA), which is really nice.  It’s hard for me to imagine, but based battery capacity, that’d be a couple of hours of run time.  It would seem I could go multiple miles at that rate.  That would need to be tested, but that’s very appealing.


240mA current draw


As I wrap this up, I think I’m concluding that I will move forward with putting my Arduino GPS system in this boat and take it on a lake.  It’s inexpensive, if something goes wrong it’s not a big deal.  If I can get it to navigate two waypoints over a hundred yards it would be a smashing success.  I’ll have more faith in the code and hardware I’ve built to scale up to the next level of cost and effort.

Having a blast.


New Project Announcement: AquaBitsOne

We here at, me), are excited to announce our next phase in rover robotics: AquaBitsOne.  This will be a prototype vessel that shifts us from terrestrial exploration to aquatic.


Protype in aquatic form
Taking us to the next phase in autonomous robotic exploration.

Over the years I have begun to fine tune my own personal development methodology, which involves setting up one big annual goal divided up in to steps that I map out as monthly goals.   You could say it is Agile Methodology applied on a personal level.  One Epic of twelves sprints that are four weeks long each.  With the New Year brings new goals in my life and the beginning of my 2018 Epic.

And this will be to achieve an oceanographic vessel that travels autonomously using GPS and transmitting its current location with APRS.  It should be capable of traveling at least one mile in the Pacific Ocean in good weather.  I also have a stretch goal of being able to record thirty minutes of underwater audio using a hydrophone.

We begin with the first Story of our first Sprint.  AquaBitsOne.  This is essentially an airboat using salvaged aircraft electronics.  It is the first prototype, and is made from cheap dollar store foam that has been waterproofed with polyurethane.  I chose this form because I already had everything needed to get started.  It means I can start testing the code and hardware developed from BitZero, on the water and at no cost.  Will it work?  I don’t know.  Does it matter?  No, we will iterate until it does work.  Is this thing going in the ocean?  Doubtful.  Again, we will iterate and learn as we go along.

So let’s do this.

Happy New Year!