Tamiya Mercedes Benz G320 Cabrio with custom Arduino-based lighting

A few weeks ago I fell for my old hobby and felt like assembling a remote-controlled car. As a fan and owner of a real Mercedes-Benz vehicle, I chose the G320 Convertible SUV kit from Tamiya. As is usual with the rather simple Tamiya kits, they have no lighting, and I didn’t want to buy a ready-made RC lighting kit.  So I decided to build my own lighting based on an Arduino Nano-compatible controller instead. In this blog post I present my solution, in case you want to rebuild it.

IMG_20180318_140630

Goal of the Project

My goal was to equip my Mercedes SUV with headlights, front fog lights, and tail lights that could all be switched on and off using a spare channel on my remote. I also wanted to equip brake lights that would light up automatically while braking or reversing.

Mercedes Benz G320 kit

Before jumping into the lighting project, let’s first talk about the G320 kit from Tamiya. The vehicle is based on the MF-01X chassis, a rather simple SUV chassis with four-wheel drive. As usual, assembling the gearbox and the two differentials takes the most time (apart from cutting and coloring the body and applying the stickers). After about 4 hours I finished assembling the chassis, installed all electrical components (engine, servo, receiver, speed controller, battery), and made a quick test drive.

IMG_20180318_141439

As usual with Tamiya, the kit is of solid quality and can be assembled with little experience in building model cars. There are a lot of tuning parts for the MF-01X chassis available. In particular, I would recommend a ball bearing set (to replace the plastic bearings) and oil dampers.

Spraying the body and especially cutting out and applying the 70 or so stickers was quite time consuming and cost me another few hours of work. Before spraying the body I drilled the holes for the lights. I used a traditional black Lexan paint spray for the top. For the rest I used Tamiya 85038 Spray TS-38 Gun Metal. I would recommend that you darken the inside of the windows with Tamiya 86031 Spray PS-31 Smoke, so that you cannot see the many cables from the outside.

IMG_20180318_140636

Lightning system

Next up was the lighting system. I would like to say in advance that I am not an electronics engineer, and this was also my very first Arduino project. Any potential for optimization and improvements of my approach are therefore reserved.

I am using a Flysky FS-IT4S remote control which, together with some additional receivers, I ordered from AliExpress for less than US$150 in total:

It is a 4-channel remote control with comprehensive programming options. It was delivered with several sensors, which I did not use for this project.

My goal is to be able to switch on the lights (headlights, front fog lights, and tail lights) with channel 3 of the remote control, and with channel 4 the brake lights. Later on I would use the programming possibilities of the remote control to program channel 4 in such a way that it always deflects in the opposite direction to channel 2 (throttle).

Reading PWM signals

My remote control uses pulse width modulation (PWM) for signal transmission. Since I was not familiar with this technology, I did some online research and came across a blog post by Nick Poole (thanks, Nick!), that helped me to read the signals of my remote control on the receiver. The pulse signal on the individual channels is 1 millisecond at zero position, 1.5 milliseconds at neutral position, and 2 milliseconds at maximum position. Taking 0.1ms tolerance into account, I decided to switch the lights on or off if the signal goes over or below 1.6ms.

Choosing LEDs

Because I wanted to save the work of manually installing pull-up resistors along with the LEDs, I bought pre-wired LED strings from AliExpress:

I used the 6-LEDs strip as is for headlights, fog lights, and tail lights. I cut off the two 3mm LEDs from the 4-LED strip, and used the remaining two bright white LEDs with a red housing cap as brake lights.

Arduino circuit

I am using an Arduino Nano V3 compatible clone as my microcontroller, which I purchased from one of the many sellers on AliExpress for 2-3 US$. The Tamiya G320 kit runs with a 7.2V NiMH battery connected to the electronic speed controller that is included in the box. It delivers 6V DC to the receiver. I did not dare to connect the receiver VCC directly to the 5V connector of the Arduino Nano. Also I had no voltage regulator with only 1V dropout at hand, so I tried to operate connect the receiver VCC to the VIN connector of the Arduino Nano (which is actually designed for 7V or more), which worked without problems. This is probably one aspect of the overall solution that could be improved.

Another important point is the peak current of the I/O connections, which is 40mA. The 6 LEDs at 6V draw 70mA, so I had to use transistors to switch the lights. My wiring diagram looked like this:

G320_Steckplatine

  • Connect VCC and GND from the reciever
  • Connect VIN and GND from Arduino Nano
  • Connect I/O pin 3 to the signal pin of channel 3 on the receiver
  • Connect I/O pin 4 to the signal pin of channel 4 on the receiver
  • I used 2N2222 transistors to switch the LEDs. You can use cheaper options, but might want to chose the right pull-up resistor for the base. Connect the black wire (minus) of the first LED strip the collector of one resistor, and the red wire (plus) to VCC. Do the same with the second LED strip and transistor. Connect the emitters of both transistors to GND.
  • Connect I/O pin 9 to the base of the transistor switching the 6-LED strip, using a 2.2k resistor
  • Connect I/O pin 10 to the base of the transistor switching the 2-LED break lights strip, using a 3.3k resistor

