Author Topic: Sequential Taillight using Arduino Pro Mini (Thread Change from 555 Delay Timer)  (Read 51245 times)

0 Members and 1 Guest are viewing this topic.

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: 555 Delay Timer.
« Reply #75 on: January 08, 2016, 05:18:39 am »
what about make the 1st LED fade once the 3rd LED is lit? then 2nd led fade when the 4th (not there of course, just imaginary) hits, and so on.  Like a chaser LED
That's happening in your simulation for some reason, probably. It doesn't happen in real life (for me anyhow). The LEDs are turned on by digitalWrite statements and these can only be "low" (ground) or "high" (+5V), so there is no way that the code itself could be fading the LEDs.



(I put the potentiometer reading "delayOn=map()"  statements in each "if" function but it should work as you have it just as well, as long as the rest of the code doesn't change much.)
« Last Edit: January 08, 2016, 05:20:51 am by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: 555 Delay Timer.
« Reply #76 on: January 08, 2016, 05:28:02 am »
As far as using a button-press to do the rate variation... I can't figure out how to keep the set value constant between power-cycles, using a momentary pushbutton. It would reset to some initial value each time the unit is powered on or restarted, and you'd have to reset it to your desired rate each time. A DIP switch/resistor array would keep the desired value between cycles, or of course a trimpot would do the same; once it's set it will "remember" the setting.

Maybe someone else knows how to maintain a non-volatile variable setting across power-cycles, without using some external storage medium like a flash memory (and its associated overhead).
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: 555 Delay Timer.
« Reply #77 on: January 08, 2016, 05:41:06 am »
I have a question about the breadboard in the Simulation. Many "real" breadboards, and also in simulations, have the power rails split into left and right halves. Is your breadboard connected internally across the middle gap? I guess it must be, if your potentiometer control is working.

The easiest person to fool is yourself. -- Richard Feynman
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #78 on: January 08, 2016, 05:44:18 am »
yes, it is
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: 555 Delay Timer.
« Reply #79 on: January 08, 2016, 05:49:29 am »
OK, I just read up on the EEPROM in the Arduino. It turns out that you can use this memory space to store variables that will persist across power cycles.

So with some clever coding you could set your desired delay by pushbutton presses, then write the variable to the EEPROM for "permanent" storage. Then read it from the EEPROM when the power is on again.

https://www.arduino.cc/en/Reference/EEPROM
https://www.arduino.cc/en/Tutorial/EEPROMWrite
https://www.arduino.cc/en/Tutorial/EEPROMRead

I've obviously never done this myself, but it seems to be a handy answer to the problem.



The easiest person to fool is yourself. -- Richard Feynman
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #80 on: January 08, 2016, 05:51:37 am »
For the non-volatile storage - look at the Arduino EEPROM library
Easy to use and saves across power cycles.

Keep in mind - try to minimise the number of write cycles - as FLASH EEPROM has a finite number of cycles (a lot, but a micro can blitz through them pretty quickly)...  so for example, only save the value 5 seconds after the last change (another example of async programming), thus when you are stepping through delay perriods, it doesn't write every time.

I'm looking at the existing code, and trying to simplify it a bit - without going to a full state machine.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #81 on: January 08, 2016, 05:53:59 am »
i'm drawing up schematic now.  only schematics i found were rom eagle. i had to download free version. trying to convert the file to diptrace now. i'm more familiar with it.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #82 on: January 08, 2016, 06:25:14 am »
Here's some code...
Derived from your original example
Not tested, but it compiles without errors

Code: [Select]
/*--------------------------------------------------------------------------------------//
           3-Light Sequential Brake/Turn Signal Actuation
           (Both Left and Right sides)
//--------------------------------------------------------------------------------------*/

#define PotInput A5
#define BRAKE_SWITCH (digitalRead(RightTurnSwitch)==HIGH && digitalRead(LeftTurnSwitch)==HIGH)

const int LeftLED[] = {10, 11, 12};
const int RightLED[] = {5, 4, 3};
const int LeftTurnSwitch = 8;
const int RightTurnSwitch = 7;

int delayPeriodMS = 250;  // declare delay time (default 250mS)
// this can be stored in EEPROM if needed

boolean Rstate=0, Lstate=0;

// *********************************************************************************
void setup() {
  for (int counter = 0; counter <= 2; counter++) {
    pinMode (RightLED[counter], OUTPUT);   // Right: connect LEDs, relay drivers or mosfet Gates here
    pinMode (LeftLED[counter], OUTPUT);   // Left: connect LEDs, relay drivers or mosfet Gates here
  }
 
  pinMode (PotInput, INPUT);
 
  //  connect Brake/Turn signal here (through divider or regulator to give ~4-5V when ON)
  pinMode (RightTurnSwitch, INPUT); // Right ts/b
  pinMode (LeftTurnSwitch, INPUT); // Left ts/b       
}

// *********************************************************************************
void loop() {
 
  delayPeriodMS = map(analogRead(PotInput ),0,1023,0,500);

  // the following block is a bit shady, and works by coincidence - as there are nested conditions
  // testing for true and false on the *same* variables - it should be rewritten if possible.
  // ideally as a state machine - but this works with blocking delays
  // ----------------------------------------------------------------------------
  if (digitalRead(RightTurnSwitch) || digitalRead(LeftTurnSwitch)) { // a switch is 'on'
    // ----------------------------------------------------------------------------
    // LEFT-RIGHT TURN INDICATORS
    // ----------------------------------------------------------------------------
    if (!Rstate) {   // If lights are already on, skip turning them on again
      delay(20);    // short pause to allow read/writes to proceed without interference
      // when Right signal goes High, actuate R outputs in sequence
      if (digitalRead(RightTurnSwitch)==HIGH && digitalRead(LeftTurnSwitch)==LOW) {
        Rstate=1;
        for (int counter = 0; counter <= 2; counter++) {
          digitalWrite(RightLED[counter], HIGH);
          delay(delayPeriodMS);
        }
      }
    }
    // ----------------------------------------------------------------------------
    if (!Lstate) {   // If lights are already on, skip turning them on again
      delay(20);    // short pause to allow read/writes to proceed without interference
      // when Left signal goes High, actuate L outputs in sequence
      if (digitalRead(RightTurnSwitch)==LOW && digitalRead(LeftTurnSwitch)==HIGH) {
        Lstate=1;
        for (int counter = 0; counter <= 2; counter++) {
          digitalWrite(LeftLED[counter], HIGH);
          delay(delayPeriodMS);
        }
      }
    }
    // ----------------------------------------------------------------------------
    // BRAKE LIGHTS 
    // ----------------------------------------------------------------------------
    if ((!Rstate) || (!Lstate)) {    // If lights are already on, skip turning them on again
      // when Brake (both) signal goes High, actuate R and L outputs in sequence
      if (BRAKE_SWITCH) {
        Rstate=1;   Lstate=1;
        for (int counter = 0; counter <= 2; counter++) {
          digitalWrite(RightLED[counter], HIGH);
          digitalWrite(LeftLED[counter], HIGH);
          delay(delayPeriodMS);
        }
      }
    }
  } else {  // no switches are on
    // ----------------------------------------------------------------------------
    // turn OFF ALL LIGHTS
    // ----------------------------------------------------------------------------
    // when signal goes LOW turn off all outputs
    for (int counter = 0; counter <= 2; counter++) {
      digitalWrite(RightLED[counter], HIGH);   Rstate=0;
      digitalWrite(LeftLED[counter], HIGH);    Lstate=0;
    }
  }
}
// *********************************************************************************
// end

MODIFIED PotInput within the analogRead() call. 
Only done for completeness
« Last Edit: January 08, 2016, 06:48:25 am by SL4P »
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #83 on: January 08, 2016, 09:33:16 am »
since the LED's will be drawing power off a wire I'll bring to the back of the truck....I need to splice off that wire and supply 9 volts to run the Arduino, as well as the mosFETS for switching.  WOuld a Small 100mA LDO Voltage regulator work for that?

Like one of these...

http://www.mouser.com/ds/2/405/ua78l09a-407362.pdf
http://www.mouser.com/ds/2/389/CD00000446-355303.pdf
http://www.mouser.com/ds/2/149/KA78L09A-185607.pdf
http://www.mouser.com/ds/2/308/MC7800-D-94905.pdf

there's even more, and I may decide to do Surface Mount. Depends on how much I can get cheap PCB's made up.

Anyway, back to the Designing.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #84 on: January 08, 2016, 09:40:15 am »
Worst case SIX LEDs on at a time - plus any other indicators and the arduino board.
If they are single 20mA LEDs (even running at 10mA), but somewhere I recall that the actual indicators had more than one LED per 'window'...

You need to figure out what's being drawn - and tot that up with a minimum 20% headroom, as the regulator and other parts may de-rate with higher temperatures... (datasheets are your friend!)  Also ensure the regulator is adequately heat-sinked.

Remember our earlier reference to noisy & spiky automotive power sources...  high voltage that may cook your regulator - so check input range, and add protection in front of that !
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #85 on: January 08, 2016, 09:47:14 am »
yes, Data sheet on LED's say 243mA per LED.

But, those will be run through the mosFETs.  Not going through the Voltage Regulator at all.

 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #86 on: January 08, 2016, 10:14:50 am »
Yep - good point - so they are on the dirty side of the regulator - excellent.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #87 on: January 08, 2016, 10:20:27 am »
ya. I thought that would be the best.

Now, you mentioned something about dimming the lights during the night...but that would require tapping into headlight switch and running another wire back.

But, what if we tapped into the Taillight (running Lights)?  That wire is one of the three going to the back. on each side.  Also, if the lights are on during the day, how would we detect that? Some people drive with lights on during day, I do sometimes. When that happens, we don't want lights to dim. I don't think a Photoresistor would work, as this unit will be under the truck and sealed in a box.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #88 on: January 08, 2016, 10:28:44 am »
First requirement for PWM, is to use output pins that are compatible with analogWrite()...

Then to answer your other question... hmm can't think of the best idea there.
Some euro and jap cars already have light sensors built in for this, but not sure how we'd retrofit in your case.

Just BTW, are your turn indicators yellow, or they same lens/red with the tail/stop...
If the tail lamps are not controlled in this project.l are they different bulbs?
Also combined stop/tail bulbs are often dual filament 25/5watt (bright/normal)

If this is all designed in it can be included with the Arduino...  (writing the requirements doc on the fly!)
Don't ask a question if you aren't willing to listen to the answer.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #89 on: January 08, 2016, 10:30:17 am »
Di d you try my modified code ?  just interested...
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #90 on: January 08, 2016, 10:55:12 am »
Not yet. Have not entered your code yet. Still working on the schematic.

Yes, the LED's are red for the running lights as well, enclosed into the same LED package. I'm not sure how they work, but I believe there is separate LEDs inside for that operation.  If not, they are on resistors or something to make them not so bright, and when the brakes are applied or turn signals, it overrides them.

It's all internal in the light.

When I hooked up the 555 timer, it was just with the turn/brake input, and then the running was just wired direct from the truck. It still worked as it should. Dim LED's for running light, but got brighter when blinker or brakes applied.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #91 on: January 08, 2016, 10:56:51 am »
ok, as long as you're happy with the result!
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #92 on: January 08, 2016, 11:07:14 am »
Here's the schematic. I'm not sure I need the Resistors with the mosFETS?  Q1 and Q2 can be regular, while the others will need to be Logic Level.

The Voltage Regular will be a small 100mA model.

C3 need to be electrolytic?

Anything else you see that should be addressed in the schematic?

Hmm, just thought of something......

If it's at night time (daytime too if lights are on), the LED's won't turn completely off during the sequencing because of the running lights. So, Looks like may need to implement that into this.  There's JUST enough pins to do this, but will have to change 3 of the analog pins into digital. I would need 6 out for the LED's, and one in for the trigger.

If I need more, I'll need to upgrade to a Nano or Micro

« Last Edit: January 08, 2016, 11:26:52 am by Falcon69 »
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #93 on: January 08, 2016, 11:18:49 am »
just noticed, it actually has 14 pins.  Can the trigger for the running lights be used with one of the analog inputs? Or must it be one of the digital?
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #94 on: January 08, 2016, 11:22:28 am »
trigger inputs can be any of the Arduino io pins nominated as pinmode input.
I didn't see the schematic link...?
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #95 on: January 08, 2016, 11:30:37 am »
it's up, and yes, I know, I need to work on my schematic Layout skills.

So RXD and TXD are the other two digital input/outputs?

So That would leave one more needed, unless the trigger input can use an Analog input/output

Tired now, 3:30am here. I'll work on this some more tomorrow. I'll try and figure out the Running Light Input.  Should be much easier, since there is no sequential to them.

 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #96 on: January 08, 2016, 11:49:05 am »
ok, I saw the pdf ... just wasn't looking in the right place!
the input FETs may be better served by optocouplers with resistor+zener input protection, and series current limiting resistors on the input pins.
I need to look closer at the whole thing, but as mentioned, you CAN use an analog input for your extra digital input.

Physically breadboard it all up and check it does what you need.
The 100R gate resistors are probably a good idea anyway.

The solution is looking good !
« Last Edit: January 08, 2016, 11:50:39 am by SL4P »
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
Re: 555 Delay Timer.
« Reply #97 on: January 08, 2016, 11:51:07 am »
thought I'd try your code before bed MC.

It doesn't work. It compiles successfully into simulation, but when it runs, All LED's turn on steady, and pressing buttons do nothing.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #98 on: January 08, 2016, 11:59:07 am »
I suppose if I was really keen, I can build up the circuit to test the cide...!
just a note - my code was taken from page 2 of the comments... not the later code that was posted... I wasn't thinking.

if the tail(running) lights are not 'controlled', they can be wired normally - straight off the car loom... or you can also toggle them to be the inverse of the sequencing if needed.  I'm not sure of the legalities.
« Last Edit: January 08, 2016, 12:00:43 pm by SL4P »
Don't ask a question if you aren't willing to listen to the answer.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: 555 Delay Timer.
« Reply #99 on: January 08, 2016, 12:09:35 pm »
I think the error is in the if() code for the BRAKE_LIGHT
I'll think about it in my morning...

When I moved all the bits around, I think the brake lights are now always on!

The structure is ok, just the form of the if() terms need to be checked && not || or something like thatM
Don't ask a question if you aren't willing to listen to the answer.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf