Arduino can easily control the DC servo motor and rotate it at an exact, required angle. The Arduino has analog output through which it generates PWM that is used to rotate servo motor at a specific angle. You can move the servo motor angle position using potentiometer or joystick or push buttons with the help or Arduino.
What if we want to control the servo motor using remote? Especially normal, readily available, hand held IR remote which we can find in all most all the homes for TV, AC, music systems, DVD or even for STB (set top box). Like, we can move the motor to specific angle like 30o, 60o, 90o etc or we can linearly increase or decrease motor angle using IR remote – any IR remote. Doesn’t this sound great?
The given project demonstrates how to move servo motor at specific angle using IR remote (like TV, DVD, AC, STB etc) with the help of Arduino. It also increases or decrease motor angle using remote and rotate motor CW and CCW. The project uses normal set top box (STB) IR remote, TSOP IR sensor and Arduino UNO board. Anyone can use any type of IR remote. Just he has to change the remote codes in the Arduino sketch (program) for the remote. This procedure is also described here while explaining the operation. So let us see how this is done.
First see the circuit diagram followed by its description and operation.
CIRCUIT DESCRIPTIONAs shown in figure, the circuit is built using 2 components only an Arduino board and IR sensor.
• The sensor TSOP1738 has 3 terminals (1) Vcc (2) Gnd and (3) output. Its Vcc terminal is given 5 V from board and Gnd terminal is connected to ground of board. Sensor output is connected digital input pin 12 of arduino board
• Analog output pin 5 is connected to servo motor signal input pin to drive the motor
• The servo motor is given external 5 V supply
Here is the snap of circuit arrangement.
Fig. 1: Prototype of Arduino and IR Remote based DC Servo Controller
CIRCUIT OPERATIONFirst we have to decide, which are the different buttons of IR remote, that we will use to rotate servo motor. We want to perform following actions – :
1. Rotate the motor to a specific angle like 30o, 60o, 90o, …. Like wise
2. Increase / decrease motor angle from 0o to 180o in steps of 5o
I have used set top box (STB) remote that has many buttons like 0-9 digit buttons, volume control buttons, channel up/down buttons, arrow key buttons etc. From all these buttons I have selected following 7 buttons for different operations.
That means when any digit button between 1 to 5 is pressed, the motor will move to that specific angle. And by pressing volume up/down button the motor angle can be precisely set in ±5o
After deciding the buttons, next is to decode the codes of these buttons. As we know when any button is pressed from remote, it will send one code and based on this code the action is performed. So to decode these codes I have used IRremote library for arduino, readily available on internet.
So download the library and use example to decode the codes of remote buttons. Upload the program into arduino micro controller and connect IR sensor as shown in figure. Now point the remote control towards IR sensor and press the button. Open serial monitor and you can observe the code of pressed button in form of numbers. Note down the codes of required buttons like I have noted the codes as per following table – :
In the arduino sketch above codes are used corresponding to button pressed to perform action as per previous table. Now let us see the actual operation.
• Motor is given supply from external 5 V and arduino board and IR sensor is given supply form USB. When power is applied the motor moves to 0o. The messages displayed on serial monitor as “IR remote controlled servo motor” and “servo motor angle 0 deg”
• Now as button 1 is pressed from remote motor will move to 30o and likewise when button 2, 3, 4 or 5 is pressed motor will move to the desire angle 60o, 90o, 120o or 150o. The serial monitor also displays servo motor angle position as “servo motor angle xx deg”
• When volume up button is pressed, the motor angle increased by 5o – means if it’s on 30o, it will move to 35o and likewise. The new angle position is displayed on serial monitor.
• Similarly when volume down button is pressed, the motor angle decreased by 5o – means if it’s on 90o, it will move to 85o and likewise. The new angle position is displayed on serial monitor.
Thus with the help of arduino, we can control the servo motor angle using IR remote and TSOP IR sensor.
Project Source Code####include <IRremote.h> // add IR remote library
#include <Servo.h> // add servo motor library
Servo servo1;
int IRpin = 12; // pin for the IR sensor
int motor_angle=0;
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600); // initialize serial communication
Serial.println("IR Remote controlled servo motor"); // display message
irrecv.enableIRIn(); // Start the receiver
servo1.attach(5); // declare servo motor pin
servo1.write(motor_angle); // move the motor to 0 deg
Serial.println("Servo motor angle 0 deg");
delay(2000);
}
void loop()
{
while(!(irrecv.decode(&results))); // wait until no button is pressed
if (irrecv.decode(&results)) // when button is pressed and code is received
{
if(results.value==2210) // check if digit 1 button is pressed
{
Serial.println("servo motor angle 30 deg");
motor_angle = 30;
servo1.write(motor_angle); // move the motor to 30 deg
}
else if(results.value==6308) // if digit 2 button is pressed
{
Serial.println("servo motor angle 60 deg");
motor_angle = 60;
servo1.write(motor_angle); // move the motor to 60 deg
}
else if(results.value==2215) // like wise for all digit buttons
{
Serial.println("servo motor angle 90 deg");
motor_angle = 90;
servo1.write(motor_angle);
}
else if(results.value==6312)
{
Serial.println("servo motor angle 120 deg");
motor_angle = 120;
servo1.write(motor_angle);
}
else if(results.value==2219)
{
Serial.println("servo motor angle 150 deg");
motor_angle = 150;
servo1.write(motor_angle);
}
else if(results.value==6338) // if volume UP button is pressed
{
if(motor_angle<150) motor_angle+=5; // increase motor angle
Serial.print("Motor angle is ");
Serial.println(motor_angle);
servo1.write(motor_angle); // and move the motor to that angle
}
else if(results.value==6292) // if volume down button is pressed
{
if(motor_angle>0) motor_angle-=5; // decrease motor angle
Serial.print("Motor angle is ");
Serial.println(motor_angle);
servo1.write(motor_angle); // and move the motor to that angle
}
delay(200); // wait for 0.2 sec
irrecv.resume(); // again be ready to receive next code
}
}
###
Circuit DiagramsCircuit-Diagram-Arduino-IR-Remote-Based-DC-Servo-Controller
Project Video
Comments
Please log in or sign up to comment.