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.

Explore the Servos

  1. Warning: Do not turn the Servos by hand. Doing so can damage mechanisms inside the Servos.
  2. Refer to the video and notice how the movements of these two Servos differ.

STEM Connections

Try New Things

  1. Change the Blink code so that the LED blinks so fast that you cannot see it blinking. How many blinks per second can your eyes register?
  2. Change the Blink code so that the LED blinks “SOS” in Morse code. SOS is the international symbol for help. The SOS pattern is three short blinks followed by three longer blinks followed by three short blinks.

Upload and Test the Code

  1. Press the upload button to upload your revised Blink program to the Arduino board.
  2. Notice the LED is blinking faster.

STEM Connections

When you change the Blink code, you need to press the upload button in the Arduino software for it to translate that revised code into a new program and send that program to the Arduino board. Any changes to the code need to be uploaded to the Arduino board. Every time the upload button is pressed it translates the code in the computer window into a program again and sends that program to the Arduino board.

Pages

Subscribe to Thinkabit Lab RSS