// Breathaylzer example by Rojas@SparkFun.com int sensorPin = 0; //alcohol sensor int green1 = 10; //green LED 1 int green2 = 11; //green LED 2 int yellow1 = 6; //yellow LED 1 int yellow2 = 9; //yellow LED 2 int red1 = 5; //red LED 1 int red2 = 3; //red LED 2 int sensorValue = 0; //default sensorValue is 0 void setup() { Serial.begin(9600); //begin serial at 9600 baud pinMode(green1, OUTPUT); //set pins as outputs pinMode(green2, OUTPUT); pinMode(yellow1, OUTPUT); pinMode(yellow2, OUTPUT); pinMode(red1, OUTPUT); pinMode(red2, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); //take analog in Serial.println(sensorValue); //send it over serial if (sensorValue <= 170){ //the alcohol sensor usually idles around 170 int green1Value = map(sensorValue, 0,170,0,255); //map 0-170 from the sensor to 0-255 to fade the LED analogWrite(green1, green1Value); //fade the LED } if (sensorValue >= 170 && sensorValue <= 340){ //if the sensor input is in the 170-340 range... int green2Value = map(sensorValue, 170,340,0,255); //map 170-340 from the sensor to 0-255 to fade the LED analogWrite(green2, green2Value); //fade the LED } if (sensorValue >= 340 && sensorValue <= 510){ //if the sensor input is in the 340-510 range... int yellow1Value = map(sensorValue, 340,510,0,255); //map 340-510 from the sensor to 0-255 to fade the LED analogWrite(yellow1, yellow1Value); //fade the LED } if (sensorValue >= 510 && sensorValue <= 680){ //if the sensor input is in the 510-680 range... int yellow2Value = map(sensorValue, 510,680,0,255); //map 510-680 from the sensor to 0-255 to fade the LED analogWrite(yellow2, yellow2Value); //fade the LED } if (sensorValue >= 680 && sensorValue <= 850){ //if the sensor input is in the 680-850 range... int red1Value = map(sensorValue, 680,850,0,255); //map 680-850 from the sensor to 0-255 to fade the LED analogWrite(red1, red1Value); //fade the LED } if (sensorValue >= 850){ //if the sensor input is in the 850-1023 range... int red2Value = map(sensorValue, 850,1023,0,255); //map 850-1023 from the sensor to 0-255 to fade the LED analogWrite(red2, red2Value); //fade the LED } }