Photo on 10-2-14 at 23.15

I’ve made an indicator which can move when people revolve the knob. And with the movement of the indicator, 2 leds will be turned on. If the indicator moved in 120 degree, the green one will be brighter and brighter, but it will turned off if the indicator moved more than 120 degrees. After the green one turned off, the right one will be on and show the dangerous. I am trying to get some connection between this one with the speed of the car.


// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
int led1 = 6;
int led2 = 5;
Servo myservo; // create servo object to control a servo
int sensor = A0;// a maximum of eight servo objects can be created
int brightness;
int pos = 0; // variable to store the servo position

void setup()
pinMode(sensor, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT); // attaches the servo on pin 9 to the servo object

void loop()
pos = map (analogRead(sensor),0,1023,0,180);
brightness= map(pos,60,180,255,0);
analogWrite(led1, brightness);
brightness= map(pos,0,60,255,0);
analogWrite(led1, LOW);

Leave a Reply

Your email address will not be published.