I am wondering if I could use just the 6 PWM outputs of the Uno to light 12 bulbs with different brightnesses. Would that be possible? If they cannot all be on at once then what would a circuit look like to at least even have 6 on at any one time with variable brightness? Many thanks
tic84:
I am wondering if I could use just the 6 PWM outputs of the Uno to light 12 bulbs with different brightnesses. Would that be possible? If they cannot all be on at once then what would a circuit look like to at least even have 6 on at any one time with variable brightness? Many thanks
Well you can light 12 bulbs if you have 2 bulbs on each pin, but then each of the 2 bulbs sharing the same pin would be on at the same time (pwm varies the brightness by rapidly turning the light on/off to reduce the amount of light that is produced). The Mega 2560 has 15 PWM pins, so you could use that to drive all of the lights directly.
You would have to look at the data sheet for the leds (plus the resistors that you install to reduce the current to the leds) to see whether it violates the max current of the Arduino.
Alternatively, a bunch of variable light products have come out recently that allow you to chain multiple lights together, and you can control the brightness of each type. The one I'm familiar with is the Adafruit NeoPixels that come in various forms (individual pixels for breadboard use or sewn in costumes, a ring of 16 lights, a stick of 8, or strips of lights sold by the meter, that you can cut down to as many as you need). For the Neopixels, you need one pin to drive it, plus ground/power. For example, this a meter of lights (60 lights per meter) that they sell for $30: Adafruit NeoPixel Digital RGB LED Strip - White 60 LED [WHITE] : ID 1138 : Adafruit Industries, Unique & fun DIY electronics and kits. The meter strips also come in other varieties that are 30 lights per meter, and 144 lights per meter.
A third option is to get one of the i2c pwm controllers out there, that allow you to set the individual pwm settings for multiple lights. Various places sell these controllers, including Adafruit. The Adafruit i2c device can control 16 lights per device, and it comes in a shield for use with the Arduino or as a separate breakout board. Pololu.com has its own pwm controllers that you might use, and I'm sure there are other places.
A fourth option is just to mimic what the Arduino does with pwm, and that is busily turn the lights on/off without using pwm. I have no idea if an Uno can do this in a timely fashion for 12 separate lights (you probably need to think about going with direct port manipulation).
Thank you for the reply. I would ideally like the possibility of having all 12 lights on at different brightnesses and being able to change these brightnesses programatically. Your last idea of creating PWM through code....does anyone know if that is possible to reliably achieve?
tic84:
Thank you for the reply. I would ideally like the possibility of having all 12 lights on at different brightnesses and being able to change these brightnesses programatically. Your last idea of creating PWM through code....does anyone know if that is possible to reliably achieve?
Maybe I wasn't clear. Using neopixels, you can control the brightness of each of the 3 colors in each pixel individually. So if you choose for instance to just use red, you would be able to set the brightness of each pixel from 0 to 255 (if you only do red, you would set the green and blue brightness to 0).
For example, this is some code I wrote that randomly sets the color and brightness of the pixels of two rings of NeoPixels (meant to go in goggles):
#include <Adafruit_NeoPixel.h>
const int pin_neopixel = 4;
const unsigned num_rings = 2;
const unsigned num_pixels = num_rings * 16;
const unsigned delay_amount = 250;
const unsigned bright_max = num_pixels - 1;
/* Pick a ranodm unused pin. */
#ifdef __MK20DX128__
const int pin_random = A13;
#else
const int pin_random = A3;
#endif
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(num_pixels, pin_neopixel, NEO_GRB + NEO_KHZ800);
void setup (void)
{
Serial.begin (9600);
pixels.begin ();
// Seed random number generator from an unused analog input:
randomSeed (analogRead (pin_random));
}
void loop (void)
{
int first_pixel = random (0, num_pixels - 1);
int brightness = random (1, bright_max);
unsigned color = random (1, 7);
unsigned red = ((color & 0x1) != 0) * brightness;
unsigned green = ((color & 0x2) != 0) * brightness;
unsigned blue = ((color & 0x4) != 0) * brightness;
int i;
Serial.print ("Start at ");
Serial.print (first_pixel);
Serial.print (", brightness: ");
Serial.print (brightness);
Serial.print (", colors:");
if (red)
Serial.print (" red");
if (blue)
Serial.print (" blue");
if (green)
Serial.print (" green");
Serial.println ("");
for (i = 0; i < num_pixels; i++)
{
int pixel = (first_pixel + i) % num_pixels;
if (i < brightness)
pixels.setPixelColor (pixel, red, green, blue);
else
pixels.setPixelColor (pixel, 0, 0, 0);
}
pixels.show ();
delay (delay_amount);
}
Similarly, on the i2c and spm pwm controllers, you can control each individual led's brightness. However, since I don't own those devices, I don't have sample code to share.
Sorry...I hadn't given enough detail for the project. What would the best way to be to power my circuit from 120V AC mains and for that to regulate brightness of 12 30V light bulbs. Would I need to ADC and then DAC or is there a simpler way that I could use the AC line in to light the bulbs and the microcontroller to change the brightness and turn them on/off? Thanks
Obviously the requirement for A/C leds changes things completely. With my naive understanding of how A/C works, I don't see how a PWM solution would work with A/C, since the on/off cycle of PWM would hit the A/C circuit at different points on the sine wave.
Yes, PWM works fine for AC (incandescent) lights, that is exactly how your average wall plate dimmer operates.
To do it however, you need (optically isolated) triac control modules for the lights and I am unsure of a way to use the PWM functions in the Arduino, so it means a software system that is triggered by the zero crossings of the mains cycle. It then runs a loop comparing a counter to the threshold points for each of the lamp controllers and switching them on at the corresponding points.
What is difficult about that, is that this tends to take all of the MCUs effort just to run this at the correct speed and it is not easy to make it respond to commands or enquiries while it is doing that.
Where do 30V light bulbs come from, by the way?
Paul__B:
Yes, PWM works fine for AC (incandescent) lights, that is exactly how your average wall plate dimmer operates.
Looking for a semantic argument, eh?
Phase control clearly is PWM where the "pulse" is a section of the AC cycle and you vary its width. It just doesn't happen to be rectangular.
Unless you know of wall plate dimmers which do not function in this fashion?
Paul__B:
Looking for a semantic argument, eh?
No. It's about Clarity and not you.
You were leading the OP to believe that the answer lies in "Arduino PWM".
Whether by that "native capability" (490Hz) or by jiggering an ATmega timer for 60Hz or 50Hz and then playing with delay(), it's wrong.
Anyway, with a lamp, when actively managed, the trigger isn't pwm'd at all. It gets triggered by a brief pulse which meets the triac "trigger on" requirement, synchronised (very important) to the line frequency. For a resistive load (lamp) the pulse width is the same each time whether dim or bright or anywhere in between.
Inductive (or highly inductive) loads may require holding the trigger for the duration of the alternation.
[Wall dimmer triggers stay on throughout, though not out of necessity but for simplicity. They're R-C circuits, there's no active ZC-PWM management going on in there.]
Thanks guys for the replies. I realise the more that I read, the less that I know. I really want to learn and appreciate any help. After much reading, I came across this:
Which seems very similar to what I am needing. I would need to power 12 bulbs, all with different brightnesses using a microcontroller. Is there any advice or help you can give? I really need to go back to the basics I think.
A PIC10F200 is just another microcontroller.
What to do or how to use it would be a matter for a PIC forum out there.
No, I didn't mean that I am using a PIC microcontroller, but that is a similar project, minus the IR part. I would want to create that, but with 12 bulbs on an Arduino.
Still, it's a vague proposition.
I can think of several ways to do that.
What means of user input?
How many levels?
What is the design goal?
It's (always) the details.
There would be no user input to begin with. I just wanted to program the microcontroller to change the brightnesses in a sequence. My question is how best to use the AC 120V and DC 5V in one circuit so that the microcontroller can change the brightness as I have trouble understanding some concepts. Thanks
Did you read my blog ?
(see/click hotlink in Reply #7.)
Yes, I've been looking at that. Thank you very much! I fear that I do not have the ability to understand it well though as I am a programmer, but not great with the physical side of things. I don't even really know where to begin with building this. Perhaps it would be better to post this in a section that is more to do with general electronics as I don't understand how to select these components and their values
A part of my problem is that the few articles that do anything similar do not discuss how any of the components were selected. Any further help would be appreciated. Many thanks
So I found this
http://wiki.dxarts.washington.edu/groups/general/wiki/4dd69/AC_Dimmer_Circuit.html
Which is very close to what I want to build. It will just need to increase it to 12 bulbs from one.
One thing that I'm confused on is how the resistors can be placed on the AC mains at 120V?
If they are only rated at 1/4 or 1/2W then wouldn't there be a lot greater power running through them?
tic84:
Sorry...I hadn't given enough detail for the project. What would the best way to be to power my circuit from 120V AC mains and for that to regulate brightness of 12 30V light bulbs. Would I need to ADC and then DAC or is there a simpler way that I could use the AC line in to light the bulbs and the microcontroller to change the brightness and turn them on/off? Thanks
-
Do you really mean 30V light bulbs, or do you mean 30W light bulbs? It it's 30V, is that AC or DC?
-
Is is feasible for you to replace the light bulbs by high power LEDs?