Go Back   RCCrawler Forums > RCCrawler General Tech > Electronics
Loading

Notices

Thread: Arduino based scale LED lighting - Wraith

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2015, 04:36 PM   #21
Quarry Creeper
 
Join Date: Jul 2015
Location: Hanover
Posts: 209
Default Re: Arduino based scale LED lighting - Wraith

While I'm waiting for parts to manifest for my CJ-5 build, I decided to work on the lights for my XJ.

Rather than make a new post, I thought it best to just add to this one. Awesome work by the OP!!!

I printed some light buckets, and re-worked my sketch.
If anyone wants the code, it's below.
some caveats....

the Arduino (upon power-up) looks to input 4 (throttle) and calls whatever signal it sees as "center channel," so if you get unexpected behavior, try cycling the power...

there are no turn signals. We don't use them.

Hazzards (4 ways) come on after 20 seconds idle.

the brake lights and rear "turns" are not connected, neither physically nor electronically. That is a different program...(just ask)

lots of blinky stuff happens if the Arduino suspects the signal is "out of bounds" with the throttle channel.

Brake lights work all three modes.
Mode 1; only brake lights.
Mode 2; Brakes and markers.
Mode 3, Brakes, markers, and Headlights.
Headlights fade when they're turned off...
Hazzards work in all three modes after 20 seconds, automatically. (as stated before)

If you don't have a three (or four) channel Rx, just "comment out" that input, and select your mode manually...

This is based upon a GikFun Pro Micro. 5v Arduino.

The Arduino cannot power the LED's directly. You must use a resistor. Your mileage will vary depending upon your choice of LED's.

because of the forward Voltage drop of my LED's
I'm using two outputs for the headlights. 10 and 3.
one output for the front two marker/flashers, 6
one output for the rear flashers, 9
one output for the brakes, 5

I've also designed a box in which to stuff everything. Ask me for the .STL if you have a 3d printer.
I'm thinking of selling the light buckets for the XJ, but I won't get into that here...

6 wires out.
4 wires in. (3 if you don't want to control the modes)

Any questions, just ask. You might be asking the same question someone else is too afraid of asking...
HANgOVER Airbrush RC is offline   Reply With Quote
Sponsored Links
Old 12-24-2015, 04:39 PM   #22
Quarry Creeper
 
Join Date: Jul 2015
Location: Hanover
Posts: 209
Default Re: Arduino based scale LED lighting - Wraith

as promised....(don't laugh too hard...
Code:
int rfhl = 10;  // pin assignments for headlights 
int lfhl = 3;
int front = 6;   //pin assignments for front markers
int brake = 5;   //brake lights
int rear = 9 ;     // pin assignment for rear markers

int modePin = 18;   //comment this out for 2 ch operation
int modeValue;      //for manual selection enter "= 1000", "=1500", "=2000" before the semicolon 
int dimVal = 20;         //placeholder for dimmer value
int blinkVal = 350;              //interval for hazzard light blink
int brite = 255;                 //brake light "brightness"
int dim;                    //brake light dim value
int db;                          //deadband center
unsigned int centered;           //is channel centered ?
int ch1 = 4;                     //pin assignment input
unsigned int pulseVal;
unsigned long currentMill;        //inactivity timer
unsigned long prevMill;           //inactivity timer 
unsigned int timerMet;           //inactivity timer
const int timerCon = 20000;      //hazzard delay time constant
unsigned long timerVal;           //inactivity timer
unsigned int dbLO;           //deadband width LO
unsigned int dbHI;          //deadband width HI
int hlState;                //used for dimming the headlights  1 is on.
int fadeValue;
int noSignalTag; 

void setup() {  //not much to see here, run once and go away...

pinMode (ch1, INPUT);       //throttle input monitor
pinMode (modePin, INPUT); //mode selector
pinMode (brake, OUTPUT);
pinMode (rfhl, OUTPUT);
pinMode (lfhl, OUTPUT);
pinMode (front, OUTPUT);
pinMode (rear, OUTPUT);
Serial.begin (9600);
db = pulseIn (ch1, HIGH);
dbLO = (db * .98);            //if the center position isn't wide enough try adjusting
dbHI = (db * 1.02);           // these constants to .9 and 1.1
}

void loop() {
  currentMill = millis();                        //timer
  pulseVal = pulseIn (ch1, HIGH);
  modeValue = pulseIn (modePin, HIGH);
  Serial.print ("deadband ");                    //debug stuffs
  Serial.println (dbLO);
  Serial.print  ("PulseVal ");
  Serial.println (pulseVal);
  Serial.print ("centered ");
  Serial.println (centered);
  Serial.print ("prevMill ");
  Serial.println (prevMill);
  Serial.print ("timerVal ");
  Serial.println (timerVal);
  Serial.println ("fadeValue");
  Serial.println (fadeValue);
timerVal = (currentMill - prevMill);



mode();                                       //mode check
if ((pulseVal > 2500) || (pulseVal < 700)) {  //if the signal is out of bounds...
  noSignal ();
}
  else if ((pulseVal >= dbHI) || (pulseVal <= dbLO)) {  //cecking for center
      centered =  0;
      timerMet = 0;
      prevMill = currentMill;
      analogWrite (brake, dim);
      noSignalTag = 0;
      
}
   else if ((timerCon >= timerVal) && (centered == 1) && (noSignalTag == 0)){  
        timerMet = 1;
} 
      else if ((timerMet = 1) && (centered == 1)){  //set "hazards" routine if centered too long
        hazzardRoutine ();
 } 
   else {
    centered = 1;
    analogWrite (brake, brite);
    
    }
}

void hazzardRoutine(){ 
  hlRoutine ();//turn your truck off or drive it!!!
  analogWrite (front, brite);
  analogWrite (rear, brite);        //change to "(brake, brite)" to use combined brake/hazzard
  delay (blinkVal);
  analogWrite (front, dim);
  analogWrite (rear, LOW);          //change to "(brake, dim)" to use combined brake/hazzard flash
  delay (blinkVal);
  return;
}
void noSignal () {            //so you know if there's no signal...
  noSignalTag = 1;
  digitalWrite (brake, brite);
  digitalWrite (front, brite);
  digitalWrite (rear, LOW);
  analogWrite (rfhl, brite);
  analogWrite (lfhl, dim);
  delay (50);
  digitalWrite (brake, LOW);
  digitalWrite (front, LOW);
  digitalWrite (rear, brite);
  analogWrite (rfhl, dim);
  analogWrite (lfhl, brite);
  delay (50);
  digitalWrite (brake, brite);
  digitalWrite (front, brite);
  digitalWrite (rear, LOW);
  analogWrite (rfhl, brite);
  analogWrite (lfhl, dim);
  delay (75);
  digitalWrite (brake, LOW);
  digitalWrite (front, LOW);
  digitalWrite (rear, brite);
  analogWrite (rfhl, dim);
  analogWrite (lfhl, brite);
  delay (100);
  return;
}

void mode () {        //ch3 input to select operating mode
  if (modeValue < 1400) {             //MODE 1  only brake lights
    dim = LOW;        
    hlState = 0;
    hlRoutine ();
    analogWrite (front , LOW);
    analogWrite (rear , LOW);
  }
  else if (modeValue > 1700) {        //MODE 3  headlights + parking lights
    hlRoutine ();
    dim = dimVal;
    hlState =1;
    fadeValue = brite;
    analogWrite (rfhl , brite);
    analogWrite (lfhl , brite);
    analogWrite (front , dim);
    analogWrite (rear , LOW);   //change to "dim" if you want them on as parking lights
  }
  else {                            //MODE 2  parking lights  (no headlights)
  dim = dimVal;
  hlRoutine ();
  analogWrite (rear , LOW);     //change to "dim" ifyou want them on as parking lights
  analogWrite (front , dim);
    if (hlState == 1) {
      hlRoutine ();
      }
    }
  }

 void hlRoutine () {
  if ((fadeValue >= 1) && (hlState || 1)){
  analogWrite (lfhl, fadeValue);
  analogWrite (rfhl, fadeValue);
    fadeValue = (fadeValue - 30);
  }

    else {
     digitalWrite (lfhl, 0);
     digitalWrite (rfhl, 0);
     fadeValue = 0;
     return; 
    }
    }
HANgOVER Airbrush RC is offline   Reply With Quote
Old 01-26-2016, 10:14 AM   #23
Quarry Creeper
 
Join Date: Jul 2015
Location: Hanover
Posts: 209
Default Re: Arduino based scale LED lighting - Wraith

I'm trying real hard not to HiJack this thread...but I feel it worthy of mention that I've re-written the code about four times since the above post.
There is added functionality, and most of the delay timers have been removed. This is important because it speeds up the program, makes it more reliable, and more responsive than my previous version.

If there is any interest at all, PM me (so we don't clutter this thread) and I'll share the code.
Or, if there's enough interest, I'll do a build thread/instructions set, as my schematics and the OP do not match.

Thanks again to the OP for tolerating me!!

Cheers,
HANgOVER Airbrush RC is offline   Reply With Quote
Old 01-26-2016, 11:18 AM   #24
I wanna be Dave
 
Join Date: Sep 2008
Location: PA
Posts: 10,299
Default Re: Arduino based scale LED lighting - Wraith

Awesome little project! Thanks for sharing. I'd love to know how to program Arduino.

Quote:
Originally Posted by HANgOVER Airbrush RC View Post
I'm trying real hard not to HiJack this thread...but I feel it worthy of mention that I've re-written the code about four times since the above post.
There is added functionality, and most of the delay timers have been removed. This is important because it speeds up the program, makes it more reliable, and more responsive than my previous version.

If there is any interest at all, PM me (so we don't clutter this thread) and I'll share the code.
Or, if there's enough interest, I'll do a build thread/instructions set, as my schematics and the OP do not match.

Thanks again to the OP for tolerating me!!

Cheers,
You could also start your own thread. I know many of us would appreciate it and it wouldn't bog you down with PMs.
JatoTheRipper is offline   Reply With Quote
Old 02-02-2016, 05:29 PM   #25
Quarry Creeper
 
Join Date: Oct 2014
Location: East
Posts: 227
Default Re: Arduino based scale LED lighting - Wraith

I'm not sure how I missed about 6 replies since December. Sorry for not posting back. Feel free to post here. I think it's a good resource to keep it all together. I don't feel your hijacking anything.

I'm in the middle of a rewrite, taking it to the next level. I'm dumping all the blocking code in lei of creating an actual loop. This means I'm am using interrupts to read and write pins. It will allow for multiple functions to occur and not wait for a function to finish. Translated, I can use my winch and change other functions without any delay in the code.

Example:



This was the Arduino controller I built for SCX10 Chevy. Full signals, tail lights. Everything I showed previously in this thread. What I added was a 6 channel receiver (of which I am using 5) for Lightbar brightness and transmitter controlled winch. I haven't finished the rewrite for this yet because the interrupts are also tide to pins that I am using. So, for a software update I have to rewire or replace the board with a revision 2. I am just starting to get back into winter building and hope to route a PCB sometime in the next month.

I can dump the code I have written though it is far from finished. I'm using calls outside the Arduino Library to access Interrupts and can post the resources on where I found the info

Last edited by drzoo2; 02-02-2016 at 05:47 PM.
drzoo2 is online now   Reply With Quote
Old 06-18-2019, 09:20 AM   #26
Rock Stacker
 
Join Date: May 2013
Location: Sweden
Posts: 55
Default Re: Arduino based scale LED lighting - Wraith

Is any one using this code anymore ? I am just started with Arduino and I wonder if someone has done some updating to this code, I would like it
quart is offline   Reply With Quote
Old 06-18-2019, 10:04 AM   #27
Quarry Creeper
 
Join Date: Oct 2014
Location: East
Posts: 227
Default Re: Arduino based scale LED lighting - Wraith

Quote:
Originally Posted by quart View Post
Is any one using this code anymore ? I am just started with Arduino and I wonder if someone has done some updating to this code, I would like it
Been a few since I started this thread.... I still have code. I just used it in my latest build last year. No updates. I was going to make it more efficient but never got around to it.




Sent from my HTC U11 using Tapatalk
drzoo2 is online now   Reply With Quote
Old 06-18-2019, 11:06 AM   #28
Rock Stacker
 
Join Date: May 2013
Location: Sweden
Posts: 55
Default Re: Arduino based scale LED lighting - Wraith

Thanks for your reply !
Like i wrote I am new to Arduino but done som html and php programming.
I am building a Scania truck and want to have some more lights then on my crawlers.

Hope you have time to help me.

The mode switch is it 2pos switch?
I would like to have it on a 3pos switch and have these functions.
0=off
1=Running lights
2= Running lights and markers.

I also want a switch for Hazzard light. Just a 2pos switch.
The last thing is reversing lights.

Done some editning in the code and also added one input for 2pos swtich and one output for highbeam.
Would really appreciate any help.
One simple thing I assume for any that can code,is the code for
Input CH2 and turn ocf on Highbeam
Dont need all code just pieces I can copy/paste to more functions
Here is the code now
Code:
int rfhl = A0;  // pin assignments for headlights 
int lfhl = A1;
int front = A2;   //pin assignments for front markers
int brake = A3;   //brake lights
int rear = A4;     // pin assignment for rear markers
int highb = A5;     //Highbeam

int modePin = 3;   //comment this out for 2 ch operation
int modeValue;      //for manual selection enter "= 1000", "=1500", "=2000" before the semicolon 
int dimVal = 20;         //placeholder for dimmer value
int blinkVal = 350;              //interval for hazzard light blink
int brite = 255;                 //brake light "brightness"
int dim;                    //brake light dim value
int db;                          //deadband center
unsigned int centered;           //is channel centered ?
int ch1 = 9;                     //Throttle pin assignment input
int ch2 = 10;                     // Radio 2pos Highbeam
unsigned int pulseVal;
unsigned long currentMill;        //inactivity timer
unsigned long prevMill;           //inactivity timer 
unsigned int timerMet;           //inactivity timer
const int timerCon = 20000;      //hazzard delay time constant
unsigned long timerVal;           //inactivity timer
unsigned int dbLO;           //deadband width LO
unsigned int dbHI;          //deadband width HI
int hlState;                //used for dimming the headlights  1 is on.
int fadeValue;
int noSignalTag; 

void setup() {  //not much to see here, run once and go away...

pinMode (ch1, INPUT);       //throttle input monitor
pinMode (modePin, INPUT); //mode selector
pinMode (brake, OUTPUT);
pinMode (rfhl, OUTPUT);
pinMode (lfhl, OUTPUT);
pinMode (front, OUTPUT);
pinMode (rear, OUTPUT);
pinMode (ch2, INPUT);
Serial.begin (9600);
db = pulseIn (ch1, HIGH);
dbLO = (db * .98);            //if the center position isn't wide enough try adjusting
dbHI = (db * 1.02);           // these constants to .9 and 1.1
}

void loop() {
  currentMill = millis();                        //timer
  pulseVal = pulseIn (ch1, HIGH);
  modeValue = pulseIn (modePin, HIGH);
  Serial.print ("deadband ");                    //debug stuffs
  Serial.println (dbLO);
  Serial.print  ("PulseVal ");
  Serial.println (pulseVal);
  Serial.print ("centered ");
  Serial.println (centered);
  Serial.print ("prevMill ");
  Serial.println (prevMill);
  Serial.print ("timerVal ");
  Serial.println (timerVal);
  Serial.println ("fadeValue");
  Serial.println (fadeValue);
timerVal = (currentMill - prevMill);



mode();                                       //mode check
if ((pulseVal > 2500) || (pulseVal < 700)) {  //if the signal is out of bounds...
  noSignal ();
}
  else if ((pulseVal >= dbHI) || (pulseVal <= dbLO)) {  //cecking for center
      centered =  0;
      timerMet = 0;
      prevMill = currentMill;
      analogWrite (brake, dim);
      noSignalTag = 0;
      
}
   else if ((timerCon >= timerVal) && (centered == 1) && (noSignalTag == 0)){  
        timerMet = 1;
} 
      else if ((timerMet = 1) && (centered == 1)){  //set "hazards" routine if centered too long
        hazzardRoutine ();
 } 
   else {
    centered = 1;
    analogWrite (brake, brite);
    
    }
}

void hazzardRoutine(){ 
  hlRoutine ();//turn your truck off or drive it!!!
  analogWrite (front, brite);
  analogWrite (rear, brite);        //change to "(brake, brite)" to use combined brake/hazzard
  delay (blinkVal);
  analogWrite (front, dim);
  analogWrite (rear, LOW);          //change to "(brake, dim)" to use combined brake/hazzard flash
  delay (blinkVal);
  return;
}
void noSignal () {            //so you know if there's no signal...
  noSignalTag = 1;
  digitalWrite (brake, brite);
  digitalWrite (front, brite);
  digitalWrite (rear, LOW);
  analogWrite (rfhl, brite);
  analogWrite (lfhl, dim);
  delay (50);
  digitalWrite (brake, LOW);
  digitalWrite (front, LOW);
  digitalWrite (rear, brite);
  analogWrite (rfhl, dim);
  analogWrite (lfhl, brite);
  delay (50);
  digitalWrite (brake, brite);
  digitalWrite (front, brite);
  digitalWrite (rear, LOW);
  analogWrite (rfhl, brite);
  analogWrite (lfhl, dim);
  delay (75);
  digitalWrite (brake, LOW);
  digitalWrite (front, LOW);
  digitalWrite (rear, brite);
  analogWrite (rfhl, dim);
  analogWrite (lfhl, brite);
  delay (100);
  return;
}

void mode () {        //ch3 input to select operating mode
  if (modeValue < 1100) {             //MODE 1  only brake lights
    dim = LOW;        
    hlState = 0;
    hlRoutine ();
    analogWrite (front , LOW);
    analogWrite (rear , LOW);
  }
  else if (modeValue > 1900) {        //MODE 3  headlights + parking lights
    hlRoutine ();
    dim = dimVal;
    hlState =1;
    fadeValue = brite;
    analogWrite (rfhl , brite);
    analogWrite (lfhl , brite);
    analogWrite (front , dim);
    analogWrite (rear , LOW);   //change to "dim" if you want them on as parking lights
  }
  else {                            //MODE 2  parking lights  (no headlights)
  dim = dimVal;
  hlRoutine ();
  analogWrite (rear , LOW);     //change to "dim" ifyou want them on as parking lights
  analogWrite (front , dim);
    if (hlState == 1) {
      hlRoutine ();
      }
    }
  }

 void hlRoutine () {
  if ((fadeValue >= 1) && (hlState || 1)){
  analogWrite (lfhl, fadeValue);
  analogWrite (rfhl, fadeValue);
    fadeValue = (fadeValue - 30);
  }

    else {
     digitalWrite (lfhl, 0);
     digitalWrite (rfhl, 0);
     fadeValue = 0;
     return; 
    }
    }

Last edited by quart; 06-18-2019 at 11:34 AM. Reason: Adding code
quart is offline   Reply With Quote
Old 06-20-2019, 11:32 AM   #29
Quarry Creeper
 
Join Date: Jul 2015
Location: Hanover
Posts: 209
Default Re: Arduino based scale LED lighting - Wraith

It's been a long time since I played with this...
The I remember it...


AUX1 fed an input to control the lighting mode. (Brakes only, parking lamps, headlights+parking lamps)
There was a Y cable that carried the signal from CH1 (throttle) that controlled the brake and reverse lights.


There was a simple routine that ran at startup, where the Arduino "learns" which way "forward" is, in order to reference "when to use reverse" lights.


The four-ways (hazard lamps) were on an "inactivity" timer and came on after 20 seconds of "no input" from the Tx. That timer was cancelled and reset every time an input was triggered.


The rest was all just "cosmetic" stuff, like making the headlights turn off slow (like an incandescent bulb does).


If you would like more help, let me know. I can help with my code build, but probable not anyone elses.
HANgOVER Airbrush RC is offline   Reply With Quote
Old 06-20-2019, 12:21 PM   #30
I wanna be Dave
 
Join Date: Sep 2008
Location: PA
Posts: 10,299
Default Re: Arduino based scale LED lighting - Wraith

Awesome stuff! Keep it up guys.
JatoTheRipper is offline   Reply With Quote
Old 06-20-2019, 12:23 PM   #31
Custom RC Electronics
 
heyok's Avatar
 
Join Date: May 2007
Location: Vancouver, BC
Posts: 2,217
Default Re: Arduino based scale LED lighting - Wraith

If you are looking for something already built, check out my stuff
heyok is offline   Reply With Quote
Reply



Arduino based scale LED lighting - Wraith - Similar Threads
Thread Thread Starter Forum Replies Last Post
Led lighting craddock35 Electronics 2 07-13-2013 02:29 PM
LED Lighting Help juswin24 Electronics 7 09-03-2012 07:55 PM
LED Lighting? Drey Electronics 5 01-19-2010 03:17 PM
Scale seats and LED roof lighting washracer_11 Newbie General 12 12-08-2008 05:43 PM
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -6. The time now is 09:34 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO ©2011, Crawlability, Inc.
Copyright 2004-2014 RCCrawler.com