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

0 Members and 1 Guest are viewing this topic.

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: 555 Delay Timer.
« Reply #100 on: January 08, 2016, 10:23:32 pm »
Nice job --- breaking tested, demonstrated working code and posting non-working, non-tested code as a replacement !!    :-DD
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 #101 on: January 08, 2016, 10:28:10 pm »
you tested it -thanks
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 #102 on: January 08, 2016, 11:31:04 pm »
The cost of the Optocouplers are fairly expensive.

Are the N-Channel MosFETs okay, the way they are in the schematic?  Will they turn fully off/on? It appears they do in the simulation.  I've just been reading and it seems the consensus is that you want to use a P-Channel for a high side switch, however, that would require more components (a NBJT or NMOS) to make it so that it inverses the signal coming from the uC to turn off the P-Channel when the lights are not switched on.

I'd rather keep the footprint as small as possible for this.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Opto's are cheap <$1 ea, and they provide complete electrical isolation of the input pins.
They can be driven on either pole - hence high-side or low-side signalling.
Most opto's are NPN, so they are normally wired to 'pull-down' the output when triggered - fairly standard method - uses the internal pull-ups in the micro..

I'm not sure that I can contribute much more, as another poster is concerned the code I posted is not up to his spec.   I agree that I would write it differently if starting from scratch, but I tried to keep it the way it was -- with minor internal tidying - seemed to be the best starting point for you to explore without wondering what / why I did things...

I'd rather have late code that was reliable, than rushed code that had race conditions etc.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
hmm, just noticed something in simulation.

If I hook power directly to the trigger going into Arduino for pin 8 (left side), then turn it to full on, it cycles once and then off. Power still applied.  Then, leaving power on the left applied, i click the right toggle switch to on. Both sides sequence, then stay lit.

Then, if i turn on and off the right side, the left side sequences, right side stays on steady. If I leave the right side in Off position, left lights then stay off, right side on steady. If I leave right side in On Position,  Both Sides stay on steady. This is true for operating switches on both sides. Same result is happening, just switched sides.

So, something weird is happening.

If I leave both switches in off position, I turn on the left, left side sequences and stays on steady. If I toggle it on and off, it sequences over and over again, as long as I keep toggle the switch.

There may be something wrong with the simulation, but, if there is not....when brakes are applied, this could screw everything up.

For example, if I have on Left turn signal, I then applied the brakes, the flashing will switch to steady on, and the right side will sequence.  That's bad.

If the simulation is right, then something is going on in coding. Or maybe another line needs to be added?

And MC, I appreciate your input, as well as the other posters. Everyone who has replied to this thread, I am thankful for.  Don't let others upset you. Post your opinions, I welcome all. I'm a newb.  Besides, arguments are good, helps me understand the differences. Just do it without flaming each other :)

« Last Edit: January 09, 2016, 02:26:07 am by Falcon69 »
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
well, I've messed with it for several hours. I even tried many different combinations of Logic Gates (NOR, AND, XOR, 3-input XOR, etc.) and I can't figure out what is happening in the simulation.

It appears to work in your video, but I can't get it to work in simulation.

I will try and search for a program that records screenshot and post it up of what the simulation is doing.

One thing I see, that may be causing it....When a switch (slide switch, not tactile) is switched on, the lights sequence once, then go off. Shouldn't they STAY on?  That would simulate the brakes being ON on that one side the switch has been toggled. 

But, when Both switches are on, the lights sequence once and stay ON.  I don't understand. I look at the code for BOTH switches on, and The code for if a Left (or right) is ON, the code looks the same.  I don't see anything that tells the Arduino to turn off the LED's at end of cycle (or leave them on).

Here's a Link to the online simulator and the file I was using, not sure if it will work for you, may have to sign up to use it.

https://123d.circuits.io/circuits/1439224-sequential-taillights/edit

« Last Edit: January 09, 2016, 10:04:04 am by Falcon69 »
 

Offline wguibas

  • Supporter
  • ****
  • Posts: 125
  • Country: us
I built this for my camaro
« Reply #107 on: January 09, 2016, 01:35:42 pm »
Hi I built this for my camaro,  It is based on arduino and TLC5940 chips.  It utilizes 17 vertical banks per side and can run up to 24 per side.  In your case you could combine outputs from the TLC's to drive the 240mA for each of the 6 LED's.  It takes inputs for Brake, Parking  Lights, and Turns Signals and outputs PWM for dimming and stuff.

