Moving Dot Display of Voltage
Without changing our LED layout we can now display a voltage value by lighting up LEDs in succession as the input voltage increases.
--------------------------- Copy Code Below
byte sensorPin = A0;
int sensorValue;
byte led1 = 8;
byte led2 = 9;
byte led3 = 10;
byte led4 = 11;
byte led5 = 12;
byte led6 = 13;
void setup()
{
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
pinMode(led6,OUTPUT);
}
void loop()
{
sensorValue = analogRead(sensorPin);
if (sensorValue >=150 && sensorValue <160)
{
digitalWrite(led1, HIGH);
}
else if (sensorValue >= 160 && sensorValue <170)
{
digitalWrite(led2, HIGH);
}
else if (sensorValue >=170& sensorValue <180)
{
digitalWrite(led3, HIGH);
}
else if (sensorValue >=180 && sensorValue <190)
{
digitalWrite(led4, HIGH);
}
else if (sensorValue >=190 && sensorValue <200)
{
digitalWrite(led5, HIGH);
}
else if (sensorValue >=200)
{
digitalWrite(led6, HIGH);
}
delay(100);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
}
--------------------------- End of Code
Things to do:
- Calculate sensor values which will allow the Arduino to discern voltages in one volt increments (and 1/2 volt increments).
NOTE: The resolution of the AD converter is 0.00488 volts per unit (5 Volts/1024 increments)
- Create an over-voltage alarm to detect when the voltage is over 4 volts
- Create a device to measure the charge on a 12 volt battery in 1 volt increments. Should be able to measure up to 13 volts and alarm when the voltage is less than 10 volts.
NOTE: You must use a voltage divider that will not allow the Arduino analog input voltage to exceed 5 volts.
byte led1 = 8;
byte led2 = 9;
byte led3 = 10;
byte led4 = 11;
byte led5 = 12;
byte led6 = 13;
void setup()
{
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
pinMode(led6,OUTPUT);
}
void loop()
{
sensorValue = analogRead(sensorPin);
if (sensorValue >=150 && sensorValue <160)
{
digitalWrite(led1, HIGH);
}
else if (sensorValue >= 160 && sensorValue <170)
{
digitalWrite(led2, HIGH);
}
else if (sensorValue >=170& sensorValue <180)
{
digitalWrite(led3, HIGH);
}
else if (sensorValue >=180 && sensorValue <190)
{
digitalWrite(led4, HIGH);
}
else if (sensorValue >=190 && sensorValue <200)
{
digitalWrite(led5, HIGH);
}
else if (sensorValue >=200)
{
digitalWrite(led6, HIGH);
}
delay(100);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
}
--------------------------- End of Code
Things to do:
- Calculate sensor values which will allow the Arduino to discern voltages in one volt increments (and 1/2 volt increments).
NOTE: The resolution of the AD converter is 0.00488 volts per unit (5 Volts/1024 increments)
- Create an over-voltage alarm to detect when the voltage is over 4 volts
- Create a device to measure the charge on a 12 volt battery in 1 volt increments. Should be able to measure up to 13 volts and alarm when the voltage is less than 10 volts.
NOTE: You must use a voltage divider that will not allow the Arduino analog input voltage to exceed 5 volts.
No comments:
Post a Comment