Hello, may ask what is the !digitalRead code?
Also, I would like to take this opportunity in uploading the whole code to fully understand it:
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //Arduino IC2 Library
LiquidCrystal_I2C lcd(0x27, 16, 2);
int sensorPin = A3;
int sensorVal = 0;
float sensorCalc51 = 0; //51%
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int buzzPin = 13; //Setting pins
int i; //loop
void setup()
{
pinMode(sensorPin,INPUT);
pinMode(redPin,OUTPUT);
pinMode(bluePin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(buzzPin,OUTPUT);
lcd.begin();
lcd.backlight(); //LCD setup
Serial.begin(9600);
}
void loop()
{
sensorVal=analogRead(sensorPin);
sensorCalc51=(341./184.)*sensorVal;
Serial.println(" ");
Serial.print("0% : ");
Serial.print(sensorVal); //prints the 0%
Serial.print(" 51% : ");
Serial.print(sensorCalc51); //prints 51%
delay(100);
if (sensorVal <= sensorCalc51) { //If value is goes between the given threshold, the LCD will print a text,GREEN pin, and buzzer will TURN OFF
lcd.clear();
lcd.clear();
lcd.print("YOU ARE TOO ");
lcd.print(sensorVal);
lcd.setCursor (3,1);
lcd.print("SOBER");
analogWrite(redPin, 000);
analogWrite(bluePin,000);
analogWrite(greenPin,255);
digitalWrite(buzzPin, LOW);
}
if (sensorVal >= sensorCalc51) { //If value is goes above the threshold, the LCD will print a text,RED pin, and buzzer will TURN ON
lcd.clear();
for (int i=0; i<=20; i=i+1) {
lcd.print("DRUNK DRIVER");
lcd.setCursor (8,1);
lcd.print("ON-BOARD");
analogWrite(redPin,255);
analogWrite(bluePin,000);
analogWrite(greenPin,000);
digitalWrite(buzzPin, HIGH);
delay (500);
digitalWrite(buzzPin, LOW);
delay (500);
}
}
} //end of loop