Connect All the Wires to the Servo

  1. Warning: Double check to make sure your wires are in the right place, as placing the wires incorrectly may cause the Servo to break.

  2. Insert the white wire into the white wire socket of the standard Servo.

  3. Insert the red wire into the red wire socket of the standard Servo.

  4. Insert the black wire into the black wire socket of the standard Servo.

Upload the Code to the Arduino board

  1. Press the upload button (arrow) to upload your Servo program to the Arduino board.

STEM Connections

The upload button translates the code you wrote into a program and sends that program to the Arduino board. Immediately after the Arduino board receives this program it begins running it. Once the Servo is properly connected to the Arduino board, you will see the program’s effect on the Servo.

Write Code For a 2 Second Delay

  1. Type: “delay(2000);” after “myservo.write(180);” and before the last curly bracket.

STEM Connections

This delay function will cause the program to pause and not read the next line for 2000 milliseconds (or 2 seconds).  Meanwhile, the Servo has been instructed to move to 180 degrees, which it will do and then remain there until it receives another command.

Write Code to Make the Servo Move the Other Way

  1. Type: “myservo.write(180);” after “delay(2000);”

STEM Connections

Remember, the write function determines the angle to which a standard Servo moves. So, the line of code “myservo.write(180);” tells the standard Servo to move to 180 degrees.

Before the Arduino board runs this line of code, the Servo was at angle 0. When the Arduino board runs this line of code, it will cause the standard Servo to rotate to the right from 0 degrees to 180 degrees.

Write Code for a Two Second Delay

  1. Type: “delay(2000);” after “myservo.write(0);” and before the last curly bracket.

STEM Connections

This delay function will cause the program to pause and not read the next line for 2000 milliseconds (or 2 seconds). Meanwhile, the Servo has been instructed to move to 0 degrees, which it will do and then remain there until it receives another command.

Write Code to Make the Servo Move

  1. Type “myservo.write(0);” between the curly brackets ({ and }) of the loop function.

STEM Connections

You will soon build a circuit using a standard Servo. Remember, a standard Servo can move to any angle in a half circle (from 0 to 180 degrees) and remain there until instructed to move again. Standard Servos are very helpful if you want a mechanism that moves to specific angles.

Assign a Pin to Control the Servo

  1. Type “myservo.attach(9);” between the curly brackets ({ and }) of the setup function.

  2. Observe the Arduino board and notice the tilde symbol (~) before pin 9 and other pins.

STEM Connections

There are two types of pins in the digital row of the Arduino Uno Board: Pins with a tilde symbol (~) that can send signals through electric current using a technique known as pulse width modulation, or PWM.  The other pins (1, 2, 4, 7, 8, 12 & 13) cannot.

Connect the Arduino board and open a programming window

  1. Plug the USB cable into both the Arduino board and the computer.
  2. Open the Arduino software on the computer.

  3. Maximize the Arduino software window.

  4. In the menu bar, go to Tools>Port> and the click COM# with “Arduino/Genuino Uno” next to it.

STEM Connections

Unlike the LED Blink activity where existing code was modified to make the LED blink in different ways, this activity will require you to write code from start to finish. The first step in writing new code is to open a new programming window.

Pages

Subscribe to Thinkabit Lab RSS