Arduino IR remote control tutorial with DC motor and RGB LED

In this tutorial am going to demonstrate how to use IR as a medium for remote control and how to integrate in variety of your Arduino projects. For the purpose of demonstration I have used DC motor and RGB LED module WS2812 as the things to control using IR remote.


  1. MOSFET IRLB8743
  2. Resistor 1K ohms
  3. DC motor – 5v
  4. Infrared remote or transmitter
  5. Infrared receiver module
  6. External supply voltage – 5v
  7. WS2812B LED’s



We are going to use MOSFET as a switch to activate the DC motor. This is because Arduino cannot source the current required to drive a motor from its pins directly so we need to use any type of switch which in my case is the MOSFET. As we already know if we apply the threshold voltage to the gate of the MOSFET the drain and the source current will run through them. We are also adding a limiting resistor (10k in my case).Our DC Motor is going to be connected to the drain pin of our MOSFET. After our connection is complete we connect in Pin 10 of our Arduino to the gate of the MOSFET. The connection as you can see is fairly easy.


The WS2812B RGB LED’s have 3 Pins (GND,DATA,5V) so we connect data in pin 5 of our Arduino. And for the GND we connect it our Arduino and external power supply GND too in order to have common ground in our circuit. Next we connect our 5 Volts to our power supply.We are using an external power supply because as we know Arduino cannot provide the circuit more than 40ma the max rating is 50ma so we  will run into the risk of damaging the microcontroller. In my case i am using 8 WS2812B leds which they draw 20ma per color,which means 20ma*24=480ma so let’s say at full PWM we are using 0.5 Ampere of current.


First of all i am using 1838T Infrared Receiver and general Infrared Remote control for my project I first choose the numbers from my controller that i want to use and i checked their hexadecimal number using the IRremote.h library example sketch in order to find the correct hexadecimal numbers (which is in my case→0:FF6897, 1:FF30CF, 2:FF18E7, 3:FF7A85). To determine the hex values transmitted by your remote you need to perform the following steps.

  1. Add this IR remote control library from Github 
  2. Upload the IRrec test sketch into your Arduino from the Examples section.
  3. You must be using IR receiver connected to the Arduino.
  4. Now open the serial remote in Arduino IDE
  5. When you press corresponding buttons in your IR remote, you can actually watch the live HEX values as data in the serial monitor.

Using this method you can also use any type of IR remote even your TV remote or remote for any other appliances.Then i connected my receiver as shown in the schematic and i declared those hexadecimal values as unsigned long int in my code.



#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            5

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      8

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 100; // delay for half a second
//Pin 11 for IR Receiver
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
//Pin 10 for Dc Motor
int DcMotor = 10;

//My IR transmitter hexadecimal values that i choose.
unsigned long int InputIr;
unsigned long int ZeroMove = 0xFF6897;
unsigned long int FirstMove = 0xFF30CF;
unsigned long int SecondMove = 0xFF18E7;
unsigned long int ThirdMove = 0xFF7A85;

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  // End of trinket special code
  pixels.begin(); // This initializes the NeoPixel library.
  irrecv.enableIRIn(); // Start the receiver

void loop() {
if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    InputIr = (results.value);
    irrecv.resume(); // Receive the next value

  if (InputIr == ZeroMove){
      for(int i=0;i<NUMPIXELS;i++){

        // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
        pixels.setPixelColor(i, pixels.Color(150,0,0)); // color of ws2812b that you like RGB
     ; // This sends the updated pixel color to the hardware.
        delay(delayval); // Delay for a period of time (in milliseconds).
        analogWrite(DcMotor,70  );
  if (InputIr == FirstMove){
      for(int i=0;i<NUMPIXELS;i++){

         pixels.setPixelColor(i, pixels.Color(126,60,0)); 

  if (InputIr == SecondMove){
       for(int i=0;i<NUMPIXELS;i++){

          pixels.setPixelColor(i, pixels.Color(8,40,126)); 
  if (InputIr == ThirdMove){
       for(int i=0;i<NUMPIXELS;i++){

          pixels.setPixelColor(i, pixels.Color(0,155,0)); 
   if  ((InputIr != ZeroMove)&&(InputIr != FirstMove)&&(InputIr != SecondMove)&&(InputIr != ThirdMove)); {
       for(int i=0;i<NUMPIXELS;i++){
        pixels.setPixelColor(i, pixels.Color(0,0,0)); 

You can figure out the value of each and every button in your IR remote. This will give an many codes which in turn means many possible devices to interface and control with Arduino Uno.

The following two tabs change content below.
DoublePi Engineer

DoublePi Engineer

I am electrical engineer and also DIY enthusiast, i like making new projects teach people and always learn new stuff about science 😀
DoublePi Engineer

Latest posts by DoublePi Engineer (see all)

Ask your query

Notify of