/*_________________________________________________ * * U C I C R I T T E R S T U D Y G R O U P * L E S S O N 3 * Working with Servos * Included in study group kit * Red = 5V * Brn = Gnd * Orange = signal input Pin 10 on this demo * * PURPOSE: * DEMO HOW TO SET SG-90 SERVO POSITION WITH SERIAL MONITOR * Shows how to use serial monitor for intput * * commands: 1500 = center * 1000 = full left * 2000 = full right * try using 900-1000 and 2000-2500 to set precise angle */ //---must use servo.h library that comes with Arduino IDE #include //---instantiate new servo object Servo myServo; //--- store current servo positionition int myPosition = 0; void setup() { //--- initialize serial monitor Serial.begin(9600); myServo.attach(10); // control the servo on pin 10 } void loop() { //---is the serial monitor running? if(Serial.available() > 0) { myPosition = Serial.parseInt(); if(myPosition != 0) { Serial.println(myPosition); myServo.write(myPosition); delay(10); } } }