Controlling a servo using a potentiometer via Intel Galileo and showing the rotation angle of the servo shaft on the Arduino Terminal.

Introduction: A Servo Motor is a type of DC motor that, via PWM (Pulse-Width Modulation), rotates with very high precision. An electronic control board connected to a sensor tracks the gears inside the Servo enclosure, decoding the rotations of these gears in a way that makes possible to the user control how much the servo shaft will move.

Servo Gears Servo Gears

Components needed:

→ One Servo Motor;

→ One 10k Ohm Linear Potentiometer;

→ Protoboard;

→ Jumpers.

1st Step:

On a Protoboard, assemble the circuit below:

Proto1

Where:

→ Red wires and black wires referes to VCC 5V and GND, respectively;

→ The Yellow wire are the PWM Servo signal;

→ The Orange Wire leads the voltage through the potentiometer resistance to be read by ADC 0.

Schematic

Schem1

2nd Step:

Upload the following code to Galileo, using the Arduino IDE or compiling directly from Linux terminal:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
    include "Servo.h"
    const int pinServo = 3; // Servo Pin
    Servo testServo; //Creating testServo object
    int eixo;
       
    void setup() {
        testServo.attach(pinServo); //Servo is connected to D3
        pinMode(potentiometer, INPUT);
        Serial.begin(9600);
              }
    void loop () {
      eixo = analogRead(potentiometer);
      eixo = map(eixo, 0, 1023, 0, 179); /*The span of the analog input is 1~1023, but the servo only sends 1~179 */
      testServo.write(eixo);
      Serial.println(eixo);
      delay(15);
      }
     

3rd step:

With the code running on Galileo, open “Serial Monitor” and turn the potentiometer to both sides.

Schem1