Servomotor control using Ir sensor

Servomotor control using Ir sensor 

To in this blog I will be explain How to control Micro Servo motor using IR sensor and Arduino Uno R3











So, if you want to learn about this small project please stay this page.


Components required

1. Arduino Uno 

2. Microservo motor 

3. Ir sensor 

4.  Jumper wire Male to male and Male to female 

5. Breadboard 

6. 5Vdc power source 


Microservo motor SG90 

Microservo motor is a lightweight and small type of servo motor with high output power. 

which is use many types of engineering project and robotics. Servomotor can be control  using any servo code or servo library. 

It is most advanced type of small motors






Features of the microserv motor sg90

Dimension - 22.2 x 11.8 x 31 mm

Weight - 9g.

Stall torque - 1.8kgf.cm

Operating voltage - 3.7Vdc to 5Vdc

Operating speed - 0.12 s/60º

Temperature range - 20ºC to 60ºC 


Generally it has three wire 150mm length with female connector. 

Red, brown and yellow  

Red wire for Vcc 

Brown wire for GND

and yellow wire for PWM Signal wire which take analog output


Circuit diagram







In this project Sevo motor rotot 180 Degree 

When any object present in front of the IR sensor and if object remove in front of th ir sensor than the motor rotot 0 degree. According to the program. 


Source code for this project 


// Rajeev Kashyap

#include <Servo.h>

Servo Servo;

int ir_sensor = 4;

int servo_motor =5;

int val; 

void setup()

  {   pinMode(ir_sensor,INPUT); 

      Servo.attach(servo_motor); 

          } 

void loop()


{  val = digitalRead(ir_sensor);  

  if (val==0) 

      { Servo.write(0);       }  

  if (val==1) 

      { Servo.write(180);     } 

}



According to above program Input of the ir_sensor connect to Arduino pin No 4 and signal pin of the servo motor connect to Arduino pin No 5 PWM pin

If you want to change the rotation angle of servo motor than change here. 




Watch the video for see it's  working please visit our YouTube channel for more Arduino  and electrical engineering projects 

https://youtu.be/gzJLY55oEhs





Previous Post Next Post