How to make a 12v PWM circuit Arduino using UNO board.
Hello guys, In this tutorial, we will explain how to make a 12v PWM circuit using the Arduino platform. For this, we first need to learn what is the PWM. PWM is simply called pulse width modulation. Click this link to learn more about this. So then let’s get to the project today.
If you have any knowledge about Arduino, you know that we can get 5VDC voltage and 40mA current through the Arduino board. For this reason, external power must be obtained to control a 12V device. So we can do this easily through a Relay module, but we cannot get a PWM value through a Relay module. (If you do not understand Relay, click on this link)Therefore we can use a transistor for this. Through this, we can perform the PWM process properly.
So this project used a MOSFET-type transistor. A transistor is simply an electronic switch. This transistor can be turned on/off to the desired size by the PWM value obtained by a PWM PIN on the Arduino board. That is, we can increase or decrease the 12v potential flowing through the transistor to the desired level. This causes the brightness of the 12v LED strip to increase or decrease. If you do not understand Transistor, study it online.
A variable resistor (Potentiometer) is used to increase or decrease the amount of light we need.
Well, now we will learn step by step how to make this project. The required components are given below. These can be easily purchased from the links below.
- Arduino UNO board x 1 – Our Store / Amazon
- IRF9540 FET Transistor x 1 — Amazon
- C1815 Transistor x 1 — Amazon
- Potentiometer x 1 — Our Store / Amazon
- 12v LED strip x 1 — Amazon
- 330 ohm resistor x 1 — Our Store / Amazon
- 1k resistor x 1 — Our Store / Amazon
- 10k resistor x 1 — Our Store / Amazon
- Breadboard x 1– Our Store / Amazon
- Jumper wires — Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Ok now, connect these components using the circuit diagram below.
Step 3
Now we will create the required program for this project. You can see it below.
- The complete program of this project – Download
/*12V PWM circuit.
Serial monitor readings.
created by the SriTu Tech team.
Read the code below and use it for any of your creation
*/
void setup() {
Serial.begin(9600);//enable serial monitor
pinMode(3, OUTPUT);//define pin
}
void loop() {
int pwm = analogRead(A0);//read analog value and put in to the variable
pwm = map(pwm, 0, 1023, 0, 255);// 0-1023 to 0-255
Serial.println(pwm);//print serial monitor
analogWrite(3,pwm);//PWM bulb
}
Code explanation
First of all, the PWM PIN used for this project has been converted to an OUTPUT PIN.
void setup() {
Serial.begin(9600);//enable serial monitor
pinMode(3, OUTPUT);//define pin
}
After, the analog value obtained by the Potentiometer in the Void loop is inserted into the variable named “PWM”. Next, the value from 0 to 1024 received through Analog read is converted from 0 to 255 and it is written in PWM PIN. Therefore, when the knob of the potentiometer is rotated, the PWM value changes. Then the amount of light increases or decreases.
void loop() {
int pwm = analogRead(A0);//read analog value and put in to the variable
pwm = map(pwm, 0, 1023, 0, 255);// 0-1023 to 0-255
Serial.println(pwm);//print serial monitor
analogWrite(3,pwm);//PWM bulb
}
Step 4
Finally, select the correct board and port, after, upload this code.
Now you can test this project by rotating the potentiometer. The full video guide is below. So, we hope to see you in the next project. Have a good day.
How to make a 12v PWM circuit Arduino using UNO board.
Could you please explain why the mosfet it used here.
Thank you
The MOSFET act as a switch
Also the Arduino typically operates on 5Volts with the LED strip needing 12Volts. The more LED’s in the strip the more current it will need to draw, the MOSFET enables this current to be drawn from the power supply without overloading the Arduino.
Yes of course
Why is the C1815 transistor used? What function does it serve in this circuit?