bine
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
#define sensor A0
#define led 13
#define ledd 8 // d out from mq3
#define buz 9
#define motor 10
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.print("ALCOHOL MONITORING");
lcd.setCursor(0,1);
lcd.print(" VEHICLE SYSTEM ");
delay(2000);
pinMode(sensor, INPUT);
pinMode(buz, OUTPUT);
pinMode(led, OUTPUT);
pinMode(ledd, OUTPUT);
pinMode(motor, OUTPUT);
lcd.clear();
}
void loop()
{
float adcValue=0;
for(int i=0;i<10;i++)
{
float actualanalogReading = analogRead(sensor);
adcValue = adcValue + actualanalogReading;
Serial.println("In loop counter >"); // logging
Serial.print(i);
Serial.print(" input reading : ");
Serial.print(actualanalogReading);
Serial.print(" cumulative input reading : ");
Serial.print(adcValue);
delay(10);
}
float v= (adcValue/10) * (3.0/1024.0);
float mgL= 0.67 * v;
Serial.println("");
Serial.print("Post calculation v value >" );
Serial.print(v);
Serial.print(" mg/L > ");
Serial.print(mgL);
Serial.println("");
Serial.print("BAC:");
Serial.print(mgL);
Serial.print(" mg/L");
lcd.setCursor(0,0);
lcd.print("BAC: ");
lcd.print(mgL,4);
lcd.print(" mg/L ");
lcd.setCursor(0,1);
if(mgL > 0.8)
{
lcd.print("Drunk ENGINE OFF ");
Serial.println("Drunk ENGINE OFF ");
digitalWrite(buz, HIGH);
digitalWrite(led, HIGH);
digitalWrite(ledd, LOW);
digitalWrite(motor, LOW);
}
else
{
lcd.print("Normal ENGINE ON ");
Serial.println(" Normal ENGINE ON ");
digitalWrite(buz, LOW);
digitalWrite(led, LOW);
digitalWrite(ledd, HIGH);
digitalWrite(motor, HIGH);
}
delay(100);
}
top code^^^ combines with this>>
const int LED = A5;
const int DO = 6;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(DO, INPUT);
}
void loop() {
int alarm = 0;
float sensor_volt;
float RS_gas;
float ratio;
//-Replace the name "R0" with the value of R0 in the demo of First Test -/
float R0 = 0.10;
int sensorValue = analogRead(A1);
sensor_volt = ((float)sensorValue / 1024) * 5.0;
RS_gas = (5.0 - sensor_volt) / sensor_volt; // Depend on RL on yor module
ratio = RS_gas / R0; // ratio = RS/R0
//------------------------------------------------------------/
Serial.print("sensor_volt = ");
Serial.println(sensor_volt);
Serial.print("RS_ratio = ");
Serial.println(RS_gas);
Serial.print("Rs/R0 = ");
Serial.println(ratio);
Serial.print("\n\n");
alarm = digitalRead(DO);
if (alarm == 1) digitalWrite(LED, LOW);
else if (alarm == 0) digitalWrite(LED, HIGH);
delay(1000);
}
BlinkWithoutDelayexample, which comes with the Arduino IDE. It shows how you can use themillis()function to write non-blocking code withoutdelay()calls. It is an important principle to learn and may be really helpful when combining your sketches – chrisl Sep 24 '20 at 14:42