const int analogPin = 0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
unsigned int val = 0;
unsigned char PIN = 0;
int ledPins[] = {
11,10,9,8,7,6,5,4,3,2 // Here we have the number of LEDs to use in the BarGraph
};
void setup() {
{
Serial.begin(9600);
pinMode(PIN,INPUT);
}
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}}
void loop() {
{
val = analogRead(PIN);
Serial.println(val);
delay(2000);
}
//This is the code to light up LED's
int sensorReading = analogRead(analogPin);
int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
else {
digitalWrite(ledPins[thisLed], LOW);
} }}
I think a lot of people are interested in calibrating the MQ-3 alcohol sensor to make a workable breathalyzer. I spent a lot of time on this and did a big writeup on the project here: