Go Down

Topic: LEDs controlled by speed-- Programming help!! (Read 1 time) previous topic - next topic


Apr 04, 2013, 02:32 am Last Edit: Apr 04, 2013, 03:15 am by jryan818 Reason: 1

I am working on a project that will allow LEDs to represent brake lights. I would like the LEDs to light up dependent on how quickly the car is slowing down. The LEDs would light up in a vertical ascending pattern. Light deceleration would illuminate the first strand of LEDs, medium deceleration would illuminate the first and second strand of LEDs, and hard braking would illuminate all three strands of braking. If it is possible I would also like to have the third strand of LEDs flash after all three strands have been lite if the brakes were to be slammed.

I intend to calculate speed using a hall effect sensor or optical sensor and have them measure the circumference of the wheel of the car (in this sense a power wheels kids toy). I had wanted to use an accelerometer, but was having trouble finding an affordable one that would measure such small increases and decreases in speed since the power wheels only goes 5 miles an hour.

I am having a lot of trouble with the programming, could anyone help me out?? This is my first time trying to do any programming and I am under time constraints so cannot spend too much time learning all of Arduinos functions.

Thank you!!!



Nearly all the pieces you need can be found in the playground of this site, but you will have to put the pieces together. The link I gave you will allow you to get an RPM reading from a hall-effect sensor. That is one piece. Turning on the LED lines is no more difficult than wiring each line up to a digital pin and using digitalWrite to control that pin. Though with the amount of current a line will take, you will probably need to use a transistor.

Look at blinking code in the playground to learn how to blink LEDs for the flashing.

You could also look at using PWM to change the brightness of the strands for more effect.

"I am under time constraints so cannot spend too much time learning all of Arduinos functions."

That kind of reads like, "Hey, someone write the code for me..." Which is probably why you are not getting any responses. I am always willing to help those willing to learn, but personally... if you want me to write code for you, I expect to be paid. I'm sure most would agree.


I apologize that it came off that way! I do want to learn and understand this programming, I simply need to learn as much as I can through this programming rather than learning properly through all of the tutorials since I have less time that could be desired for a newbie!

That link you provided is very helpful, thank you!

When you said PWM is that comparable to 'fading'? I was under the impression to use an AnalogWrite for that function rather than a DigitalWrite. Would you advise one being better than the other?

Again, I really appreciate you responding and any advice you could give! Thank you!


Apr 05, 2013, 03:11 am Last Edit: Apr 05, 2013, 03:27 am by DVDdoug Reason: 1
When you said PWM is that comparable to 'fading'?
Correct! See the Fade Example.

I was under the impression to use an AnalogWrite for that function rather than a DigitalWrite.
Correct again!

I am having a lot of trouble with the programming
As always, I recommend that you break your project into separately-testable parts...

I'd start with the LED stuff, since that's the easy part.    Just hard-code the "fake" RPM data into you sketch to test the LED hardware & software.

Then when you build & test the RPM sensor, use the Serial Monitor to send the input-state, and perhaps some variable-values and/or the RPM to your computer over the USB connection.

When you're confident that the RPM sensor hardware & software are working, you can add the code to detect/calculate acceleration & deceleration, and merge it all together.


Success! To do a fade with many LEDs do you suggest parallel over series? If I want them to fade at different levels should I program it to different pins and then have them dependent off of if statements?


I guess a better question would be how to increase the power to an Arduino Uno? My understanding is an 6volt (or whatever power source) to the LEDs to a resistor and then a transistor. That would then be connected to the pin on the Arduino board and then to ground? Would this solve my abilities to power more than one LED or should I be able to do it without the external power source?

Go Up