Skip to content

Instantly share code, notes, and snippets.

@TURBULENTE
Created July 4, 2016 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TURBULENTE/db958e8de1dca393c6a2e01cceb95430 to your computer and use it in GitHub Desktop.
Save TURBULENTE/db958e8de1dca393c6a2e01cceb95430 to your computer and use it in GitHub Desktop.
Code test for making a servo move with a light resistor using Arduino UNO.
#include <Servo.h>
Servo myservo;
int motor = 9; // LED connected to digital pin 9
int val;
void setup() {
// nothing happens in setup
myservo.attach(motor);
Serial.begin(9600);
}
void loop() {
//sensor
val = analogRead(A5);
val = map(val, 0, 1023, 0, 180);
if (val>160){
}else{
myservo.write(val);
delay(15);
Serial.println(val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment