Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Controlling Servo Motor using Freeduino

By Sajid Shaikh September 27, 2021

 

Servo is a special type of motor which converts electric signals in to shaft positions.

Servos can be broadly classified as Industrial servos and Hobby grade servos.

Industrial servos are generally heavy duty high power AC or DC servos widely used for precise robotic arms.

Hobby grade servos are widely used in RC Hobbies like RC Plane, Cars Helicopters, Multirotors, Boats, hover craft, etc.

They are mostly used to control the control surfaces (RC Planes) or for thrust vectoring mechanisms (hovercraft, boats, multirotors) or for steering mechanisms (RC Cars).

Hobby grade servos are further classified as micro, standard, giant based on the torque they can provide, however their working principal is just the same.Based on speed of operation they are classified as Analog or Digital servos, Digital servos provide greater speed but consume more power.

Speed of a servo motor is defined as time taken for shaft to move from 00 to 600 after the application of signal.

In this article we will be using an ARDUINO clone board viz. FREEDUINO.
The freeduino board used is based on arduino duemilanove board and uses atmega 328PA Microcontroller IC.

Most salient feature of an arduino platform is its ease of use, since arduino was designed for artists instead of engineers it becomes more interesting and fun to learn arduino programming and make projects based on it.

Freeduino Board:

 

Freeduino Board

 Description

Description:

         Servo is most widely used actuator in project like robotic arms, RC plane, self balancer, etc.

        It uses a negative feedback mechanism to maintain its shaft position with minimum error.

        The servo motor has three wires unlike normal PMDC motors which have two wires.

        Among those 3 wires, 2 wires provide power supply to the motor and one is used to send signals to the motor for required shaft positions.

        These signals are PWM signal of varying duty cycle and frequency of 40-50HZ (analog servos) or 400-500Hz (digital servos).

        Analog servos are cheaper and consume less power and Digital servos provide relatively high torque and speed and are normally used as   Helicopter Tail servo.

        Shaft is rotated by an angle depending on the ON-Time of the pulse.

         1ms = 00

        1.5ms=  900

         2ms=     1800

Input (ADC):

Arduino has a inbuilt 10-bit Analog to Digital converter(ADC), hence it can provide Digital values from 0-1023.(since 2^10=1024)

We can also set the ADC reference voltage in arduino, but here we’ll let it use default value.

Variable resistor (preset or potentiometer) has three pins; outer two pins are connected to ground and Vcc.

This forms a potential divider and we get the voltage (Vout) corresponding to the knob of resistor.
Analog to Digital Converter

As we rotate the knob of variable resistor the voltage at middle pin goes from 0-5V and ADC of arduino converts it into 1024 values i.e. 0-1023 digital values.

Now we will be using these 1024 values to control our servo motor.

 

Output (PWM): 

To drive a servo we need to get a PWM signal from the board, this is usually accomplished using timer function of the microcontroller but arduino makes it very easy.

Arduino provides a servo library in which we have to only assign servo angle and the servo rotates by that angle, all the PWM calculations are handled by the servo library and we get a neat PWM signal according to the desired angle.

Arduino has a 8-bit PWM generator, so we can get up to 256 distinct PWM signal

We need 0-180 degrees of servo rotation.

Now since we are getting 1024 values from ADC which we have to use to rotate servo shaft by 0-180 degrees, we will use a function called mapping to map these 1024 distinct values to 180 values.

Map function has a syntax: map(mapping_values,(range of values),(range in to which it has to be mapped)

Example: In our case the map function will look like angle=map(pot_value,0,1023,0,180);
if you want to change the direction of servo angle with respect to potentiometer knob, change the wiring or write mapping function as, angle=map(pot_values,0,1023,180,0);

Now, as we change the variable resistor the voltage at ADC input will go from 0 to 5V(analog), 0-1023(digital) and then it’ll be mapped to  0-180(servo angle).
Potentiometer is a simplest device to understand analog device functioning, after getting well acquainted with it we can use other analog devices like LDR, infrared distance sensors, temperature sensors, accelerometers as our input device and make other cool projects like self balancing robot, line follower, obstacle avoider, solar tracker, etc.

 Components and Circuit

Components:

Freeduino board (Atmega 328)

Features:

Microcontroller

ATmega328

Operating Voltage

5V

Input Voltage (recommended)

7-12V

Input Voltage (limits)

6-20V

Digital I/O Pins

14 (of which 6 provide PWM output)

Analog Input Pins

6

DC Current per I/O Pin

40 mA

DC Current for 3.3V Pin

50 mA

Flash Memory

32 KB (ATmega328) of which 0.5 KB used by bootloader

SRAM

2 KB (ATmega328)

EEPROM

1 KB (ATmega328)

Clock Speed

16 MHz

Servo: Tower pro 9G Micro-servo.

Potentiometer: 10K variable resistor (preset or pot)

CIRCUIT

Freeduino Pinout

Servo Control using Arduino

 Images

IMAGES:

Controlling Servo Motor using Freeduino

Breadboard with variable resistor

Controlling Servo Motor using Freeduino

Breadboard and servo motor

Controlling Servo Motor using Freeduino

Arduino based Circuit

 Video

 

 

 

You may also like:


  • What are different types of industrial robots?

  • What types of motors are used in electric vehicles?

  • What is Wireless Electric Vehicle Charging System (WEVCS)?

  • What is the role of embedded software in electric vehicles?

  • What drone parts you need to build a quadcopter?

  • What’s a protective relay and what does it protect?

Project Source Code

###


#include                        //include servo library to control servos

 

Servo sajidservo;                           //define your servo    

int pot=0;                                                   //potentiometer connected at pin no 0 of ADC 

 

void setup()

{

  sajidservo.attach(9);                    //attach your servo to a PWM pin(here pin no.9)

  Serial.begin(9600);         //exclude this if you don't want to see ADC values on serial monitor

}

void loop()

{

  int val=analogRead(pot);                  // Read values from ADC and save it in variable val

  int pos=map(val,0,1023,0,180);        // map the range of ADC with pwm

  sajidservo.write(pos);                                    // write to the servo

  Serial.println(val);                                         //exclude if don't want to see ADC values

 

}

###

 



Filed Under: Electronic Projects
Tagged With: adruino, motor, servo motor
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Redundant XORs
  • No Output Voltage from Voltage Doubler Circuit in Ansys Nexxim (Harmonic Balance Simulation)
  • Discrete IrDA receiver circuit
  • ISL8117 buck converter blowing up
  • I²C Ground Isolation with Series Battery Cells (ULIN13-01 + PIC18LF4520)

RSS Electro-Tech-Online.com Discussions

  • Help with finding unique wire lug(s)
  • Simple LED Analog Clock Idea
  • Kawai KDP 80 Electronic Piano Dead
  • Saga 1400sv vinyl cutter motherboard issue
  • using a RTC in SF basic

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe