Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
const int rs = 12, en = 7, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int gasPin = A0; //GAS sensor output pin to Arduino analog A0 pin
const int buzzerPin = 8; //Buzzer is connected pin 13
int gasValue = 0;
#define RX 10
#define TX 11
int countTrueCommand;
int countTimeCommand;
boolean found = false;
uint32_t nextlogTime = 0;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
lcd.setCursor(0, 1);
gasValue = analogRead(gasPin);
if (gasValue >= 300)
{
lcd.print("GasDetected:");
Serial.print("GasDetected:");
digitalWrite(buzzerPin, 1);
gasStatus = 1;
// delay(100);
// digitalWrite(buzzerPin,0);
}
else
{
lcd.print("Normal Air: ");
Serial.print("Normal Air: ");
digitalWrite(buzzerPin, 0);
gasStatus = 0;
}
lcd.print(gasValue);
Serial.println(gasValue);
delay(1000);
}
countTimeCommand++;
}
if (found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if (found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
delay(100);
}