Electric Chevy S10

EV Electric Vehicle Chevy S10 Lithium Battery ThunderSky Warp 9 Zilla 1000 amp Controller

Arduino Uno Servo with LED indication

My first attempt at creating a "sketch" that used a servo and led lights at the same time.

 The Arduino Uno is connected to my laptop via a USB cable for power and uploading.

 The circuit: Connect the servo to ground and 5V, and the signal wire to pin 9. I then used pins 10-13 for the leds 1 through 4 and pin 8 for led 5. Yeah, I should've fixed that allready...

 a 220 ohm resistor for each led to ground, the led's longer pin to the signal pins.

 

The "sketch"

/*
Servo with position indicating LED lights
Coded by Brian Mathis
Lots of help from http://www.arduino.cc/
Free to use as you want!
*/

#include <Servo.h> //Includes the library code to run a servo
 
Servo servo1;  // Creates a servo object and names it

int led1 = 10;  // Creates an led name and its pin output
int led2 = 11;
int led3 = 12;
int led4 = 13;
int led5 = 8;

void setup()
{

servo1.attach(9);  // Makes pin 9 the servo's signal output

pinMode(led1, OUTPUT);  //labels the pin as an output
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);

}

void loop()
{
 
digitalWrite (led1, HIGH);

servo1.write(0);     // Positions the servo to 0 degrees

delay(500);          // Time delay of half a second
 
digitalWrite (led1, LOW);
digitalWrite (led2, HIGH);
 
servo1.write(45);

delay(500);
 
digitalWrite (led2, LOW);
digitalWrite (led3, HIGH);
 
servo1.write(90);   
delay(500);         
 
digitalWrite (led3, LOW);
digitalWrite (led4, HIGH);
 
servo1.write(135);   
delay(500);
digitalWrite (led4, LOW);
digitalWrite (led5, HIGH);
 
servo1.write(180);   
delay(500);
digitalWrite (led5, LOW);
digitalWrite (led4, HIGH);
   
servo1.write(135);   
delay(500);
digitalWrite (led4, LOW);
digitalWrite (led3, HIGH);
 
servo1.write(90);   
delay(500);
digitalWrite (led3, LOW);
digitalWrite (led2, HIGH);
 
servo1.write(45);   
delay(500);
digitalWrite (led2, LOW);
digitalWrite (led1, HIGH);
 
}

Recent Videos

1976 views - 0 comments