How to change intensity of 12 volt DC 40 watt bulb

HI i am new to this stuff,

I want to control intensity of intensity of 12 volt DC 40 watt bulb, I have collect so many PWM but i am confusing in Bulb Driver circuit. any body will help

What Arduino are you using?

Use a logic level MOSFET like the IRLZ44

Thank you Sir,

I am Using Now for Experiment, Arduino Uno, My plan is To Make Separate PCB For it,
For Change PWM I select code is Given below,
const int brightnessUp = 10; // the number of the pushbutton pin
const int brightnessDown = 9; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int maxBrightness = 12; //this can be any number - it's the number of steps between dimmest and brightest.

// variables will change:
int brightness = maxBrightness;
int interval=1;

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pins as an input:
pinMode(brightnessUp, INPUT);
pinMode(brightnessDown, INPUT);
Serial.begin(9600);
}

void loop(){
if (digitalRead(brightnessUp) == HIGH && brightness < maxBrightness){
brightness = brightness + interval;
//if the brightness Up button is pushed, add one degree of brightness to the current level
Serial.println(brightness); //for debugging purposes
}
if (digitalRead(brightnessDown) == HIGH && brightness > 0){
brightness = brightness - interval;
//if the brightness Down button is pushed, subtract one degree of brightness from the current level
Serial.println(brightness); //for debugging purposes
}
delay(100);
analogWrite(ledPin, map(brightness, 0, maxBrightness, 0, 255));
//this code maps the max brightness constant to the max LED brightness

}

Here I will separate Button for Increment and decrement, and Send Brightness Value to LCD & Serial Monitor

Pin13 on an Uno is not a PWM pin.
Leo..

1 Like
BOARD PWM PINS PWM FREQUENCY
Uno, Nano, Mini 3, 5, 6, 9, 10, 11 490 Hz (pins 5 and 6: 980 Hz)
Mega 2 - 13, 44 - 46 490 Hz (pins 4 and 13: 980 Hz)
Leonardo, Micro, Yún 3, 5, 6, 9, 10, 11, 13 490 Hz (pins 3 and 11: 980 Hz)
Uno WiFi Rev2, Nano Every 3, 5, 6, 9, 10 976 Hz
MKR boards * 0 - 8, 10, A3, A4 732 Hz
MKR1000 WiFi * 0 - 8, 10, 11, A3, A4 732 Hz
Zero * 3 - 13, A0, A1 732 Hz
Nano 33 IoT * 2, 3, 5, 6, 9 - 12, A2, A3, A5 732 Hz
Nano 33 BLE/BLE Sense 1 - 13, A0 - A7 500 Hz
Due ** 2-13 1000 Hz
101 3, 5, 6, 9 pins 3 and 9: 490 Hz, pins 5 and 6: 980 Hz

Sorry sir,

It was my mistake, I will keep in mind that pin 13 is not for PWM, BUT MY MAIN INTENSION IS TO KEEP SEPARATE BUTTON FOR INCREASE AND DECREASE BRIGHTNESS OF LAMP

If any other short code for it then also suggest that

consider


#define ButUp   A1
#define ButDown A2
byte pinsBut [] = { ButUp, ButDown };
#define N_BUT   sizeof(pinsBut)

byte butLst [N_BUT];

byte pinLed    = 10;

enum { Off = HIGH, On = LOW };

const int MaxBrightness = 255;
int brightness = MaxBrightness;

// -----------------------------------------------------------------------------
void loop ()
{
    for (unsigned n = 0; n < N_BUT; n++)  {
        byte but = digitalRead (pinsBut [n]);

        if (butLst [n] != but)  {
            butLst [n] = but;

            if (On == but)  {
                switch (pinsBut [n])  {
                case ButUp:
                    if (MaxBrightness <= ++brightness)
                        brightness = MaxBrightness;
                    break;

                case ButDown:
                default:
                    if (0 >= --brightness)
                        brightness = 0;
                    break;
                }
            }
    
            analogWrite (pinLed, brightness);
            Serial.println (brightness);
        }
    }
}

void setup () {
    pinMode (pinLed, OUTPUT);

    for (unsigned n = 0; n < N_BUT; n++)  {
        pinMode (pinsBut [n],   INPUT_PULLUP);
        butLst [n] = digitalRead (pinsBut [n]);
    }

    analogWrite (pinLed, brightness);

    Serial.begin (9600);
}

Dear Sir, This code is confusing, Here two analog Pin has acquired, It should be by digital pin , when i start brightness is very high, whenever or anybody will start any Instrument PWM Should be LOW to high Not High to Low, May be this code is short for experts, but i am new bee, so it is hectic for me

I’m sure you can figure the initial brightness by yourself.
It’s pretty clearly obvious, otherwise, take it to the ‘paid’ section, and someone will change it for you.

i test code i post with a multifunction board that has buttons and LEDs. the buttons are connected to the analog inputs which can be used as digital I/O

on my board, since the LED is turned on by setting the output LOW and the pin is initialized to 255, the LED is off when started.

thank you sir for helping me ,

i have collected new here
volatile int i=0;//initializing a integer for incrementing and decrementing duty ratio.
void setup()
{
pinMode(6, OUTPUT); // sets the pin3 as output
pinMode(2, INPUT);// sets the pin0 as output
pinMode(4, INPUT);// sets the pin1 as output
Serial.begin(9600);
}
void loop()
{
analogWrite(6, i); // analogWrite values from 0 to 255
if (digitalRead(2)==LOW)
{
if (i<255)
{
i++;//if pin0 is pressed and the duty ratio value is less than 255
delay(150);
Serial.println(i);

                            }
            }
            if (digitalRead(4)==LOW)
            {
                            if (i>0)
                            {
                                            i--;// if pin1 is pressed and the duty ratio value is greater than 0
                                            delay(150);
                                            Serial.println(i);
                                            
                            }
            }

}

Using code tags will help us help you.