Arduino IR remote control tutorial with DC motor and RGB LED

188bet服务官网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.

MATERIALS REQUIRED:

  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

SCHEMATIC DIAGRAM:

CONTROLLING A DC MOTOR USING MOSFET:

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.

CONTROLLING WS2812B WITH ARDUINO:

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.

IR TRANSMISSION AND DECODING:

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 fromGithub
  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.

WORKING VIDEO:

CODE:

#include
         
          #include
          
           #ifdef __AVR__    #include
           
            #endif    // 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)!#endif    // End of trinket special code    pixels.begin()!// This initializes the NeoPixel library.Serial.begin(9600)!irrecv.enableIRIn()!// Start the receiver    pinMode(DcMotor,OUTPUT)!}    void loop() {  if (irrecv.decode(&results)) {      Serial.println(results.value, HEX)!InputIr = (results.value)!delay(100)!irrecv.resume()!// Receive the next value    }      if (InputIr == ZeroMove){      Serial.println("CHECK0")!for(int i=0;i
            
             

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.


Leave a Comment

Your email address will not be published.Required fields are marked*

Baidu
map