New Idiot- 1st Arduino- LED Dimming

I am an artist and this is my first time using an Arduino. I would like to use an Uno R3 with a Maxbotix LV-EZ0 ultrasonic sensor and a wall adapter Power Supply - 9VDC 650mA to dim some(5) LEDs when someone approaches the sensor. Then when they back away from the sensor the light needs to return to “on”. I can use any help. I need to know everything involved in making this happen. Thanks to everyone.

I’d approach this in stages. Try just blinking an LED (blink on the arduino examples page). Then lean how control the brightness (fade) Then learn how to use the maxbotix ranger (there’s probably an exmaple out there some where). Then try putting them together.

Thanks. I’ve read the blink tutorial and am reading about the arduino, sketches and all. I feel confident I will be able to figure out how to set up the Maxbotix as an on/off trigger but I still have some questions and am on a short time deadline. I have been searching for ideas on the dimming but as a beginner I am getting lost. I think maybe a 555 timer to blink the LEDs(the 3 light bar - COM-00680) as the dimming part might work. Does anyone have any experience with this or know where I can find breakdowns of similar projects? And, will this LED light bar need a heat sink? Anymore help would be a lifesaver as this is part of a thesis project due in May(just decided to add the lighting part and didn’t realize it would require so much knowledge). Thanks again

dude, look at the fade example. This uses something called PWM (though the arduinitos call it “analog write” for some reason). By varying the PWM (er analog write) value over time you can get it to smoothly change brightness. Like start the LED at 0, then in the loop delay for 50 milliseconds, add 1 to the LED value. In around 12 seconds the LED will go from off to fully on. Fairly smoothly. Faster? delay less or add more than one. Play with it.

Light bar needs heat sink? Probably not though I’m just guessing. You will probably need to do use a driver circuit since the arduino can only realistically drive one LED per pin. Lots of options for that but it not clear to me precisely what you want to do. Do you have specs on your light bar?

So it’s the 3 LEDs in the bar above and not 5 LEDs in some other arrangement ? Dimming of LEDs is generally done via PWM. If you want to control the bar you’ve selected you’ll need a way to switch it on and off rapidly, something like a FET between the bar’s return and the power ground. The Arduino PWM output would then be used to control the FET. This is similar to the Arduino fade example mentioned above.

http://arduino.cc/en/Tutorial/Fading

there might be ways to avoid a driver (aka the mosfet mee-n-mac mentioned). Like use a separate pin per LED. But if the LEDs are high power then it’s a whole different ball game. Please post specs or point to where they are. More info = better advice.

If I’m understanding you correctly, you need to dim 5 LEDs when somebody approaches the Ultrasonic sensor.

What you’ll want to do is try and find an example on how to use it with an Arduino (if you can’t, try figuring out how to get data from it by looking around in its data sheet).

Then, figure out how the data corresponds with the distance. For example, if it works via a ping signal, how long of a delay corresponds to what distance?

Once you have these two things figured out, you need to decide if you want all of the LEDs to fade the same way or individually, and then create a fade program accordingly that instead of using a delayed time to fade, just fades with the distance sensed. You do not have to use a 555 timer, or anything else. All you need to do is have a loop that reads the sensor, stores it in a variable, and then fades the LEDs using that variable.

If you look at the fade example in the Arduino IDE, you’ll see that analogWrite() has a value from 0 to 255 in the parentheses. That’s where you want to put your sensor variable. (If the sensor variable is out of bounds, e.g. 1000, divide it by something, like 4, to get in range, 250.)

And there you go.

Good luck,

Selenaut:
If you look at the fade example in the Arduino IDE, you’ll see that analogWrite() has a value from 0 to 255 in the parentheses. That’s where you want to put your sensor variable. (If the sensor variable is out of bounds, e.g. 1000, divide it by something, like 4, to get in range, 250.)

Just a thought or two …

The OP may find that he needs to filter the noise from the sensor before setting the LED brightness. Not hard to do and definitely something to worry about only after all else is working, but I thought I’d mention it just in case the OP finds the brightness dancing around and gets disheartened.

Also I wonder if there shouldn’t be a non-linear relationship between the distance measured and the brightness level. I believe the human visual system is logarithmic and so halving the average optical power out of the LEDs would not be perceived as being half as bright. Then again maybe he’s planning to use this for some camera lighting rig and … :?:

With a little more thought I bet we can complicate this beyond all reason … CoBAR. :twisted:

Good point about cobar - we do that really well around here.

Yeah, perceived brightness does follow a logarithmic curve. In addition, since the viewer is getting closer, they also will perceive brightness increase due to inverse squared rule (# of photons striking the retina is proportional to 1/R^2 where R is the distance). I’d probably start with straight linear and see how it goes. At least for the first version.

As for filtering, a simple iir filter will probably yield reasonable results. Something like

current_distance = new_distance f + current_distance(1-f)

where f is between 0 and 1. Smaller values of f will kill noise better but with slower response. I’d start with 0.5.

However, if the sample rate from the sonar (and thus the LED update rate) is fast enough, noise may not be a problem at all.