Go Down

Topic: LED Upgrade Project for Motorcycle (Read 182 times) previous topic - next topic

Ratbag

This question(s) must have been answered before however I can't find definitive answers anywhere.

I am trying to do a project to add LED indicators, daylight running lights with riding modes (day time, night time, braking etc) to my motorbike. Using an Arduino Nano to drive RGB LEDS which will be Red (tail lights) unless the indicator is functioning when using PWM i'll add some Green light to make Amber. The LEDs will then flash on an off in sync with the main LEDS as I hope to use the current/voltage driving the indicators as a 'sync'. When the turn is over and the indicator cancels, then the RGB LED will return to being just a Red tail light. I am also driving some from Daylight Running Lights up front that I want to wigwag when the horn sounds or dim a bit at night time - this means I am using all the digital pins for PWM or simple on/off 5V+

Simple eh?

I am quite enjoying the aspect of programming and also the electronics to make this work. This is the progress so far:

1. I am using a Buck transformer to bring the bikes 12V-15V power down to 5V - this works. I am toying with the idea of fusing with resettable fuses for additional protection. The powerful DLR LEDS are 12v and will be powered off the bikes 12V power. All looks good for this bit :)

2. Powering the RGB LEDs will take a MOSFET device as some of the LEDs strips and others will draw more than the total amount the Arduino can supply on its digital output pins (I have ordered a few 4 port MOSFET boards and also some components to try making my own) so am confident that part of the project will work - assuming PWM will run through the MOSFET… Again each Digital pin will have a resettable fuse that will trip above 40mA (I hope), but don't think driving a MOSET will take anything like that… All Good - i hope...

3. Now I need to take a 'signal' from the indicator (and another from the horn) circuits to see if the indicator (horn) is on or off. As all my D pins are being used for driving LEDS I plan to use the analogue pins to sense if there is a 5V+ input or 0V. This means I need to be very careful as I can't have 12V run straight into the analogue pin. I have tried using a simple (standard two resistor circuit) voltage divider with 60ohm in R1 and 20ohms in R2 which does take the power from say 14.5V to 3.6V but the resistors get hot (they are only 1/4W rated). I tried putting two 120ohm in parallel for R1 and two 40ohm in parallel for R2 thinking that would share the load - but it still gets hot, and this is just measuring it with a multimeter - is this right?!? It seems to be a very basic circuit and no-one else seems to complain about resistors 'melting'…

I have on order some LD1117S33CTR 15V to 3.3V voltage regulator chips which should solve the problem but i am still baffled why my other circuit isn't working. Maybe too great a voltage drop maybe I should do the drop in stages and daisy chain voltage dividers together? Do you suppose that taking a feed off the indicators / horn will effect their function? I thought it would be ok as I am not driving anything off the circuit - just taking a measurement - should I have a whopping great resistor in there to ensure its ok, or will the voltage regulator do that too?

I'd appreciate your thoughts on why the voltage divider is getting hot, and also if I ought to put a zener diode in there to cap the voltage at 5V+?


The second part of the problem is that I need to check if there is power to an A? pin and then perform an action. I have been able to do a simple 'read' on digital ports but not sure if that is the same on analogue? Can someone please show me a bit of code that can see if 5V+ is present on an analogue INPUT pin? And if I need pull-up set?

I hope all this makes sense!

Thanks in advance.


MrMark

#1
Jul 12, 2018, 08:27 pm Last Edit: Jul 12, 2018, 08:38 pm by MrMark
With a 60 and 20 Ohm resistor the nominal current through your voltage divider is about 14.5 V1 / (60 + 20 Ohms) = 180 mA.  Since power is voltage times current the divider is dissipating about 14.5 V * 180 mA = 2.6 Watts, considerably higher than the 1/4 Watt rating.  Something like 6000 and 2000 Ohms might be more appropriate.

To read an analog voltage, use the Arduino analogRead() function and test whether the value is over some appropriate threshold using an if .. else statement.

The nominal output of the voltage divider is 14.5 V * (20 / (20+60)) or 3.6 Volts.  Full scale (5 Volts) on an Arduino Uno 10 bit A/D is 1023.  To set the threshold between the high (3.6 Volts) and low (0 Volt) state (1.8 V), use 1.8 V / 5 V * 1023 = 368 in the comparison.


1 - 14.5 V is a  typical operating voltage for a "12 Volt" motorcycle electrical system.

Ratbag

Thank you MrMark,

