Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Project 5

Assignment:01
01.Mood Cue.

 Circuit (Mood Cue):

 Code:

#include <Servo.h>

Servo myServo;

0
int const potPin = A0;

int potVal;

int angle = 0;

void setup()

myServo.attach(9);

Serial.begin(9600);

void loop()

potVal = analogRead(potPin);

angle = map(potVal,0,1023,0,179);

Serial.print("potVal: ");

Serial.print(potVal);

Serial.print(" angle: ");

Serial.println(angle);

myServo.write(angle);

1
delay(15);

 Summary

Attach 5V and ground to one side of your breadboard from the Arduino. Place a
potentiometer on the breadboard, and connect one side to 5V, and the other to
ground. A potentiometer is a type of voltage divider. As you turn the knob, you
change the ratio of the voltage between the middle pin and power. You can read
this change on an analog input. Connect the middle pin to analog pin 0. This will
control the position of your servo motor. The servo has three wires coming out of
it. One is power (red), one is ground (black or brown), and the third (white or
orange or yellow) is the control line that will receive information from the Arduino.
Plug three male headers into the female ends of the servo wires.
Connect the headers to your breadboard so that each pin is in a different row.
Connect 5V to the red wire, ground to the black wire, and the white wire to pin 9.
When a servo motor starts to move, it draws more current than if it were already
in motion. This will cause a dip in the voltage on your board. By placing a 100 uf
capacitor across power and ground right next to the male headers, you can
smooth out any voltage changes that may occur. You can also place a capacitor
across the power and ground going into your potentiometer. These are called
decoupling capacitors because they reduce, or decouple, changes caused by the
components from the rest of the circuit. Be very careful to make sure you are
connecting the cathode to ground (that is the side with a black stripe down the
side) and the anode to power. If you put the capacitors in backwards, they can
explode. Your servo motor comes with female connectors, so you need to add
header pins to connect it to the breadboard.

You might also like