Resistive Sensor Assignment Arduino Code

by buechley


int sensorPin = A5;
int sensorValue;
int internalLED = 13;
int LED1 = 9;
int LED2 = 10;
int LED3 = 11;
int LED4 = A2;

void setup() {
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH); //turns on the internal pull-up resistor

pinMode(internalLED, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);

digitalWrite(internalLED, HIGH);
Serial.begin(9600);
}

void loop() {
sensorValue=analogRead(sensorPin);
Serial.println(sensorValue);
delay(100);

if (sensorValue < 1000)
{
digitalWrite(LED1, HIGH);
if (sensorValue <750)
{
digitalWrite(LED2, HIGH);
if (sensorValue <500)
{
digitalWrite(LED3, HIGH);
if (sensorValue <250)
{
digitalWrite(LED4, HIGH);
}
else
digitalWrite(LED4, LOW);
}
else
{
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
}
}
else
{
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
}
}
else {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
}
}