Project 05: Mood Cue

Arriving to this project means not only that you are starting to familiarize with Arduino, but also that you are determined to be able to create amazing things with it. So first of all, we would like to congratulate you.

Notwithstanding this, it is probably true to say that knowing how to switch on some LEDs won’t make the difference. But this is about to change. On this post we are going to explain how to get things into movement.

For this purpose, a servomotor is going to be used. As you may well know, it is a kind of motor which moves into a position and remains there if none new order is told. Also, it should be noted that a servo can just be turned 180 degrees.

To let the servo know which angle it should rotate we are going to make use of the same technique taken for PWM on the previous project. As you should remember, depending on the pulse width adjustment the information passed through the servo would be one or another. To this end, an analog input, a potentiometer is going to be used. In this way, when rotating the potentiometer, the servo will do as well.

We are also making use of two capacitors in order to mitigate the tension fall when moving the servomotor.

After understanding the main purpose of this project, the next step is to build it. To do that, the elements required are: a potentiometer, a servomotor, two capacitors and a few cables.

In order to make the connections properly the next image will help you.  Nevertheless, don’t forget the importance of comprehending each step you are taking. If you have any doubt, don’t hesitate to write a comment. Our team would be grateful to help you.

mood-cue

As it is shown in the previous picture, the potentiometer must be connected to an analog input as long as to the 5V entry and to the ground. Otherwise, the servo must be to a digital input as well as to the 5V and the GND. Make sure you connect the capacitors properly as they have polarity.

As always, we are including the code (containing some useful explanations) used to make this project. However, in this case, it doesn’t present any difference from the code proposed by the Arduino Starter Kit.

Before reading the code, note that a servomotor library is being used. After importing it, you can use all the functions that contains making the code much easier.

#include <Servo.h>// Importing the Servo lybrary
Servo MyServo;//Variable refering to the servo lybrary. It has all the function that the lybrary has.
int const PinPot=A0;//Connecting the potentiometer to an analog and creating the properly constant
int ValuePot;//Creating variable
int Angle;//Creating variable
void setup() {
 MyServo.attach(9);//Relating the servo to the pin 9
 Serial.begin(9600);//Initialting the serial port
}

void loop() {
 ValuePot=analogRead(PinPot);//Reading PinPot
 Serial.print("Potentiometer position:");//Showing the previous on the serial monitor
 Serial.print(ValuePot);
 Angle=map(ValuePot,0,1023,0,179);//Changing the scale values
 Serial.print(", Angle: ");
 Serial.print(Angle);
}

Apart from the specific functions from the imported library which are clarified in the code. Is to notice another new function: map(). Don’t forget to use it when changing a numeric scale.

To finish, just connect your Arduino Uno to electricity and move the potentiometer as it were a joystick. The result should be the following.

Thanks for reading and see you on the next post!

One thought on “Project 05: Mood Cue

  1. Whoever wrote the code missed the line to actually write the mapped values to the servo. You know, the part of the code that *actually does the thing you want to do.* You need to add:

    MyServo.write(Angle);

    after the Serial.print(Angle); line. To anyone who writes the above code and is disappointed that your servo doesn’t work, this is why.

    Like

Leave a comment