2.3.9: Servo with Potentiometer 11/28
- Due Nov 28, 2022 by 11:59pm
- Points 100
- Submitting a text entry box
Write a program that will solve the following task:
- The servo motor should be set to position 0 anytime the button is pressed.
- If the potentiometer reads a value below 200, the servo motor should be set to a position of 0.
- If the potentiometer reads a value from 200 to 400, the servo motor should be set to a position of 45.
- If the potentiometer reads a value from 400 to 600, the servo motor should be set to a position of 90.
- If the potentiometer reads a value from 600 to 800, the servo motor should be set to a position of 135.
- If the potentiometer reads a value of 800 or above, the servo motor should be set to a position of 180.
- Use the following diagram to create your circuit on Tinkercad using a 10K Ohm resistor and use the resistor provided by your teacher to build your physical circuit
To Develop your program:
- Build your circuit simulation in Tinkercad.
- Type the following into the code section of Tinkercad to get started:
// Add Servo library, create a servo named myServo in Pin 5, and set to an angle of 0
// Set a button as input in Pin 2 and a potentiometer as input in Pin A0
#include <Servo.h>
Servo myServo;
int button = 2;
int potPin = 0;
int potValue = 0;
void setup(){
myServo.attach(3);
pinMode(button, INPUT);
pinMode(potPin, INPUT);
myServo.write(0);
}
- Write your code inside the loop function using the commands you’ve learned. (Don’t forget comments!)
- Run your program on the simulation and on your physical device.
- Once you are sure that you’ve solved each portion of the problem, copy and paste your code from the Tinkercad editor into here to save it.
- Click the ‘Submit’ button to submit your program to your teacher for grading.