Last active
July 30, 2019 01:02
-
-
Save futureshocked/95a9ac30ceb462128fc053983c5e33de to your computer and use it in GitHub Desktop.
This sketch demonstrates how to use the Grove servo motor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 05.60 - Grove servo motors | |
| * | |
| This sketch demonstrates how to use the Grove servo motor. | |
| For the servo motor to | |
| work, you must connect it to a PWM-capable pin. | |
| Grove sockets that breakout PWM pins are D3, D5, D6, and D8 (inner pin only). | |
| Connect the servo motor to Grove socket D3 and upload the sketch. | |
| The motor will rotate 180, back and forth. | |
| Components | |
| ---------- | |
| - Grove Base Shield | |
| - An Arduino Uno compatible board (such as Arduino/Genuino Uno or Seeeduino) | |
| - Grove servo motor module | |
| - One Grove cable | |
| IDE | |
| --- | |
| Arduino IDE | |
| Libraries | |
| --------- | |
| - Servo.h (part of the Arduino IDE) | |
| Connections | |
| ----------- | |
| Use a Grove cable to connect the module to Base Shield connector D3. | |
| Other information | |
| ----------------- | |
| - Use this sketch along side the video lecture 05.60 of Grove For Busy People | |
| - Grove documentation: http://wiki.seeedstudio.com/Grove-Servo/ | |
| - Grove component: https://txplo.re/d55cd | |
| Github Gist | |
| ----------- | |
| <script src="https://gist.github.com/futureshocked/95a9ac30ceb462128fc053983c5e33de.js"></script> | |
| https://gist.github.com/futureshocked/95a9ac30ceb462128fc053983c5e33de | |
| For course information, please go to https://techexplorations.com/product/grove-for-busy-people/ | |
| Created on July 5 2019 by Peter Dalmaris | |
| */ | |
| #include <Servo.h> | |
| Servo myservo; // create servo object to control a servo | |
| const int motorPin = 8; | |
| int pos = 0; // variable to store the servo position | |
| void setup() { | |
| myservo.attach(motorPin); // attaches the servo on pin 9 to the servo object | |
| // myservo.write(180); // Experimentally, determine the exterme positions for your servo | |
| // delay(2000); | |
| // myservo.write(10); | |
| // delay(2000); | |
| } | |
| void loop() { | |
| for (pos = 10; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees | |
| // in steps of 1 degree | |
| myservo.write(pos); // tell servo to go to position in variable 'pos' | |
| delay(15); // waits 15ms for the servo to reach the position | |
| } | |
| for (pos = 180; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees | |
| myservo.write(pos); // tell servo to go to position in variable 'pos' | |
| delay(15); // waits 15ms for the servo to reach the position | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment