Controlling Servo Motor (Setting Angle) using Arduino IDE

About This Tutorial
In this tutorial, we will control Servo Angle connected to evive and Arduino using Arduino IDE functions.
Tutorial Info
Programming Platform:
Difficulty:
Estimated Time (hrs):
1

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1
Micro Servo Motor with Accessories1

Introduction

A servo motor is a rotary actuator that allows for precise control of angular position.  It consists of a suitable motor coupled to a sensor for position feedback.

Metal Servo motor

Controlling Servo Angle

Servo is controlled on the concept of PWM (Pulse Width Modulation). The refresh interval (the minimum time to refresh servos in microseconds) is 20000, which means that the servo is refreshing at a frequency of 50Hz. For most of the servos, a certain range of PWM correspond to the range of angle servo can rotate. Minimum pulse width is the shortest time for the pulse has been HIGH and maximum pulse width is the longest time for which the pulse is HIGH. Hence if the range of motor angular position is from 0 to 180, then minimum pulse width corresponds to 0 and maximum pulse width corresponds to 180.

Controlling Servo using evive and Arduino IDE

evive has two dedicated servo motor outputs pins.

Signal pin of servo 1 is connected to digital pin 44 and servo 2 is connected to digital pin 45.

evive servo output channel

Circuit Diagram

In the following example, I will be showing you how to control servo through channel 1. Given below is the circuit diagram:

A Servo pin has three wires (Order to be connected in evive, left to right)

  • Brown wire: GND
  • Red wire: VCC
  • Orange wire: Signal
Caution: Power evive using a 12V 2A power adapter for smooth functioning of servo motor. The VVR (Variable voltage) should be close to 6V.

Code for setting servo angle

There is a servo library which can be used to control the servo motor. The available functions are provided in the table below:

 

FunctionReturn data typeComment
attach(int pin);unit8_tAttach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
attach(int pin, int min, int max);unit8_tAs above but also sets min and max values for writes
detach();void
write(int value);voidIf value is < 200 its treated as an angle, otherwise as pulse width in microseconds
writeMicroseconds(int value);voidWrite pulse width in microseconds
read();IntegerReturns current pulse width as an angle between 0 and 180 degrees
readMicroseconds();IntegerReturns current pulse width in microseconds for this servo (was read_us() in first release)
attached();boolReturn true if this servo is attached, otherwise false

In this example we will  attach a servo motor and set the angle of the servo to 90 degrees.

[pastacode lang=”c” manual=”%2F*%0A%20*%20Setting%20Servo%20Angle%0A%20*%20%0A%20*%20Made%20by%20Pankaj%20Verma%0A%20*%2F%0A%20%0A%23include%20%3Cservo.h%3E%0A%0AServo%20servo_44%3B%0A%0Avoid%20setup()%7B%0A%20servo_44.attach(44)%3B%20%2F%2F%20init%20pin%0A%20servo_44.write(90)%3B%20%2F%2F%20write%20to%20servo%0A%7D%0A%0Avoid%20loop()%7B%0A%7D” message=”” highlight=”” provider=”manual”/]

Controlling Servo using Arduino Uno

Arduino uno has 6 PWM pins: 3, 5, 6, 9, 10, and 11 which provide 8-bit PWM output with the analogWrite() function.

We will controlling serov using Pin 3.

Circuit Diagram

A Servo pin has three wires (Order to be connected in evive, left to right)

  • Brown wire: GND
  • Red wire: VCC
  • Orange wire: Signal

Servo Angle

Caution: Power servos using a 6V 2A power adapter for smooth functioning of servo motor.

Code for setting servo angle

[pastacode lang=”c” manual=”%2F*%0A%20*%20Setting%20Servo%20Angle%0A%20*%20%0A%20*%20Made%20by%20Pankaj%20Verma%0A%20*%2F%0A%20%0A%23include%20%3Cservo.h%3E%0A%0AServo%20servo_3%3B%0A%0Avoid%20setup()%7B%0A%20servo_3.attach(3)%3B%20%2F%2F%20init%20pin%0A%20servo_3.write(90)%3B%20%2F%2F%20write%20to%20servo%0A%7D%0A%0Avoid%20loop()%7B%0A%7D” message=”” highlight=”” provider=”manual”/]

This Helped
This didn't help
Share this Tutorial
Facebook
Twitter
Google+
Pinterest
Reddit
Print
Related Tutorials
Featured Projects
Unique-Christmas-Tree

DIY Unique Christmas Tree

This project will show you how to make a unique DIY Christmas Tree for this year’s Christmas.

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart