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 to stay in touch with us!
In this project with an arduino we will control a 5m LED strip with 60LED/m through a P-channel mosfet more precise an IRF 4905.
To switch the mosfet we use a 2n2222a npn transistor mounted with a resistor like a voltage divider.
Because the mosfet is p-channel when it has at gate 12 V it is blocked, when it has 0V on the gate pin it is like an closed switch.
The montage is in the image below:
When arduino pin is in high state the 2n2222a transistor is polarized and the mosfet start conducting(0V on the gate pin) and so the led strip is powered on.
Now with the blink example uploaded on the arduino and the schematic above the led strip will be switched off and on like the led from pin 13(a short video in the bottom of page).
Now let’s try to adjust the intensity with a potentiometer connected to an analog pin. The main schematic is the above one with the 2n2222a transistor connected to D11(capable of pwm) and the potentiometer must be connected with a pin at 5V on arduino, one at GND and the variable one(usually the one in the middle) at any analog pin, we choose analog 0(A0).
The program is this:
int ledStrip = 11; // 2n2222a connected to digital pin 11
int potentiometer = 0; // potentiometer connected to A0
void setup()
{
pinMode(ledStrip, OUTPUT); // sets the pin as output
}
void loop()
{
analogWrite(ledStrip, analogRead(potentiometer)/ 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}
Of course a short video at the final of the article.
Next what if we can change the intensity of the light from a remote and an infrared sensor. For that we use a IR remote kit. The schematic for this receiver depends by producer but you have to connect one pin to 5V one to GND and one(the signal) to a pwm pin(we choose digital 5).
Before to start with the LED strip we have to identify the codes for every button on the remote. For that below is the program:
#include <IRremote.h>
int RECV_PIN = 11;// the signal pin of the IR receiver to Arduino digital pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);// the code shown here
//must be copied in the program with pwm
irrecv.resume();
delay(200);
}
}
This program uses the IRremote.h library and it can be installed with sketch/include libraries/add zip library.
After that on the serial monitor will apear the HEX code for every button. If they are different from those to the program below you must copy from serial monitor and change them in the next program.
#include “IRremote.h”
int strip = 10;//LED strip connected to the digital pin 10
int receiver = 5; // the signal pin of the IR receiver to Arduino digital pin 11
int x=0;// value of pwm duty cycle
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(10, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
LEDstripPWM(); //call the LEDstripPWM function
irrecv.resume(); // receive the next value
}
// LEDstripPWM(); with this enabled the intensity will increase automatically
//like in the video otherwise the duty cycle will increase with multiple pushes
if(x>255){
x=0;
}
analogWrite(10, x);
}
void LEDstripPWM() //function for identify the button pressed and set
//the pwm duty cycle
{
switch(results.value)
{
case 0xFD00FF:
Serial.println(” 1 “);
x=25;
break;
case 0xFD807F:
Serial.println(” 2 “);
x=50;
break;
case 0xFD40BF:
Serial.println(” 3 “);
x=75;
break;
case 0xFD20DF:
Serial.println(” 4 “);
x=100;
break;
case 0xFDA05F:
Serial.println(” 5 “);
x=125;
break;
case 0xFD609F:
Serial.println(” 6 “);
x=150;
break;
case 0xFD10EF:
Serial.println(” 7 “);
x=175;
break;
case 0xFD906F:
Serial.println(” 8 “);
x=200;
break;
case 0xFD50AF:
Serial.println(” 9 “);
x=225;
break;
case 0xFD30CF:
Serial.println(” * “);
break;
case 0xFDB04F:
Serial.println(” 0 “);
x=0;
break;
case 0xFD708F:
Serial.println(” # “);
break;
case 0xFD8877:
Serial.println(” UP “);
x=x+20;
break;
case 0xFD9867:
Serial.println(” DOWN “);
x=x-20;
break;
case 0xFD28D7:
Serial.println(” LEFT “);
break;
case 0xFD6897:
Serial.println(” RIGHT “);
break;
case 0xFDA857:
Serial.println(“OK “);
break;
}
delay(200);
}
The video with blink program:
The video with potentiometer:
The video with the IRremote:


