Tab Content
Tab Title
Instructions
Tab Content
  1. Type "standardServo.attach(9);" between the curly brackets ({ and }) of the setup function.
     
  2. Press enter to add another line.
     
  3. Type "continuousServo.attach(10);".
     
  4. Observe the Arduino board and notice the tilde symbol (~) before pins 9 and 10, as well as other pins.

 

STEM Connections

When programming one Servo, pin 9 was used to control it. Now that 2 Servos are being used, two pins will be required to control them. For example, pins 9 and 10 can be used. Other pins will also work but remember that only those with a tilde symbol (~) should be selected, as the PWM signal is needed to control the Servos.

Be sure to type both lines of code inside 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, the “attach” functions are being added to the setup section of the code because pins 9 and 10 only need to be set up once.

Notice the ''//'' before the gray text. As we saw in previous activities, these are comments or notes for programmers and do not change the program. 

Tab Title
Implementation
Tab Content

At the Thinkabit lab, we explain how pins work and ensure that each student has an opportunity to both write code and check the code.

  • Remind students that the Servo is controlled by a certain shaped signal but only certain pins on the Arduino are physically capable of generating the PWM signal.
  • Ask students to identify which numbers on the digital side can generate the signal. Hint: these all have a squiggly line next to them.
    Students should answer: 3, 5, 6, 9, 10, 11.
  • Explain that the squiggly line indicates that those pins can create a PWM signal.
  • Explain that in the void setup (), one of the pins (listed above) will be assigned to control the Servo. Since there are 6 PWM pins, we could potentially control up to 6 Servos at the same time using one Arduino Uno.
  • Explain the following analogy. The PWM pins can be thought of as bilingual. All the digital pins speak the language called digital, where there are 2 choices: on or off, yes or no, 0 or 1. The PWM pins, however, speak a language called analog, where there are many choices, or a range of values. The digital signal is like a light switch; the light is either on or off. Analog is like a light dimmer. The lights can be very bright, less bright, barely lit, or off. 

Before transitioning to the next activity, ask students to switch roles, so that each student has an opportunity to both write code and check the code.

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.
  2. If it changed colors to a different color, the Arduino software may have been updated.  As long as it is colored, the code should still work properly.
Instruction Category
Video