Sponsor Detail
0
Hackster
2019-11-17
Follow

Servo Motor Control with Remote

1553
Views
0
Comments
0
Likes
50
Followers


With this simple Arduino project you can control servo using a remote control. All you need is an Arduino Uno board (or similar), a servo motor (doesn't have to be very powerful), a TV remote, IR receiver (TS0P1738) and a small piece of cardboard.


Let's get started!

Installing the IR Library:

The very first thing that we need to do associating with arduino is to download the IR library.

Download IR library from below link and install it: https://github.com/z3t0/Arduino-IRremote

If you don't know how to install a library follow below link: https://www.arduino.cc/en/guide/libraries

Decoding IR Signals:

First you need to connect the parts as per the given circuit diagram:

You can checkout Pin out of TSOP1738 below:


Use following code to decode IR remote:

/*The IR sensor's pins are attached to Arduino as so:Pin 1 to Vout (pin 11 on Arduino)Pin 2 to GNDPin 3 to Vcc (+5v from Arduino)*/#include <IRremote.h>int IRpin = 11;IRrecv irrecv(IRpin);decode_results results;void setup(){Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver}void loop() { if (irrecv.decode(&results))    {     Serial.println(results.value, DEC); // Print the Serial 'results.value'     irrecv.resume();   // Receive the next value   }}


  • Open Arduino IDE and Upload code
  • Open Serial Monitor
  • Aim your remote at the sensor and press each button
  • You can see different numbers for each button

Consider any two buttons, and note down decoded values.In my case I have chosen Power button and Mode button.

I got the following values:

  • Power button=33441975
  • Mode button =33446055

We will be using this two values to control rotation of servo motor.you need to add this two values in the program which is given on next step:

Let's set-up the final hardware!


The Final Circuit!

Connect the servo's signal pin to pin#9 on the arduino

connect the servo's VCC and GND pins to 5V VCC and GND on the arduino

The servo will be glued to one end of the plastic bottle, and rotate a piece of cardboard small enough to close the opening of the bottle so that the food is blocked.

If all the hardware set-up is connected properly, you can simply compile and upload the following sketch to the board.

#include <IRremote.h>#include <Servo.h>int IRpin = 11;  // pin for the IR sensorIRrecv irrecv(IRpin);decode_results results;Servo myservo;void setup(){ Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver myservo.attach(9);  // attaches the servo on pin 9 to the servo object}void loop() {
if (irrecv.decode(&results))    {     irrecv.resume();   // Receive the next value   }  if (results.value == 33441975)  // change according to your IR remote button number    {      myservo.write(0);      delay(15);    }    if (results.value == 33446055)  // change according  to your IR remote button number    {      myservo.write(30);    delay(15);    }}


Schematics



Code:-

#include <IRremote.h>
#include <Servo.h>
int IRpin = 11;  // pin for the IR sensor
IRrecv irrecv(IRpin);
decode_results results;
Servo myservo;
void setup()
{
 Serial.begin(9600);
 irrecv.enableIRIn(); // Start the receiver
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
void loop() 
{
 if (irrecv.decode(&results)) 
   {
     irrecv.resume();   // Receive the next value
   }
  if (results.value == 33441975)  // change according to your IR remote button number
    {
      myservo.write(0);
      delay(15);
    }
    if (results.value == 33446055)  // change according  to your IR remote button number
    {
      myservo.write(30);
    delay(15);
    }
    
}     


End


THANKS PCBWAY 👍





PLEASE SUBSCRIBE MY CHANNEL FRIENDS


  • Servo

You might like

  • QUTRC Perseus Rover Project

    Seybold
    1267
  • Formula Student Racecar "FAUMax Pi"

    Engineer
    1281
  • University of Toronto Formula Racing Team

    Engineer
    763
  • Formula Student FCT (FSFCT) - The Project's Rebirth

    Team Leader
    596
  1. Comments(0)
  2. Likes(0)

Content