Now it’s time to upload the sketch:

[EDIT 19.03.2018: added a code-based Schmitt trigger to prevent flickering, thanks to Raphael Krebs.]


// here's where we'll keep our channel values and led states
int ch3;
int ch3previous;
int ch4;
int ch4previous;

// the pins our channels are attached to
int ch3pin = 3;
int ch4pin = 4;

// the pins our leds are attached to
int ledpinHeadlight = 9;
int ledpinBrake = 10;

// the triggering signal width
int trigger = 1600;

void setup() {
// set the pin modes
pinMode(ch3pin, INPUT);
pinMode(ch4pin, INPUT);
pinMode(ledpinHeadlight, OUTPUT);
pinMode(ledpinBrake, OUTPUT);
}

void loop() {
// read the pulse width of each channel
ch3 = pulseIn(ch3pin, HIGH);
ch4 = pulseIn(ch4pin, HIGH);

// toggle headlight if ch3 was pressed
if(ch3 > trigger && ch3previous <= trigger) {
if(digitalRead(ledpinHeadlight) == LOW) {
digitalWrite(ledpinHeadlight, HIGH);
}
else {
digitalWrite(ledpinHeadlight, LOW);
}
}

// turn on break light if ch4 is triggered
if(ch4 > trigger) {
digitalWrite(ledpinBrake, HIGH);
}
else if(ch4 < trigger – 50) {
digitalWrite(ledpinBrake, LOW);
}

ch3previous = ch3;
ch4previous = ch4;
}

After uploading we can finally test our circuit:

  • Press and release the button for channel 3 on the remote control unit. This should toggle the lights on and off
  • Press and hold the button for channel 4 on the remote control unit. This should turn the brake lights on. Release the button to turn them off

IMG_20180224_170045

Next, we want to make sure that the brake lights light up automatically when the brake is applied. This can be achieved by configuring channel 4 of the remote control depending on channel 2 (throttle), so that channel 4 becomes positive when channel 2 becomes negative. The following picture illustrate the setting to be made in the”Mix” menu of the remote control.

RemoteMixConfig

Test your configuration by applying the brake. The brake lights should light up as long as the brake is active.

Circuit soldering

After I had confirmation that my circuit worked, I soldered the individual components together on a board. I removed the upper PINs of the Arduino Nano. I also used a 5-pin connector to connect the body, to which the lights are later attached, to the chassis on which the receiver is located.  I used a shrink tube to protect everything.

IMG_20180314_173340

Bringing it all together

Now comes the fun: attach everything together and try it out 🙂 I fixed the wiring harnesses and my Arduino with cable ties, which I attached to mounting lugs. I glued the mouting lugs to the body with two-component glue. For the LEDs I used sockets, which I also attached to the body with two-component glue. I fixed the LEDs in the sockets with some hot glue. The result looks like this:

IMG_20180318_141340

After this last step nothing more stood in the way of trying it out. My work of several hours was duly rewarded.

Do you have a similar project? Please tell me about it!

Acknowledgements

Special thanks go to:

  • Nick Poole, for his blog post about how to read PWM signals with Arduino
  • Raphael Krebs, for his help with transistors
  • My fiancee Sarah, for allowing me to spend hours in the basement tinkering

 

Advertisements

2 thoughts on “Tamiya Mercedes Benz G320 Cabrio with custom Arduino-based lighting

  1. Raphael Krebs March 19, 2018 / 08:29

    Hi Dieter,

    This looks great! Looking forward to some pics or videos of this Car driving in the dark 😉

    We did not talk about schmitt triggers yet.
    When applying a Pulse width of roughly 1.6ms you might encounter a flickering of your brake lights. That is because your on- and off-threshold have the same value of 1.6ms.

    Read more about the concept of schmitt triggers here: https://en.wikipedia.org/wiki/Schmitt_trigger

    In your scenario you may simply implement a software schmitt trigger that could look like the following example:

    // turn on break light if ch4 is above 1.6ms
    // turn off break light if ch4 drops below 1.55ms
    if(ch4 > trigger) {
    digitalWrite(ledpinBrake, HIGH);
    }
    else if(ch4 < trigger – 50) {
    digitalWrite(ledpinBrake, LOW);
    }

    Kind regards
    Raphael

    • Dieter Gasser March 19, 2018 / 20:19

      Thanks Raphael for your valuable input. I update the code to implement a schmitt trigger.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s