Every thing is better with LEDs, right?

rc lights body with lights

So my r/c car needed some. Options are just buy a kit and be stuck with the vendor possibilities or DIY.

Of course DIY!!!

After some brainstorming I decided to start small.

Level 1:

  • head and tail lights
  • break lights
  • some blinking
  • switch able from the remote

Lucky for me my remote control set has 3 channels and with it's already custom firmware I can program it to cycle throug -100%, -50%,... to 100%.

And a quick look into my electronic part bins showed yeah I have all needed parts.

BoM:

  • 4x LEDs
  • 4x matching resistors
  • bains >> Arduino
  • power main r/c battery
  • some connectors ( for connecting the receiver and the LEDs, I want to be able to easily disconnect it )
  • cables
  • hot glue

Basically the Arduino is connected in parallel to channel 2 and 3 ( throttle and the button) The Arduino reads the PWN signals from the receiver and does some LEDs blinking.

Simple right? No? here is a schematic thing

rc lights schematic

HW version 1, kind of huge ;-)

rc lights perfboard version1

HW version 2, better. rc lights perfboard version2

And a PCB idea

rc lights pcb

And the Fritzing project file rc-lights-v4-arduino-mini-pro.fzz

Software:

rclightv3_serialoutput.ino

/
RC Lights by Stefan.Schmidt@knallakoff.de

Utility.h for the foreach(), pachted for IDE 1.0
v4
pro mini

http://arduino.cc/playground/Code/Utility
patch http://markus.jabs.name/2011/12/arduino-kennt-wprogram-nicht-mehr/
/
#include <Utility.h>
boolean debug = false;

//def input for 3 channel
int channel1_pin = 14;
unsigned int channel1_pulse;
int channel2_pin = 15;
unsigned int channel2_pulse;
int channel3_pin = 16;
unsigned int channel3_pulse;


int lstates[8] = {0, 0, 0, 0, 0, 0, 0, 0};  //to stor the lights start.... only 1 used until now
// only 4 are used, more to come...
byte headr = 10;
byte headl = 11;
byte backr = 3;
byte backl = 6;
byte revl = 5;
byte tr = 9;
byte tl = 12;
byte ex1 = 13;

byte lights[8] = {headr, headl, backr, backl, revl, tr, tl, ex1};



void setup(){
    if (debug){
        Serial.begin(9600);
    }
    // input setup
    pinMode(channel1_pin, INPUT);
    pinMode(channel2_pin, INPUT);
    pinMode(channel3_pin, INPUT);

    // output setup
    foreach(lights, 8, pinMode, OUTPUT);
    // by default all LEDs are on, so you can see if they are working
    foreach(lights, 8, digitalWrite, HIGH);
}

void loop()
    {  
    // Read the channles, CH1 Steering, CH2 Throttle and 
    // CH3 multi position switch, -100%, -50%, 0%, 50% and 100% on my H-GT3b with 0.41 PSX Firmware, 4 of 8 are possible positions are used
    // CH1 disabled by default I do not use it (not connected) and this add delay so it does not blink so fast ;-)

    //channel1_pulse = pulseIn(channel1_pin, HIGH, 20000);
    channel2_pulse = pulseIn(channel2_pin, HIGH, 20000);
    channel3_pulse = pulseIn(channel3_pin, HIGH, 20000);

    // Some Debug to see what is read from the channels
    if (debug){
        Serial.print("c1: ");
        Serial.print(channel1_pulse);
        Serial.print(" c2: ");
        Serial.print(channel2_pulse);
        Serial.print(" c3: ");
        Serial.println(channel3_pulse);
    }

    //begin switching depending on CH3 position
    //CH3 100% - some fast single blinking (
    if (channel3_pulse > 1900) {
        if (lstates[4]== 0){
            digitalWrite(lights[0], HIGH);
            digitalWrite(lights[1], LOW);
            digitalWrite(lights[2], LOW);
            digitalWrite(lights[3], LOW);
            } 
        if (lstates[4]== 1){
            digitalWrite(lights[0], LOW);
            digitalWrite(lights[1], HIGH);
            digitalWrite(lights[2], LOW);
            digitalWrite(lights[3], LOW);
            } 
        if (lstates[4]== 2){
            digitalWrite(lights[0], LOW);
            digitalWrite(lights[1], LOW);
            digitalWrite(lights[2], HIGH);
            digitalWrite(lights[3], LOW);
            } 
        if (lstates[4]== 3){
            digitalWrite(lights[0], LOW);
            digitalWrite(lights[1], LOW);
            digitalWrite(lights[2], LOW);
            digitalWrite(lights[3], HIGH);
            lstates[4]= -1;
            }
        lstates[4]++;    
    }

    //CH3 50% - some 4 LED blinking slower
    if ((channel3_pulse > 1700)and (channel3_pulse < 1900)) {
        if (lstates[4]== 0){
            digitalWrite(lights[0], HIGH);
            digitalWrite(lights[1], HIGH);
            digitalWrite(lights[2], HIGH);
            digitalWrite(lights[3], HIGH);
            lstates[4]= 1;
            } 
        else {
            digitalWrite(lights[0], LOW);
            digitalWrite(lights[1], LOW);
            digitalWrite(lights[2], LOW);
            digitalWrite(lights[3], LOW);
            lstates[4]= 0;
            }
        delay(150);
    }

    //CH3 0% - LEDs blinking in X pattern - slower

    if ((channel3_pulse > 1400)and (channel3_pulse < 1700)) {
        if (lstates[4]== 0){
            digitalWrite(lights[0], LOW);
            digitalWrite(lights[1], HIGH);
            digitalWrite(lights[2], LOW);
            digitalWrite(lights[3], HIGH);
            lstates[4]= 1;
            } 
        else {
            digitalWrite(lights[0], HIGH);
            digitalWrite(lights[1], LOW);
            digitalWrite(lights[2], HIGH);
            digitalWrite(lights[3], LOW);
            lstates[4]= 0;
            }
        delay(300);
    }

    //CH3 -50% - normal 4 LED on (normal light) if CH2 is beaking /reverse rear LEDs blink
    if ((channel3_pulse > 1200)and (channel3_pulse < 1400)) {
        digitalWrite(lights[0], HIGH);
        digitalWrite(lights[1], HIGH);
        digitalWrite(lights[2], HIGH);
        digitalWrite(lights[3], HIGH);
        lstates[4]= 0;
        if ((channel2_pulse < 1300)) {
            digitalWrite(lights[2], LOW);
            digitalWrite(lights[3], LOW);
            lstates[4]= 1;
            delay(30);
            }
        if ((channel2_pulse < 1300)and(lstates[4]== 1)) {
            lstates[4]= 0;
            digitalWrite(lights[2], HIGH);
            digitalWrite(lights[3], HIGH);
            delay(30);
            }
    }

    //CH3 -100% - lights off, if CH2 is beaking /reverse rear LEDs blink 
    if ((channel3_pulse > 900)and (channel3_pulse < 1200)) {
        digitalWrite(lights[0], LOW);
        digitalWrite(lights[1], LOW);
        digitalWrite(lights[2], LOW);
        digitalWrite(lights[3], LOW);
        if ((channel2_pulse < 1300)) {
            digitalWrite(lights[2], HIGH);
            digitalWrite(lights[3], HIGH);
            }
        } 
    }

No comments

The author does not allow comments to this entry