OVERVIEW
In this activity, you will control the servo motor provided along with the 321Maker shield.
OUTCOMES
By the end of this assignment you will be able to:
- Use Servo library to control micro servo.
- Control servo using input devices.
REQUIREMENTS
- Arduino-Compatible board
- 321Maker shield
- USB Cable
- Arduino Software
- SG90 9 g Micro Servo
- Account on a Git repository hosting service
BACKGROUND
"Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees.".
LEVEL 1: SETUP
- Create a new source code repository on your GitLab account. Use the starter code repository as your starting point.
- Open Visual Studio Code.
- Clone the repository into your local hard drive.
- Select file servoControl.ino.
- Connect your servo motor to the 321Maker shield as follows: Connect the devices as follows.
321Maker Servo GND ----------- GND
VCC ----------- VCC
D9 ----------- Pulse
- Connect the Arduino to your computer using the USB port.
- Make sure you select the correct Arduino board and communications port (don't forget to set bound rate).
- Make sure the code uses the correct pin, change it if necessary.
- Fix code so that it complies with servo specification:
- Verify that code compiles without error.
- Upload program to Arduino board.
- Congratulations, your should see the servo motor sweep side to side.
- Demo to your instructor
LEVEL 2: PROGRAM MODIFICATION
- Implement knob functionality using the 321Maker rotation sensor. You probably want to use the map function.
- Commit changes.
- Demo to your instructor
LEVEL 3: ADVANCED
- Add code so that servo also rotates depending on the button pressed. Button 1 should move the servo to the left (1 degree at a time). Button 2 should rotate the servo to the right (1 degree at a time).
- Commit changes.
- Demo to your instructor
- Change code so that it uses the buzzer to indicate that the servo has reached its maximum rotation angle.
- Commit changes
- Demo to your instructor
Attachment:- Visual Studio Code.rar