Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Last active August 29, 2015 14:02
Show Gist options
  • Save abruzzi/92c89953bab4ede7d95d to your computer and use it in GitHub Desktop.
Save abruzzi/92c89953bab4ede7d95d to your computer and use it in GitHub Desktop.
Arduino Servo
/*
* Arduino pin 9 -> S3003 PWM(orange)
* Arduino 5V -> S3003 VCC(red)
* Arduino GND -> S3003 GND(brown)
*/
#include <Servo.h>
Servo servo;
int servoPin = 9;
int pos = 0;
void setup() {
servo.attach(servoPin);
}
void loop() {
for(pos = 0; pos < 180; pos += 1) {
servo.write(pos);
delay(20);
}
for(pos = 180; pos >= 1; pos -= 1) {
servo.write(pos);
delay(20);
}
}
#include <Servo.h>
Servo servo;
int servoPin = 9;
void setup() {
Serial.begin(9600);
servo.attach(servoPin);
}
int deg = 0;
void loop(){
if(Serial.available()) {
deg = Serial.parseInt();
}
if(deg >= 0 && deg <= 180) {
servo.write(deg);
delay(20);
} else {
Serial.write("bad request");
}
delay(100);
}
/*
* Connet JY-MCU Bluetooth with arduino
* Rx -> Tx
* Tx -> Rx
* 5v -> 5v
* Gnd -> Gnd
*/
int value;
int led = 13;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop(){
if(Serial.available()) {
value = Serial.read();
}
if(value == 'H') {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment