Controlling DC Motors Using Arduino and IR Remote

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

12/13/2019 Controlling DC Motors using Arduino and IR Remote

HOME / PROJECTS, EMBEDDED, ARDUINO / CONTROLLING DC MOTORS USING ARDUINO AND IR REMOTE

Controlling DC Motors using Arduino and IR Remote

09 Controlling DC Motors using Arduino and IR Remote


Jul  By Ali Hamza  Arduino, Embedded, Projects  Arduino, Arduino Uno, DC Motor, IR Remote, IR Sensor, L293D  7 Comments

In this project we will learn how to decode IR remote signals with Arduino and to control
Contents
DC motors depending on the button pressed. For demonstrating the working we are
using ve buttons on the remote. When the next button on the remote is pressed, 1 Components Required
motors will rotate in clockwise direction. And if the previous button is pressed motors 2 Circuit Diagram
will rotate in anticlockwise direction. We can also control these two motors individually 3 Arduino IR Remote Library
using left, right arrow buttons and stop button can be used to stop the rotation. 4 Finding IR Remote Codes
4.1 Program Code
We are using 1838 IR receiver (AX-1838HS, TL1838, TSOP1838)   for sensing IR signals 4.2 IR Remote Codes in Serial Monitor
transmitted from the remote. Arduino Uno is the brain of this project. We are using 5 Program
5.1 Explanation
L293D motor driver IC to drive motor since Arduino won’t be able to supply enough
6 Working
current to drive a DC motor. L293D can drive two dc motors at the same time.
7 Video

Components Required
Arduino Uno
IR Sensor 1838
IR Remote (TV remote or any other IR remote will work ne)
L293D DC Motor Driver IC
2x DC Motors
9V Battery
Breadboard
Connecting Wires

Circuit Diagram

Controlling DC Motors using IR Remote – Circuit Diagram

Firstly we can connect IR sensor to Arduino Uno.

Connect the left pin of IR sensor which is ground to the ground of the Arduino 

https://electrosome.com/dc-motors-arduino-ir-remote/ 1/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

Connect the middle pin which is 5V input to the 5V output pin of the Arduino.
Connect the right pin which is signal output pin to the digital pin 2 of the Arduino.

We are using a 9V battery to power 2 DC motors.


Now we can connect L293D IC to Arduino Uno. The pin out of the IC is shown below.

Z wave Smart Home Hub


Z-wave compatible home hub. Connect to your cloud. Access various of
smart devices.

dusuniot.com OPEN

Pin Diagram of L293D

Connections are as follows :

Connect enable pins (Pin 1, Pin 2) of L293D to 5V output of Arduino. This enables two H-Bridge channels inside the IC to drive
two DC motors.
Connect logic voltage input (Pin 16) of L923D to 5V output of Arduino. This de nes the voltage (5V) logic of control signals .
Connect motor/drive supply (Pin 8) of L293D to +ive of the 9V battery.
Connect ground pins (Pin 4, 5, 12, 13) to ground of Arduino and -ive of the battery.
Connect pin 2 of L293D to digital pin 6 of the Arduino.
Connect pin 7 of L293D to digital pin 5 of the Arduino.
Connect pin 10 of L293D to digital pin 11 of Arduino.
Connect pin 15 of L293D to digital pin 12 of Arduino
Connect rst DC motor to Pin 3 and Pin 6 of L293D.
Connect second DC motor to Pin 11 and Pin 14 of L293D.

Arduino IR Remote Library


You need to manually add IR Library to Arduino IDE as it is not included by default. You can ignore it if you already added it.
Otherwise you can do following steps for that.

Download Library : Arduino IR Remote Library.


Open Arduino IDE.
Go to Sketch >> Include Library >> Add .ZIP Library
Select the downloaded ZIP le and press open.

Finding IR Remote Codes


Hope you already included IR remote library. Next step is to nd CODES of required buttons in you IR Remote. Then we will use
these decoded IR remote CODES in the main program to detect which button is pressed. You can use the following program to
decode IR codes.

Program Code

https://electrosome.com/dc-motors-arduino-ir-remote/ 2/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

#include <IRremote.h> //including the remote library


int receiver_pin = 2; //output pin of IR receiver to pin 2 of arduino
IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2
decode_results output;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
receiver.enableIRIn(); // Start to take the output from IR receiver
}

void loop() {
if (receiver.decode(&output)) {
unsigned int value = output.value;
Serial.println(value);
receiver.resume();
}
}

IR Remote Codes in Serial Monitor


Run above code and open the serial monitor to view decoded codes. Press required buttons of your remote pointing towards the IR
receiver. You can use any IR remotes like TV remote or even you can give  signals from mobile by installing IR remote app (only if you
mobile has IR transmitter). When you press buttons, you can see the decoded code of each buttons in the serial monitor as shown
below.

IR Remote Codes in Serial Monitor

Now you can copy these decoded IR remote codes to the main program (see below) for each function.

Program

https://electrosome.com/dc-motors-arduino-ir-remote/ 3/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

#include <IRremote.h> //including the remote library

#define Next_button 60891 // code received from next button


#define Prev_button 49467 // code received from previous button
#define left_button 58747 // code received from left button
#define right_button 15355 // code received from right button
#define Stop_button 7611 // code received from stop button

int receiver_pin = 2; //output pin of IR receiver to pin 2 of arduino


//initializing the pins for leds
int left_motor1 = 11; //pin 6 of arduino to pin 7 of l293d
int left_motor2 = 12; //pin 7 of arduino to pin 2 of l293d
int right_motor1 =6; //pin 5 of arduino to pin 10 of l293d
int right_motor2 = 5; //pin 4 of arduino to pin 15 of l293d

IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2


decode_results output;

void setup() {
Serial.begin(9600);
receiver.enableIRIn(); // Start to take the output from IR receiver
//initializing all the pins where we have connected the led's as output pins
pinMode(left_motor1, OUTPUT);
pinMode(left_motor2, OUTPUT);
pinMode(right_motor1, OUTPUT);
pinMode(right_motor2, OUTPUT);
}

void loop() {
if (receiver.decode(&output)) {
unsigned int value = output.value;
switch(value) {
case Next_button:
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,LOW);
break;
case Prev_button:
digitalWrite(left_motor1,HIGH);
digitalWrite(left_motor2,LOW);
digitalWrite(right_motor1,LOW);
digitalWrite(right_motor2,HIGH);
break;
case left_button:
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,HIGH);
break;
case right_button:
digitalWrite(left_motor1,HIGH);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,LOW);
break;
case Stop_button:
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,LOW);
digitalWrite(right_motor1,LOW);
digitalWrite(right_motor2,LOW);
break;
}
receiver.resume();
}
}

Explanation 

https://electrosome.com/dc-motors-arduino-ir-remote/ 4/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

In the rst section we are adding the IR library for decoding IR signals from the remote. Then we de ned decoded codes of remote
buttons that we got from the rst program. I have added ve buttons which will control both motors in clockwise, anticlockwise
directions, individual left right motor control and a stop button.

#include <IRremote.h> //including the remote library


#define Next_button 60891 // code received from next button
#define Prev_button 49467 // code received from previous button
#define left_button 58747 // code received from left button
#define right_button 15355 // code received from right button
#define Stop_button 7611 // code received from stop button

In the next section we are de ning all digital input output pins of Arduino which are used in this project.

int receiver_pin = 2; //output pin of IR receiver to pin 2 of arduino


//initializing the pins for leds
int left_motor1 = 11; //pin 6 of arduino to pin 7 of l293d
int left_motor2 = 12; //pin 7 of arduino to pin 2 of l293d
int right_motor1 = 6; //pin 5 of arduino to pin 10 of l293d
int right_motor2 = 5; //pin 4 of arduino to pin 15 of l293d

After that we are we are initializing the IR library and digital pins.

IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2


decode_results output;

void setup() {
Serial.begin(9600);
receiver.enableIRIn(); // Start to take the output from IR receiver
//initializing all the pins where we have connected the led's as output pins pinMode(left_motor1, OUTPUT);
pinMode(left_motor2, OUTPUT);
pinMode(right_motor1, OUTPUT);
pinMode(right_motor2, OUTPUT);
}

