HELP on PWM programmed

hi guys.. i want to ask for y'al help. recently im doing a project about energy light saving. what im doing is just a prototype. im using Arduino UNO (Atmega328p). So here is the idea. i have an LDR in my analog input. and output is actually a bunch of LED's connected to the PWM digital input of the atmega328p. What im goin' to do is, i wanted to reduced the uses of LED's (only several of LED' are ON) in my output that is controlled by the arduino. Arduino will get a signal from the LDR of how much intake of light it gets. If the LDR received high amount of light, the LED's at the output will only ON half of it. If the LDR detects no light, (night, cloudy day) all of the LED's will ON. I've posted the photo of my connection. i hope u guys an help me. thanks..

i want to ask for y'al help

too vague .
be specific

How are you going to power the LEDs?
Where is the schematic from?

Where is the schematic from?

HERE
http://forum.arduino.cc/index.php?topic=233588.msg1682021#msg1682021

One thing you don't want to do is pull over 200 mA through the Arduino, and try to pull 20 mA or less through any 1 pin.

With PWM you can make every led attached through the PWM pin to be ON over a duty-cycle. PWM goes on/off about 490 times a second. So ALL your leds can be ON like 0% of the time up to 100% in 256 steps. You can make them all dimmer than a 15 year old in 6th grade if you want so why bother shutting just some of them off?

Really, use PWM to control a transistor that runs maybe 12V through the collector-emitter and a resistor for each led and have the LDR reading determine what duty cycle to run the PWM.

This Playground project uses a led as both light and sensor, but adjusts brightness for the eyes... it dims in the dark and brightens in light. The circuit is used in TV remotes and cellphones to save power and be eye comfortable. You would want almost the opposite but check out how it's done!
http://playground.arduino.cc/Learning/LEDSensor

LarryD:
How are you going to power the LEDs?
Where is the schematic from?

actually the LEDs will be connected to 12v of power supply. This schematic is design by my self and some hep from friends.

PWM at 1 out of 255 is just under 0.4% brightness. That's the same a 1 led out of 255 being ON 100% of the time and the rest OFF, except they would ALL be on 0.39% of the time without having to figure out which some of them should be On or OFF, just all the same.

so.. let say for 1 pin of PWM, can it control 5 LEDs or only 1 ?

gerard_92:
so.. let say for 1 pin of PWM, can it control 5 LEDs or only 1 ?

It can control as many leds as your transistor can power, provided you give them the power.
Literally, hundreds of regular leds.
You might want to get the EE members here to discuss power FETS.

thanks for the info.. is it possible for me to control the LEDs by using LDR ? Because this project is about green technology, which im going to design a energy saving light which is used inside office or houses. When the LDR detects high intensity of light, only several leds will on.. and if LDR detect low intensity of light (cloudy or dark) all of the leds will on..is it possible ?

gerard_92:
thanks for the info.. is it possible for me to control the LEDs by using LDR ? Because this project is about green technology, which im going to design a energy saving light which is used inside office or houses. When the LDR detects high intensity of light, only several leds will on.. and if LDR detect low intensity of light (cloudy or dark) all of the leds will on..is it possible ?

Yeah but with PWM you are turning them all on for some percent of the time and off for the remainder (if any) 490 times a second so the leds go from off to dim to semi-bright to full bright. And it doesn't hurt the leds that I know of. PWM gives you brightness control from 0 to 255 == full OFF to full ON.
All your leds are one light. If you have 100 leds and run them at 10% it should be like 10 leds running full time.

You can control a bunch of leds on 1 pin and they will all be the same duty-cycle, the same percent brightness.
It's like if you have a 100 Watt incandescent and you only feed it 50 Watts instead of two 50 Watt bulbs and only turn one on. You'd get the same brightness but only need one switch.

GoForSmoke:

gerard_92:
thanks for the info.. is it possible for me to control the LEDs by using LDR ? Because this project is about green technology, which im going to design a energy saving light which is used inside office or houses. When the LDR detects high intensity of light, only several leds will on.. and if LDR detect low intensity of light (cloudy or dark) all of the leds will on..is it possible ?

Yeah but with PWM you are turning them all on for some percent of the time and off for the remainder (if any) 490 times a second so the leds go from off to dim to semi-bright to full bright. And it doesn't hurt the leds that I know of. PWM gives you brightness control from 0 to 255 == full OFF to full ON.
All your leds are one light. If you have 100 leds and run them at 10% it should be like 10 leds running full time.

You can control a bunch of leds on 1 pin and they will all be the same duty-cycle, the same percent brightness.
It's like if you have a 100 Watt incandescent and you only feed it 50 Watts instead of two 50 Watt bulbs and only turn one on. You'd get the same brightness but only need one switch.

Hmm..is it..so, if i dont use PWM it still can be done ?

What is the fixation with "some ON, the rest OFF"?

  1. PWM turns ON and OFF 490 times a second.
  2. 10 leds all at 10% PWM uses the same power as 1 led ON all the time.
  3. 10 leds all on 1 PWM actually gets you 10 leds with 256 different light/power levels.
  4. 10 leds set up so that you can choose how many light up gets you 10 different light/power levels.
  5. 10 leds set up with PWM each gets more levels and maybe with enough leds you can see a difference.
  6. Many leds on 1 PWM and transistor is simple wiring and simple coding.
  7. Many leds with individual control uses many more parts, more code, and is suited for fancy displays.
  8. You can use "software PWM" to increase the number of levels past 256 a few times over if you want.

Are you trying to save power? Usually that is to save money. If so then why spend a bunch more on the lamp?

You could run your lamp with an 8 pin ATtiny25 and a few more on the same less than $1 chip.
What is it you really want to do?

GoForSmoke:
What is the fixation with "some ON, the rest OFF"?

  1. PWM turns ON and OFF 490 times a second.
  2. 10 leds all at 10% PWM uses the same power as 1 led ON all the time.
  3. 10 leds all on 1 PWM actually gets you 10 leds with 256 different light/power levels.
  4. 10 leds set up so that you can choose how many light up gets you 10 different light/power levels.
  5. 10 leds set up with PWM each gets more levels and maybe with enough leds you can see a difference.
  6. Many leds on 1 PWM and transistor is simple wiring and simple coding.
  7. Many leds with individual control uses many more parts, more code, and is suited for fancy displays.
  8. You can use "software PWM" to increase the number of levels past 256 a few times over if you want.

Are you trying to save power? Usually that is to save money. If so then why spend a bunch more on the lamp?

You could run your lamp with an 8 pin ATtiny25 and a few more on the same less than $1 chip.
What is it you really want to do?

Yes. i do want to save power. actually this design project is based on green tech. So, what come across my mind is i want to make a prototype to show how we can reduces the uses of light inside a building. Not manually (switching on and off button), but automatically. So, what i can think is to control an LEDs in my project. It should be control by the amount of light received by LDR. So, i came with this schematic. So, if you can help me, how can i achieved my goal.. and i can improvise my circuit. :slight_smile:

What are LEDs you are you using, link please?

LarryD:
What are LEDs you are you using, link please?


this type of led. crystal white led 3v

See image attached:
Do you want to limit the LEDs to on/off or is it OK to use PWM?

Edit:
In the final design, MOS fets would be more efficient than bipolar transistors.

gerard_92:
[Yes. i do want to save power. actually this design project is based on green tech.
So, what i can think is to control an LEDs in my project. It should be control by the amount of light received by LDR. So, i came with this schematic. So, if you can help me, how can i achieved my goal.. and i can improvise my circuit. :slight_smile:

Use the LDR or maybe a few pointed around to determine the current light level and compute how bright you want your leds in total to be and drive them all to the same brightness using 1 PWM pin to switch the power transistor that powers all of the leds. The PWM takes care of the ON/OFF, all you will see is leds changing brightness.

2 leds running at 50% brightness is basically the same in power and light as 1 led at full bright. Why screw around with extra wires to turn 1 off and the other on when both can go from 0 to full in 255 steps?

Tell you what. Wire 1 led to a PWM pin through a 220 ohm resistor and vary the PWM. You can even use the LDR or turn-pot on an analog pin for input to get the variance.
The 1 led won't just be ON or OFF all the time except when it's turned all the way up or all the way down. But in between it really will turn ON and OFF faster than you can see and it only uses power when it is ON.

In fact you can remove the controller chip entirely and have it work. Oh yes you can.
You can put the LDR and a resistor in a circuit with a transistor that directly controls power to however many leds and they won't turn ON and OFF but simply run at some level of brightness inverse to what the LDR picks up.

GoForSmoke:
In fact you can remove the controller chip entirely and have it work. Oh yes you can.
You can put the LDR and a resistor in a circuit with a transistor that directly controls power to however many leds and they won't turn ON and OFF but simply run at some level of brightness inverse to what the LDR picks up.

yes.. i do realize that this project can be simple as it is. But i want to make a project that rely on a programmed so that i can improved this project apart from being a simple project. That is why i need your help.. Thanks