Here is the original board I made along with the updated surface mount version:




and for all the engine fanboys, there is also a supercharger hidden under there.



I also used it in  an old Thunderbird with relays driven from the TLC's to drive the Bulbs.


« Last Edit: January 09, 2016, 02:16:07 pm by wguibas »
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
I'm going to order these.... Which one to get? They don't look the same.

The one with the holes on both edges (12 and 6) looks like it has 6 more outputs for something.

http://www.ebay.com/itm/Arduino-Pro-Mini-ATMEGA328P-16MHz-5V-ATMEGA328-/201389987587?hash=item2ee3c75703:g:BzEAAOSwjVVVqJxa
http://www.ebay.com/itm/16M-ATMEAG328-3-3V-8Mhz-Replace-ATmega128-Module-For-Arduino-Pro-Mini-Compatible-/272081659240?hash=item3f5954a568:g:oZMAAOSwPcVVrNFs
Don't try to save too much money here! The cheapest Chinese clones may be "buyer beware" kinds of items.
Look for ProMinis that have the holes labelled on top (the first one has labels on the bottom not the top), that come with header pins, either separate or pre-installed. I would suggest that you look for 5V versions rather than 3.3 volt versions for your application.

The extra holes on the first one are the 4 analog pins A4-A7 and headers for the serial communication. The second one has the 4 extra analog holes (not on the edges) but no serial comm pins. (When the ProMini is connected to its programming module it can do serial communication through it.)

To program the ProMinis you will also need the programming module (only one) :  something like this:
http://www.ebay.com/itm/3-Pack-Arduino-Pro-Mini-USB-Programmer-Newest-Design-USA-Seller-FAST-Ship-/231348215568?hash=item35dd6d9f10:g:6rEAAMXQ1d1TJ~JV
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
this is the one i ended up buying...

http://www.ebay.com/itm/281788992457

I haven't bought the other components yet. I'm still not sure on the mosFETs or Optocouplers to get. If I go with mosFETs, I'll need 6 of them to handle at least 243mA per. Since it is on a vehicle, do I need to look for an N-Channel logic level one with vds >12v and and vgs >12v?  I'm guessing ALWAYS keep rds very low.

For Optocoupler, I can't find anything on mouser's site that does more then the 243mA, They only have a couple, and those are >$1 each. If I go SSR, those are about $.075.  Thats more then double the cost of the mosfets. 

Also, the mosfets for the turn/brake input coming from the truck to the arduino....can that be the same as the other 6? (logic level)....I know it will have a ~12v input to the gate, but switching 5 volts.

Here's one of the mosfets I was looking at...
http://www.mouser.com/ds/2/149/FDN359BN-80801.pdf  It's cheap too, .165 when ordered in 100
« Last Edit: January 10, 2016, 08:04:13 pm by Falcon69 »
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
well, I've messed with it for several hours. I even tried many different combinations of Logic Gates (NOR, AND, XOR, 3-input XOR, etc.) and I can't figure out what is happening in the simulation.

It appears to work in your video, but I can't get it to work in simulation.

I will try and search for a program that records screenshot and post it up of what the simulation is doing.

One thing I see, that may be causing it....When a switch (slide switch, not tactile) is switched on, the lights sequence once, then go off. Shouldn't they STAY on?  That would simulate the brakes being ON on that one side the switch has been toggled. 
Yes, they should stay on, according to my understanding of your original requirements and the code I wrote. Is your switch working right? No loose contacts? Did you modify the code I wrote too much?
Quote

But, when Both switches are on, the lights sequence once and stay ON.  I don't understand. I look at the code for BOTH switches on, and The code for if a Left (or right) is ON, the code looks the same.  I don't see anything that tells the Arduino to turn off the LED's at end of cycle (or leave them on).
Did you change the logic that checks the Rstate and Lstate flags or something?
Quote
Here's a Link to the online simulator and the file I was using, not sure if it will work for you, may have to sign up to use it.

https://123d.circuits.io/circuits/1439224-sequential-taillights/edit

