Controlling DC Motors Using Arduino and IR Remote
Controlling DC Motors Using Arduino and IR Remote
Controlling DC Motors Using Arduino and IR Remote
HOME / PROJECTS, EMBEDDED, ARDUINO / CONTROLLING DC MOTORS USING ARDUINO AND IR REMOTE
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
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.
dusuniot.com OPEN
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.
Program Code
https://electrosome.com/dc-motors-arduino-ir-remote/ 2/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote
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();
}
}
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
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.
In the next section we are de ning all digital input output pins of Arduino which are used in this project.
After that we are we are initializing the IR library and digital pins.
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
Video
https://electrosome.com/dc-motors-arduino-ir-remote/ 6/12
12/13/2019 Controlling DC Motors using Arduino and IR Remote
dusuniot.com OPEN
Related Posts:
Home Automation
Arduino Weather Calculator using using Arduino and
Station Web Server Arduino Uno ESP8266 Module
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
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
RECENT POSTS
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
What is a Microprocessor ?
by Ligo George
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
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
FOLLOW US
https://electrosome.com/dc-motors-arduino-ir-remote/ 12/12