## Introduction: 12 Volts Dimmable Lamp With Arduino or Atmega328

In this post i will show you how to make your own dimmable lamp.

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. This project is detailed below:

## Step 1: Choosing the Lamp and Other Components

In this project i've used a halogen lamp with 16W power at 12volts. We choose 12 volts because is a low voltage safe and we can obtain it from a power supply (you need a 12 volts power supply), 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 it will chop the voltage until we have the intensity we want. To chop the voltage we will use a transistor. To protect the microcontroller we use a optocoupler which has a limit of switching current. We choose a PC123. 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 faults in the part of mosfet. The wiring diagram is above. 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) the 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.

## Step 2: PWM Control From Atmega or Arduino

To adjust the PWM between 0 and 255 we use a 20kohms potentiometer on analog 3 pin.

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 spotPin=A3;

int LEDPin=9;

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: