Search

12 VOLTS LAMP DIMMING WITH ATMEGA 328

 

 

 

 

How many time do you want a lamp that  can be adjusted in intensity???

Of course you can buy it but why not to make yourself one as you like (homemade) and have the satisfaction that you made something by yourself.

Such a project is detailed below:

In this case we use a halogen lamp with 16W power at 12volts. We choose 12 volts because is a low voltge safe and we can obtain it from a power source, with the condition to have a bigger current than lamp. That current is calculated with this formula:

Power (lamp)=12 volts x Current

Current=Power lamp /12 volts.

The halogen lamp is not very efficient and so we recommend a LED lamp , or what you find at your store, but be carefully to be capable dimming. The mount base (GU 10 or GU 5.3 or anything you can find, but to be compatible with the lamp) remain at your own decision.

Because sometimes we want to dim the lamp, we try with an Atmega 328 and anothers components to reduce the intensity with a potentiometer. The atmega 328 has the PWM option, so we will chop the tension until the intensity we want. To chop the tension we will use a transistor.

An article about Atmega328 sandalone you have here.

Before we start we recommend to read about PWM here.

At 16W power the lamp will absorb 1.4 Amps, so we have to place a transistor capable to manage the 1.4 Amp. For this we use a 2SK2648 (from an old PC power source, datasheet here), a MOSFET with n canal that can support a 9 Amps, more than sufficient.

An important characteristic of MOSFETs is RDS(on)= f(ID and VGS), the resistance of mosfet when it is in conduction. Another characteristic unlike the bipolar transistor is that the mosfet need a tension on the gate bigger than 10 volts, we will use 12 from power source.



Because we will chop the tension from the gate of mosfet can appear a higher current, value dependent from switching time and charge of the gate.

From the VDS=f(Qg,VGS) chart for a 12 volts tension the Qg is around 10nC.

Because the PWM of atmega 328 has a switching frequency about 500Hz we have a switching time around 2 ms. The current is I=Q/t, around I=5uA. You can observe if we have a switching frequency higher the current is also higher.

Why we have calculate this value???

To protect the microcontroller we use a optocoupler which has a limit of switching current. We choose a PC123 (datasheet here). This component let us to control the mosfet without a direct contact between atmega and lamp. This control is made by light and protect the atmega from eventual defect in the part of mosfet.

The wiring diagram is below:

schema

The signal comes from atmega’s pin in optocoupler and comes out through the optocoupler transistor and goes to the mosfet, which copy the PWM signal from the atmega.

The 10k resistor and the transistor of optocoupler make a voltage divider, so when the transistor is polarized (like a closed contact) and mosfet is blocked (lamp off), when the transistor is blocked (like a open contact) the mosfet receive on gate 12 volts and it is polarized (lamp on). If we have a p channel mosfet the situation was reversed.

To adjust the PWM between 0 and 255 we use a 20kohms potentiometer on analog 3 pin like in the image below:

WP_20160611_12_15_37_Pro

Because the 1.4 Amps flows through a small piece(mosfet) it will be heating up, so we have to mount a radiator on it. We use also a radiator from a PC power source.

In the picture below is the mode how we choose this radiator for the  mosfet:

radiator

More detailes about radiator calculus, even a online calculator for electronic devices you can find herehere and here.

All the parts we have mounted on a PCB created like in this post or a prototype board.

The PCB schematic with FREEPCB can be downloaded below:

LAMP PCB with FREEPCB

Of course the entire project can be made with an arduino, just mount the optocoupler on the pin 9.

The program for this project is:

int potPin=A3;
int LEDPin=9;
int readValue;
int writeValue;
void setup() {
// put your setup code here, to run once:
pinMode(spotPin, INPUT);
pinMode(LEDPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
readValue=analogRead(spotPin);
writeValue=(255./1023.)*readValue;
analogWrite(LEDPin, writeValue);
}

 

Please let us in the comment zone any suggestions that you think will improve the article!

If you like the article click the follow button from social media to stay in touch with us!

 

A small video to demonstrate how it’s work:

 

 

Facebooktwitterpinterest

Related posts

Leave a Comment

Show Buttons
Hide Buttons