Tab Content
Tab Title
Instructions
Tab Content

Instructions

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

By typing “myservo.attach(9);”, you are telling the Arduino board to send a signal  (to the Servos) from pin 9.

You are using pin 9 because it is a pin that can send signals through electric current using a technique known as pulse width modulation, or PWM . Only pins with a tilde symbol (~) can send signals using PWM. It is necessary to use a PWM pin, like pin 9, to control Sservos.

Be sure that you are typing this line of code inside of the curly brackets for the setup function.

Remember, code that is written inside the void setup curly brackets runs just once at the beginning of the program. So, you are adding the “attach” function to the setup section of the code because pin 9 only needs to be set up once.

Notice the ''//'' before the gray text. As we saw in the LED Blink Activity, these are comments meant for humans and do not change the program.

Tab Title
Troubleshooting
Tab Content

‘attach’ didn’t turn orange

  1. Check the spelling of the word “attach” and make sure that no letters are capitalized.
Tab Title
Implementation
Tab Content

1. We know the Servo is controlled by a certain shaped signal, but which pins on the Arduino are physically capable of generating the PWM signal?

Ask the students: Which numbers on the digital side have a squiggly line?
Answer: 3, 5, 6, 9, 10, 11 1.2.

2.The squiggly line indicates that those pins are capable of creating a PWM signal.

3. In the void setup (), we will associate one of those pins to control the Servo. We happen to choose 9 in this activity. Since there are 6 PWM pins, we could potentially control up to 6 Servos at the same time using one Arduino.

4. We can think of the PWM pins as bilingual. All of the digital pins speak the language called digital, where we have 2 choices: on or off, yes or no, 0 or 1. But the PWM pins speak a language called analog, where we can have many choices, or a range of values. Think of a digital signal like a light switch, the light is either on or off. Analog is like a light dimmer. The lights can be very bright, not as bright, just a little light, or off. You may see these at a movie theater.

5. If your students are working in pairs, after they finish this line of code is a good time to have them switch, so the person who was typing is now checking and the person who was checking is now typing.

Instruction Category