Now in the main program the following section will decode the received IR signal and will be stored in the variable named ‘value’.
After that we have made di erent conditions using switch statement. If the code received will match any of these conditions then
motors will be switched accordingly.

if (receiver.decode(&output)) {
unsigned int value = output.value;
switch(value) {
case Next_button:
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,LOW);
break;

Working

https://electrosome.com/dc-motors-arduino-ir-remote/ 5/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

Controlling DC Motors using IR Remote

You can watch the following video to see how it works.

Video

Controlling DC Motors with Arduino and IR Remote

https://electrosome.com/dc-motors-arduino-ir-remote/ 6/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

Z wave Smart Home Hub


Z-wave compatible home hub. Connect to your cloud. Access various of
smart devices.

dusuniot.com OPEN

Like 4.8K people like this. Sign Up to see what your


friends like.

Related Posts:

Temperature Controlling of DC Controlling LED’s Digital Thermometer


Controlled Fan using Motors using using IR Remote using Arduino and Digital Door Lock
Arduino MPU5060 Control… DS18B20 Sensor using Arduino

Home Automation
Arduino Weather Calculator using using Arduino and
Station Web Server Arduino Uno ESP8266 Module

 Share this post

    

 Author
Ali Hamza

 Comments (7)

Bob
Hi. When I try to compile the “Finding IR remote code” program I get this error message. I double checked the wiring and
everything look okay. I also made sure that I downloaded and added the right zip library. Do you have any idea why this
error message occurs? Thanks for any help.
C:Program Files (x86)ArduinolibrariesRobotIRremotesrcIRremoteTools.cpp:5:16: error: ‘TKD2’ was not declared in this scope
int RECV_PIN = TKD2; // the pin the IR receiver is connected to
^
Multiple libraries were found for “IRremote.h”
Used: C:Program Files (x86)ArduinolibrariesRobotIRremote
Not used: C:UserscharlDocumentsArduinolibrariesArduino-IRremote-master
exit status 1
Error compiling for board Arduino/Genuino Uno. 

https://electrosome.com/dc-motors-arduino-ir-remote/ 7/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

October 22, 2017 at 7:11 am

Bob
Nevermind! I solved the issue… I just had to install the library in the library manager!
October 22, 2017 at 8:22 am

Bob
Okay now I have a di erent issue. I have tried to recieve a signal from two di erent TV remotes on the “Finding IR remote
code” and no remote codes are printed to the console window. Once again I am pretty certain that my circuits are correct
and the code compiles ne. Do you have any troubleshooting ideas? Thanks!
October 22, 2017 at 8:39 am

Tech Tek
JUST PUT DELAY(200); AFTER receiver.resume(); AND ALL WORKS FINE.
THANKS
February 3, 2018 at 11:10 pm

Islam Ahmad
how to make the motors stop when i left my hand o the remote ?
May 3, 2018 at 7:54 pm

Moist Manatees
I believe the “Connections are as follows:” section is missing one step (though the diagram shows it):
Connect enable pins (Pin 3, Pin 4), which are on pin 9 of L293D to 5V output of Arduino.
January 9, 2019 at 9:31 am

Ayush Meena
i tried same connections but my aurdino is not getting on
April 8, 2019 at 2:10 am

Leave a Reply

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

Comment

Name *

Email *

Website

https://electrosome.com/dc-motors-arduino-ir-remote/ 8/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

Save my name, email, and website in this browser for the next time I comment.

POST COMMENT

RELATED POSTS

Controlling LED’s Mobile Phone Automatic Garden Calcula


using IR Remote Detector Circuit Light Controlling Arduino
Control – Arduino July 16, 2017 | Aman Deep | 555 System December 26
Circuits, Electronics, Hobby Arduino, Em
Project Circuits, Projects | 555, mobile, September 25, 2012 | Abhay Arduino, Ard
Op-Amp, Sensor | 1 Comment Bajpai | Electronics, Hobby GLCD, Keypa
February 23, 2018 | Ali Hamza | Circuits, Projects | 555, Automatic, 0 Comments
Arduino, Embedded, Projects | IR This is a very interesting hobby
Garden, light, Op-Amp | 15
Receiver, IR Sensor, IR Transceiver, project which can detect active Arduino Uno
Comments
mobile phone or GSM build project
LED Control, Remote, Sensor | 0
communication in its proximity.... Just like my previous circuit using them look m
Comments
LM358 this is also very cheap,also project, we a
Read More 
This article allows you to turn ON under 100 rupees. This is a
and OFF LED's using a cheap IR circuit... Read More 
remote control. Here we used an...
Read More 
Read More 

RECENT POSTS

Installing Keil IDE – ARM Microcontroller Tutorial – Part 1


October 8, 2019

Sending E-mail from ESP8266 – IoT Project


January 17, 2019

Controlling LED using ESP8266 and Telegram Bot – IoT Project


December 21, 2018

Interfacing MPU-6050 / GY-521 board with Arduino Uno


December 16, 2018

Updating Sensor Data to Google Spreadsheet using ESP8266 – IoT Project


November 28, 2018

Flashing Espressif and NodeMCU Firmware to ESP8266


October 28, 2018

FOLLOW US

  

https://electrosome.com/dc-motors-arduino-ir-remote/ 9/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

MOST VIEWED

Astable Multivibrator using Transistors


by Ligo George

Getting Started with MPLAB XC8 Compiler – LED Blinking


by Ligo George

LED Blinking using 8051 Microcontroller and Keil C – AT89C51


by Ebin George

What is a Microprocessor ?
by Ligo George

5V Power Supply using 7805 Voltage Regulator with Design


by Manoj Shenoy

Transistor as a Switch
by Ligo George

CATEGORIES

 Electronics

 555 Circuits

 Basic Electronics

 Opamp

 Electronics News

 IC

 Power Supply

 Sensors

 What is Inside?

 Featured

 Mobiles

 News

 Processors

 Projects

 Embedded

 Arduino

 AVR Microcontroller

 ESP8266

 PIC Microcontroller

 Hobby Circuits

 IoT

 Softwares

 Tablets
https://electrosome.com/dc-motors-arduino-ir-remote/ 10/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote
 Tablets

 Technology Transfer

 Tutorials

 8051 Microcontroller

 8085

 Arduino

 ARM

 ARM7

 ATMEL AVR

 CloudX

 ESP8266

 MATLAB

 OpenWrt

 PCB Designing

 DipTrace

 OrCad

 PIC Microcontroller

 CCS C Compiler

 Hi-Tech C

 MikroC

 MPLAB XC8

 Python

 Raspberry Pi

 Python Rpi

 SCILAB

MOST COMMENTED

Digital Clock using PIC Microcontroller and DS1307 RTC


by Ligo George

Voltmeter and Ammeter using PIC Microcontroller


by Ligo George

Water Level Indicator and Controller using PIC Microcontroller


by Ligo George

Interfacing HC-SR04 Ultrasonic Sensor with PIC Microcontroller


by Ligo George

Automatic Power Factor Controller using Microcontroller


by Divya Syamala

USB PIC Programmer : PICKit2


by Ligo George 

https://electrosome.com/dc-motors-arduino-ir-remote/ 11/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote

TAGS

3D 16F877A 555 8051 MICROCONTROLLER ANDROID ARDUINO ARDUINO UNO ATMEGA32 ATMEL DC MOTOR DHT22

ELECTRONICS EMBEDDED ESP8266 GOOGLE HI-TECH C IOT L293D LCD LED MATLAB MICROCONTROLLER MIKROC

MOBILE MOTOR MPLAB MPLAB XC8 OP-AMP PCB PIC PROTEUS PWM PYTHON RASPBERRY PI RFID SAMSUNG

SENSOR SENSORS SERVO MOTOR SMARTPHONE TABLET TRANSISTOR TRANSISTORS TUTORIALS XC8

RECENT COMMENTS

 Chand Sayyad on Transformerless Capacitor Dropper Power Supply

 Shani on Interfacing DC Motor with PIC Microcontroller using L293D

 Rendon Gree on Using UART on Raspberry Pi – Python

 Rendon Gree on Using UART on Raspberry Pi – Python

 B B DWIVEDI on What is a Microprocessor ?

FOLLOW US

   

© Copyright 2018. All Rights Reserved.

https://electrosome.com/dc-motors-arduino-ir-remote/ 12/12

You might also like