This is my first individual project using Arduino. This project illustrates the rotation of a servo motor using IR Remote Control. We can make the servo motor rotate both clockwise and anticlockwise.
1: Schematic Diagram:
The ground and VCC pin of the Arduino and bread board are connected using jumper wires. The ground and VCC of IR Receiver are connected to bread board using the same technique. The signal pin of IR Receiver is connected to 3rd digital pin of Arduino using a jumper wire
The ground and VCC of servo motor are connected to breadboard. Connect the signal pin of the servo motor to 9th digital pin of Arduino.
1 ) Initially the IR Arduino Library is installed
Link : http://surl.li/euffi
Paste the above folder in Documents -----> Arduino ----> Libraries
2) Select the IRrevDemo example
3) Value of REC_PIN is changed to 2
After uploading the code choose serial monitor and press the + button and - button inside the remote
The HEX Codes are visible inside the serial code
+ --------> FB54EA5B
- ---------> 3E3D6F9
4) Copy the code and the changes are made in + and - accordingly
#include <IRremote.h> //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0xFB54EA5B //clockwise rotation button
#define minus 0x3E3D6F9 //counter clockwise rotation button
int RECV_PIN = 2; //IR receiver pin
Servo servo;
int val; //rotation angle
bool cwRotation, ccwRotation; //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
servo.attach(9); //servo pin
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
if (results.value == plus)
{
cwRotation = !cwRotation; //toggle the rotation value
ccwRotation = false; //no rotation in this direction
}
if (results.value == minus)
{
ccwRotation = !ccwRotation; //toggle the rotation value
cwRotation = false; //no rotation in this direction
}
}
if (cwRotation && (val != 175)) {
val++; //for colockwise button
}
if (ccwRotation && (val != 0)) {
val--; //for counter colockwise button
}
servo.write(val);
delay(20); //General speed
}
Video Link:
https://drive.google.com/file/d/1NeDfLwOMuY9-R0eyRrl-SZo8WXfudYcm/view?usp=share_link
Comments
Please log in or sign up to comment.