Arduino Mood Cue (Starter Kit Project #5)

Here, we will turn a potentiometer to consequently rotate a simple servo meter. The arduino will collect the data a

Setup

Here are the components we need:

  • Arduino UNO + Breadboard
  • 2 100 μF Capacitors
  • Jumper wires/cables
  • Potentiometer
  • Servo Motor (with arm)

Layout

Here’s what it should look like, as per the Arduino projects book.

And here is my build:

You might notice that there are some differences between the schematic and what I’ve made. Firstly, the potentiometer is just too large to be placed on the same strip as a capacitor and power/ground connections, which is why I have used orange jumpers to elongate the entire setup. Also note that the capacitors, if connected incorrectly, could potentially explode. I would google up how to connect these and then proceed! It took me a lot of time to find out which pin is the anode and which pin is the cathode. Turns out the pin which has a grey arrow full of zeros pointing downwards is the negatively charged electrode, or the cathode.

Code

You can find the full code here.

#include <Servo.h>
Servo myServo;

To start, we import the library required to interact with the servo motor, and create an instance of the Servo object to handle our motor. Then, all we need is 4 lines of functional code.

void loop() {
    potVal = analogRead(potPin);
    angle = map(potVal, 0, 1023, 0, 179);
    myServo.write(angle);
    delay(15);
}

Firstly, we read our analogue potentiometer value and convert it into an angle for rotating our servo motor. Then, using the servo library, we turn our motor. The delay of 15 milliseconds is to accomodate the time used up in rotating the motor.

Demo