I had thought that low resistance used in the voltage/potential divider would be better but will experiment with your suggested values and beyond! Don't forget though that I had tried the same 'ohms' but with multiple 1/4W resistors in parallel - was that a stupid idea or was there a degree of positive logic behind it that only failed because I used too low resistance values?

I will explore the analogRead function in a bread board setting to see how it works. Thank you. Do you have an opinion about pull-up or is that a red herring?

Thank you also for showing me the calculation to work out what 'trip' voltage to detect. Good shout!

13.8V is that I was a lad taught as being the 'powered with alternator' voltage on a vehicle's power 'bus' - In my planning I allowed for some variance ether way - although it's a new bike so shouldn't be to random.

Cheers

MrMark

#3
Jul 12, 2018, 09:42 pm Last Edit: Jul 12, 2018, 09:44 pm by MrMark
I had thought that low resistance used in the voltage/potential divider would be better but will experiment with your suggested values and beyond! Don't forget though that I had tried the same 'ohms' but with multiple 1/4W resistors in parallel - was that a stupid idea or was there a degree of positive logic behind it that only failed because I used too low resistance values?
One can parallel resistors to get higher effective Wattage, but the 60 Ohm resistor in your original post was dissipating close to 2 W so one would need at least 8 by 1/4 W resistors in parallel.  It's good practice to use parts rated with at least twice the expected max, so even that would be marginal.

Guidance from the AtMega data sheets says that the input resistance to an analog input pin should be no more than 10000 Ohms or response time suffers.  Thus the design rational is to specify resistor values approaching but below this limit since there's no real advantage to lower values and they dissipate more power as you've observed. 

An additional consideration is that higher resistance values serve to limit the (potentially damaging) energy at the pin from voltage spikes on the signal.  Motorcycle and automotive power typically has surprisingly large voltage spikes over the nominal voltage.

Quote
I will explore the analogRead function in a bread board setting to see how it works. Thank you. Do you have an opinion about pull-up or is that a red herring?
You don't need the pull-up since the external voltage divider resistors will actively pull to ground if no input is present.

Quote
13.8V is that I was a lad taught as being the 'powered with alternator' voltage on a vehicle's power 'bus' - In my planning I allowed for some variance ether way - although it's a new bike so shouldn't be to random.
14.5 V is somewhat intentionally on the high side to be sure not to over voltage the Arduino pin.  13.8 V sounds low to me, but isn't completely implausible.  Using the analog input in the manner described the system won't be particularly sensitive to the exact voltage of the system, which is good because it does change.

Paul__B

This question(s) must have been answered before however I can't find definitive answers anywhere.
Only some hundreds of times.  :smiley-roll:

I am trying to do a project to add LED indicators, daylight running lights with riding modes (day time, night time, braking etc) to my motorbike. Using an Arduino Nano
Correct choice of board.  People often propose to use a UNO for a project but the UNO is really only for experimentation and demonstration, not for "real world" projects.

to drive RGB LEDS which will be Red (tail lights) unless the indicator is functioning when using PWM I'll add some Green light to make Amber.
Why PWM?  Selecting the right current limiting resistor will get the balance right, unless you want other colour variations.  Do you need white?  If not, red/ green LEDs would suit.

1. I am using a Buck transformer to bring the bikes 12V-15V power down to 5V - this works. I am toying with the idea of fusing with resettable fuses for additional protection.
The fuses protect your wiring, not the electronics.  So should be close to the battery.

2. Powering the RGB LEDs will take a MOSFET device as some of the LEDs strips and others will draw more than the total amount the Arduino can supply on its digital output pins (I have ordered a few 4 port MOSFET boards and also some components to try making my own)
I think that all of the LED strips will require switching MOSFETs.  You can allow to run one indicator LED at 20 mA from an Arduino pin.

so am confident that part of the project will work - assuming PWM will run through the MOSFET
220 Ohm resistor in series between Arduino pin and FET gate, 10k resistor from Arduino pin to ground to keep FET off while booting.

Again each Digital pin will have a resettable fuse that will trip above 40mA (I hope)
Rubbish!

Each pin will have a 220 Ohm resistor in series to whatever it drives.  What has 40 mA got to do with anything?

3. Now I need to take a 'signal' from the indicator (and another from the horn) circuits to see if the indicator (horn) is on or off. As all my D pins are being used for driving LEDs I plan to use the analog pins to sense if there is a 5V+ input or 0V.
"Analog" pins A0 to A6 are digital pins.

This means I need to be very careful as I can't have 12V run straight into the analogue pin. I have tried using a simple (standard two resistor circuit) voltage divider with 60ohm in R1 and 20ohms in R2 which does take the power from say 14.5V to 3.6V but the resistors get hot (they are only 1/4W rated). I tried putting two 120ohm in parallel for R1 and two 40ohm in parallel for R2 thinking that would share the load - but it still gets hot, and this is just measuring it with a multimeter - is this right?!? It seems to be a very basic circuit and no-one else seems to complain about resistors 'melting'…
Wrong values.  Use 22k and 12 k for a 3:1 reduction.  10 V in will be reduced to about 3.5 V which is a valid logic HIGH.

I have on order some LD1117S33CTR 15V to 3.3V voltage regulator chips which should solve the problem
What problem?

but I am still baffled why my other circuit isn't working. Maybe too great a voltage drop maybe I should do the drop in stages and daisy chain voltage dividers together? Do you suppose that taking a feed off the indicators / horn will effect their function?
How?

I'd appreciate your thoughts on why the voltage divider is getting hot, and also if I ought to put a Zener diode in there to cap the voltage at 5V+?
It certainly will not get hot using the correct resistor values.  You could put in a 3.6 V Zener just in case.

The second part of the problem is that I need to check if there is power to an A? pin and then perform an action. I have been able to do a simple 'read' on digital ports but not sure if that is the same on analogue? Can someone please show me a bit of code that can see if 5V+ is present on an analogue INPUT pin? And if I need pull-up set?
You use digitalRead, not analog.

Ratbag

HI Paul_B,

Thank you for your comments and observations. They certainly helped and also made me think about some of my 'cunning' plans :)

I'll post comments in line with yours below:


Why PWM?  Selecting the right current limiting resistor will get the balance right, unless you want other colour variations.  Do you need white?  If not, red/ green LEDs would suit.
You are quite right - in order to get this to work I have had to be conservative on which colours on the RGB LED to PWM and which to do a simple on off. On the rear RGB LEDS it needs RED and Amber as the two functional colours - RED is easy as its 100% on and Green and Blue off. Amber is achieved by having RED full on and Green 45% appx. I have tried using resistors but it isn't as good as using PWM. On the front RGB LEDS it has white light (all on 100%) and Amber, so again the Green will be on PWM. I would like to make the White light a bit blueish but don't have enough pins, and it would also mean reducing Red and Green intensity to make the blue show up - according to the colour tables at least!

The fuses protect your wiring, not the electronics.  So should be close to the battery.
The whole fusing thing is an idea I pinched from the Ruggeduino https://www.rugged-circuits.com. Automotive applications can be challenging because of the variable power and spikes etc. It might not be necessary but it's giving me some good soldering practice :)


I think that all of the LED strips will require switching MOSFETs.  You can allow to run one indicator LED at 20 mA from an Arduino pin. 220 Ohm resistor in series between Arduino pin and FET gate, 10k resistor from Arduino pin to ground to keep FET off while booting.
Usage of MOSFETs all round - Agreed - I simplified my project statement otherwise it would read like War & Peace... Thank you for the resistor ideas - I shall try it.


Rubbish!

Each pin will have a 220 Ohm resistor in series to whatever it drives.  What has 40 mA got to do with anything?
50mA is what the spec sheet says is the max current supplied by a pin. The ruggedised Arduino people use a 40mA resettable fuse. Sounds like it's not necessary but since I have them...


"Analog" pins A0 to A6 are digital pins.
Great! :)

What problem?

and How? (will it effect the bikes electrics).
It's an expensive bike full of technology. For some elements of the project I am not messing about with simple home brew circuits (voltage dividers) but getting fully supported, properly designed and manufactured bits for that purpose i.e. automotive spec components. Playing with different types of voltage dividers / regulators and the like is so that I develop an understanding of the fundamental principles (or try too...).

The bike has CANBUS technology and my experience on messing about with CANBUS is that you need to test your components. As a very simple example installing an LED sight light without a restive load will trigger CANBUS to think the bulb is blown - likewise carelessness can lead to interference with the vehicles safe operation e.g ABS, traction control, cruise control, throttle by wire, EMU etc, etc. I'm not saying my project will interfere with all this but I am definitely going to check and test!

Thank you again for your advice.

Paul__B

You are quite right - in order to get this to work I have had to be conservative on which colours on the RGB LED to PWM and which to do a simple on off. On the rear RGB LEDS it needs RED and Amber as the two functional colours - RED is easy as its 100% on and Green and Blue off. Amber is achieved by having RED full on and Green 45% appx. I have tried using resistors but it isn't as good as using PWM.
What you mean to say is that it is easier to change PWM values in software than to change resistors.  Which is true.  But resistors will do just as well.

Now what does happen, is that RGB colour mixing will vary with fluctuations in line voltage as the different coloured LEDs have different threshold voltages, but that affects PWM just as well.

On the front RGB LEDS it has white light (all on 100%) and Amber, so again the Green will be on PWM. I would like to make the White light a bit blueish but don't have enough pins, and it would also mean reducing Red and Green intensity to make the blue show up - according to the colour tables at least!
It has nothing to do with pins.  If the blue is not bright enough (and you are already on the maximum safe current ), then the only way to get more blue is to reduce red and green.

The whole fusing thing is an idea I pinched from the Ruggeduino https://www.rugged-circuits.com. Automotive applications can be challenging because of the variable power and spikes etc. It might not be necessary but it's giving me some good soldering practice :)
It is not relevant to your design.  The Ruggeduino is designed to have its pins shorted out but also to have no resistance in series with the pins (though you need to realise that the effective output internal resistance of the ATmega is 45 Ohms).  What you do is simply to put a 220 Ohm resistor in series with every output pin where it drives a FET or LED.  This limits short circuit current to 22 mA and LED current to 10 mA or so so you need no further protection.

22k in series with each input pin is again, virtually complete protection but you may choose to add a 4.7 V Zener from pin to ground.

Usage of MOSFETs all round - Agreed - I simplified my project statement otherwise it would read like War & Peace... Thank you for the resistor ideas - I shall try it.
Oh, it is critical to include every detail if you want to get sensible answers.  As you are finding out.  :smiley-lol:

50mA is what the spec sheet says is the max current supplied by a pin. The ruggedised Arduino people use a 40mA resettable fuse. Sounds like it's not necessary but since I have them...
Total nonsense on all counts!   :smiley-eek: The absolute maximum current that you might ever allow a pin to pass by whatever you connect to it, is 40 - forty - mA.  Go read the spec sheet - I have no idea what "spec sheet" you have been reading!  This implies a maximum safe working for one pin at a time of about 30 mA.  If you take the hint from the charts on that sheet, you see that it is intended to supply up to 20 mA for a limited number of pins at once.

But a 220 Ohm resistor in series provides complete protection (unless you intend to put the battery voltage on a pin somehow), so the Polyfuses are as I keep emphasising, nonsense.  Of course, there is a structural imperative, that these 220 Ohm resistors are assembled adjacent to the Arduino mount.

Great! :)
Yes, "newbies" tend not to read the complete description and understand that the Analog input function is in addition to the digital functions just as PWM is additional to some (other) digital pins and I2C is yet another addition to A4 and A5.  A6 and A7 are not present on the UNO (due to the DIP chip format) and are in fact, analog input only.

It's an expensive bike full of technology. For some elements of the project I am not messing about with simple home brew circuits (voltage dividers) but getting fully supported, properly designed and manufactured bits for that purpose i.e. automotive spec components. Playing with different types of voltage dividers / regulators and the like is so that I develop an understanding of the fundamental principles (or try too...).
That's OK, but the simple fact is that all inputs from the 12 V circuitry will have a 22k resistor in series which affects the operation of the automotive systems no more than (and is pretty much equivalent to) moisture in the wiring!

We have to chuckle when "newbies" start talking about using voltage regulators as voltage dividers.  OK, I'll let you in on the secret: whether or not they might work as such, a voltage regulator requires input and output capacitors which would substantially delay the signal input into the Arduino, possibly by one or more seconds.

The bike has CANbus technology and my experience on messing about with CANbus is that you need to test your components. As a very simple example installing an LED sight light without a restive load will trigger CANbus to think the bulb is blown
That is not entirely "CANbus technology" - which describes the signalling system - but the fact that CANbus facilitates message return from the interface chips so that they can report a current draw anomaly.  It leads to the absurd situation that you install LED lighting ("side light?") in place of incandescent to save on power, but then have to cause it to waste just as much power as the incandescent to keep the CANbus happy.  :smiley-eek:

likewise carelessness can lead to interference with the vehicles safe operation e.g ABS, traction control, cruise control, throttle by wire, EMU etc, etc. I'm not saying my project will interfere with all this but I am definitely going to check and test!
I am pretty sure that a 22k resistor additional load will not affect the operation of the technology (but don't put it on a spark plug lead  :smiley-roll: ).

Go Up