Servo Sweep using Arduino IDE

About This Tutorial
In this tutorial we will sweeps the shaft of a RC servo motor back and forth across 180 degrees using Arduino IDE.
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

In this tutorial we will sweeps the shaft of a RC servo motor back and forth across 180 degrees.

Servo Sweep using evive and Arduino IDE

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.

Logic Diagram

Angle at the start of the program should be 0 degrees. Then it should increase until it reasches 180 degree angle, then it should decrease until it reaches 0 degree angle.

Code

[pastacode lang=”c” manual=”%23include%20%3Cservo.h%3E%0A%0Adouble%20Angle%3B%0AServo%20servo_44%3B%0A%0Avoid%20setup()%7B%0A%20Angle%20%3D%200%3B%0A%20servo_44.attach(44)%3B%20%2F%2F%20init%20pin%0A%7D%0A%0Avoid%20loop()%7B%0A%20while(!(((Angle)%3D%3D(180))))%0A%20%7B%0A%20Angle%20%2B%3D%205%3B%0A%20servo_44.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%20%7D%0A%20while(!(((Angle)%3D%3D(0))))%0A%20%7B%0A%20Angle%20%2B%3D%20-5%3B%0A%20servo_44.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%20%7D%0A%7D” message=”” highlight=”” provider=”manual”/]

Servo Sweep 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

[pastacode lang=”c” manual=”%23include%20%3Cservo.h%3E%0A%0Adouble%20Angle%3B%0AServo%20servo_3%3B%0A%0Avoid%20setup()%7B%0A%20Angle%20%3D%200%3B%0A%20servo_3.attach(3)%3B%20%2F%2F%20init%20pin%0A%20servo_3.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%7D%0A%0Avoid%20loop()%7B%0A%20while(!(((Angle)%3D%3D(180))))%0A%20%7B%0A%20Angle%20%2B%3D%205%3B%0A%20servo_3.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%20delay(20)%3B%0A%20%7D%0A%20while(!(((Angle)%3D%3D(0))))%0A%20%7B%0A%20Angle%20%2B%3D%20-5%3B%0A%20servo_3.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%20delay(20)%3B%0A%20%7D%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