Analog Sensor

I used conductive tape and paint in order to create an analog sensor. One of the two LEDs is lighted by the circuit, according to the voltage of the potentiometer.

int inputPin = A0;
int WhiteLED = 13;
int RedLED = 3;

void setup() {
pinMode(inputPin, INPUT);
pinMode(WhiteLED, OUTPUT);
pinMode(RedLED, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int value = analogRead(inputPin);
int ledValue = map(value, 0, 1023, 0, 255);
Serial.println(ledValue);

if (ledValue >= 100) {
analogWrite(WhiteLED, ledValue);
digitalWrite(RedLED, LOW);
delay (1000);
}

else {
analogWrite(RedLED, ledValue);
digitalWrite(WhiteLED, LOW);
delay (1000);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s