That simulator sort of works for me but seems to be glacially slow, slower than I'm willing to wait. All I can tell you is that the code I wrote does work on my breadboard.  I've added a two-stage brightness control using a simple CdS photoresistor (that I scavenged from a dollar "garden light" thing).

  (sequence rate control)
  (brightness level control)

I've taken out the first delay() statement at the top of the loop(), it was not needed. I also moved the LED pin assignments to the PWM-capable pins so that dimming would work. 

I checked the timing with my oscilloscope and the remaining delay(20) statements result in about a 40 millisecond delay between pressing the Brake switch and the first LED coming on. At 60 mph this translates into about 4 feet of travel.  The delay(20) statements need to be there because if read and write statements are too close together in time weird things can happen; this is a known quirk of the Arduino/Atmel system. I'd love to see if a Finite State Machine solution could overcome this problem...

Here's the code again, that I'm using in the video demonstrations above. It works.

Code: [Select]
/*--------------------------------------------------------------------------------------//
 3-Light Sequential Brake/Turn Signal Actuation
 (Both Left and Right sides)
 
 With Variable sequence rate and Brightness Control
 //--------------------------------------------------------------------------------------*/

int Bright = 0;  // variable to hold brightness level
int delayOn = 333;  // set sequence delay time in ms here
boolean Rstate=0, Lstate=0;

void setup() {
  pinMode (9, OUTPUT);   // Right: connect LEDs, relay drivers or mosfet Gates here
  pinMode (11, OUTPUT);
  pinMode (12, OUTPUT);

  pinMode (3, OUTPUT);    // Left: connect LEDs, relay drivers or mosfet Gates here
  pinMode (5, OUTPUT);
  pinMode (6, OUTPUT);

  //  connect Brake/Turn signal here (through divider or regulator to give ~4-5V when ON)
  pinMode (7, INPUT); // Right ts/b
  pinMode (8, INPUT); // Left ts/b   

  pinMode(A0, INPUT);  // potentiometer to control sequence delay
  pinMode(A1, INPUT);  // CdS photoresistor to control brightness level
}

void loop() {
  while (digitalRead(7)==LOW && digitalRead(8)==LOW) {
    // do nothing, wait for signal to go HIGH
  }

  //  Bright = map(analogRead(A1),0,1023,0,255);  // continuous brightness control
  if (analogRead(A1)<=512) Bright = 8;
  else Bright = 255;  // 2-level brightness

  if (!Rstate) {
    delay(20);
    // when Right signal goes High, actuate R outputs in sequence
    if (digitalRead(7)==HIGH && digitalRead(8)==LOW) {
      Rstate=1;
      delayOn = map(analogRead(A0),0,1023,0,500);
      analogWrite(9,Bright);
      delay(delayOn);
      analogWrite(11,Bright);
      delay (delayOn);
      analogWrite(10, Bright); 
    }
  }
  if (!Lstate) {
    delay(20);
    // when Left signal goes High, actuate L outputs in sequence
    if (digitalRead(7)==LOW && digitalRead(8)==HIGH) {
      Lstate=1;
      delayOn = map(analogRead(A0),0,1023,0,500);
      analogWrite(3, Bright);
      delay(delayOn);
      analogWrite(5,Bright);
      delay (delayOn);
      analogWrite(6, Bright); 
    }
  }
  if ((!Rstate) || (!Lstate)) {
    // when Brake (both) signal goes High, actuate R and L outputs in sequence
    if (digitalRead(7)==HIGH && digitalRead(8)==HIGH) {
      Rstate=1;
      Lstate=1;
      delayOn = map(analogRead(A0),0,1023,0,500);
      analogWrite(9, Bright);
      analogWrite(3, Bright);
      delay(delayOn);
      analogWrite(11, Bright);
      analogWrite(5, Bright);
      delay (delayOn);
      analogWrite(10, Bright);
      analogWrite(6, Bright); 
    }
  }
  delay(20);

  // when signal goes LOW turn off all outputs
  if (digitalRead(7)==LOW) {
    digitalWrite(9, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    Rstate=0;
  }
  if (digitalRead(8)==LOW) {
    digitalWrite(3, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    Lstate=0;
  }
}


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

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
this is the one i ended up buying...

http://www.ebay.com/itm/281788992457

I haven't bought the other components yet. I'm still not sure on the mosFETs or Optocouplers to get. If I go with mosFETs, I'll need 6 of them to handle at least 243mA per. Since it is on a vehicle, do I need to look for an N-Channel logic level one with vds >12v and and vgs >12v?  I'm guessing ALWAYS keep rds very low.

For Optocoupler, I can't find anything on mouser's site that does more then the 243mA, They only have a couple, and those are >$1 each. If I go SSR, those are about $.075.  Thats more then double the cost of the mosfets. 

Also, the mosfets for the turn/brake input coming from the truck to the arduino....can that be the same as the other 6? (logic level)....I know it will have a ~12v input to the gate, but switching 5 volts.

Here's one of the mosfets I was looking at...
http://www.mouser.com/ds/2/149/FDN359BN-80801.pdf  It's cheap too, .165 when ordered in 100

That particular ProMini is not the one I would have recommended, personally, since it has the pin labels on the bottom (maybe, if you are lucky) rather than the top, and it takes at least ten days to get to the USA from Hong-Kong. You will still need to get the programmer module too.

The optocouplers only have to handle the Gate signals to the switching mosfets, right? Not the full current to the LEDs.

You do realize that an SOT-23 mosfet package is about the size of half a grain of rice, right? Are you able to handle printed circuit board design and construction with surface-mount components?
 
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
circuit boards are not a problem. I can place 0402 if I have to. I made a manual pick & place machine with vaccuum pick up tool  that indexes at 45 degree increments, and also with a double mounted Microscope.  And I made a toaster reflow oven.  My 3D printer came in handy for making it.

Ya, But I had already bought the ProMini before you said anything :/

Ones from the US are like 5x the cost for the same item.  I can wait :P

No, the LED's will have the full current going through the Source and Drain to switch on the LED's which at full brightness draw 243mA each.  The gate will be activated via Arduino ~5v.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
i noticed in that new code, all the digital write were changed to analogwrite?

EDIT:  Oh, now I see why you did that. Because it now sees what the photo resistor is, before sending signal to the LED
« Last Edit: January 10, 2016, 08:41:51 pm by Falcon69 »
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
circuit boards are not a problem. I can place 0402 if I have to. I made a manual pick & place machine with vaccuum pick up tool  that indexes at 45 degree increments, and also with a double mounted Microscope.  And I made a toaster reflow oven.  My 3D printer came in handy for making it.

Excellent!

Quote


Ya, But I had already bought the ProMini before you said anything :/

Ones from the US are like 5x the cost for the same item.  I can wait :P


Often... you get what you pay for. I hope the units you bought from Hong-Kong work properly, don't get lost in the mail, etc.
A genuine SparkFun ProMini is about 10 dollars. Three clones, plus the programmer, for 18 dollars post-paid from a USA seller is still a pretty good deal IMHO.

Quote

No, the LED's will have the full current going through the Source and Drain to switch on the LED's which at full brightness draw 243mA each.  The gate will be activated via Arduino ~5v.


Yes, I understand that part. So what do you intend to use the optocoupler for? The "logical" way to use it would be to isolate the mosfet Gate from the Arduino, I thought. In that case you don't need some high-current rated device, at the slow frequencies we are talking about here.
« Last Edit: January 10, 2016, 09:21:18 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
oh, i was thinking of using it on the gate of the mosFET.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
oh, i was thinking of using it on the gate of the mosFET.

Right. So it doesn't need to carry the ~250 mA that the LED will draw, just the current necessary to turn the mosfet ON. Maybe something like VOM618A-4 would work.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
so you are saying to do this.....

Arduino > NPN Optocoupler/Photo Transistor > P-Channel Logic Level mosFET > LED's

Instead of....

Arduino > N-Channel Logic Level Mosfet > LED's


What About the Turn/brake Wire> Arduino Trigger Pins 7 and 8? 

Do...
 12V (Brake/Turn Wire)> 78L09 > Pins 7 & 8

Or...
  12V (Brake/Turn Wire)> N-Channel Logic Level mosFET (same as other ones, too keep BOM Lower) > Pins 7&8

Or...
 12V (Brake/Turn Wire)> NPN Optocoupler/PhotoTransistor > P-Channel Logic Level mosFET (same as other ones to keep BOM Lower) > Pins 7&8




 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
so you are saying to do this.....

Arduino > NPN Optocoupler/Photo Transistor > P-Channel Logic Level mosFET > LED's

Instead of....

Arduino > N-Channel Logic Level Mosfet > LED's
No, I'd still use N-ch mosfets. Arduino>opto>Nch Mosfet, and logic level isn't needed because you can use the 12-14 V vehicle supply to drive the mosfet Gate through the optocoupler. If you need to invert the signal you can do that very easily in the software.
Quote


What About the Turn/brake Wire> Arduino Trigger Pins 7 and 8? 

Do...
 12V (Brake/Turn Wire)> 78L09 > Pins 7 & 8


78L05, not 09. This is the first thing I'd try, myself, since I have a bunch of 78L05s in my parts stash.
 
Quote

Or...
  12V (Brake/Turn Wire)> N-Channel Logic Level mosFET (same as other ones, too keep BOM Lower) > Pins 7&8

Or...
 12V (Brake/Turn Wire)> NPN Optocoupler/PhotoTransistor > P-Channel Logic Level mosFET (same as other ones to keep BOM Lower) > Pins 7&8

You should be able to do this part without a mosfet, just the optocoupler. Again, if inverting is needed it's easily done in the software. This is probably a better solution than using the 78L05 regulator; you'll be using the Arduino's 5 V regulated output through the opto to provide the "HIGH" signal to the input pins.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline wguibas

  • Supporter
  • ****
  • Posts: 125
  • Country: us
To do the inputs all you need is a voltage divider.  Put the 12V/14V wire from the car through a 22K resistor.  Take a 10K resistor attach it to ground.  Join the 2 resistors together opposite their connections and connect the node of these 2 resistors to the arduino input.  It will see about 4.2V when the car is sending a signal. 

« Last Edit: January 10, 2016, 10:48:08 pm by wguibas »
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
I keep forgetting to ask... do your LED modules need a current-limiting resistor or are they designed to connect directly to the vehicle's 12-14 VDC without an external resistor? I'm asking because if a resistor is needed, it will probably need to be something like 50-56 ohms, 5 watts.....
(14 volt supply, ~250 mA.....)  :(



To do the inputs all you need is a voltage divider.  Put the 12V/14V wire from the car through a 22K resistor.  Take a 10K resistor attach it to ground.  Join the 2 resistors together opposite their connections and connect the node of these 2 resistors to the arduino input.  It will see about 4.2V when the car is sending a signal. 

Yes, that's good too. Probably still better to use an optoisolator just to be safe.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
NO, I don't need to invert the signal...I just suggested the P-Channel because the Power needs to go INTO the LED's.I just heard it was better to use P-Channel for high side switch.  But that would mean I'd have to invert the signal, hence why an NPN photo transistor.

As I have the schematic now..it goes like....
Vehicle 12v > Drain N-Channel mosFET through Source of mosFET > LED's > Ground

Since the LED's share a Common ground for the Turn/Brake and for the Tail Light (running Light).....I have to run it as a High Side. Switching the common ground is not acceptable, as it would make the running lights flash when turn signals are on...Don't want that happening. Running lights need to STAY on (separate LED's not connected to the turn/brake LEDs within the LED modules themselves)

If the N-Channel still works for that configuration, I'd rather use it. I never liked using P-Channels as switches. But, I'm a newb, what do I know.

The LED's are connected directly to the vehicles factory Turn/Brake, Ground, and Taill Light wires that are already in the back of the truck.  Basically, we cut the wires going to the existing factory taillights, and wired the LED's in.

Voltage Divider would work, however, What if there is a spike voltage? Wouldn't that damage the arduino? a mosfet or optocoupler would provide protection, wouldn't it from that?



 

Offline wguibas

  • Supporter
  • ****
  • Posts: 125
  • Country: us
The divider would handle greater than 16V and still not blow the arduino.  Other electronics in the car  would blow up before the atmel.
I've had this in my car for years now and it works fine.   Unless a 10K ground resistor goes bad the atmel is safe.
 

Offline Falcon69Topic starter

  • Super Contributor
  • ***
  • Posts: 1482
  • Country: us
okay, that would svae some money too.  Are you using 1/2w fort those?
 

Offline wguibas

  • Supporter
  • ****
  • Posts: 125
  • Country: us
1/8w is fine, it draws no real current, its just signal.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf