Hello from a newbie!
I am attempting to build an air quality / pollution monitor prototype using an Arduino Uno, DHT22 (Temperature/Humidity), MQ5 (LPG Gas sensor) and a 1602A LCD
I am looking to display values of a DHT22 and MQ5 sensors on a 16 * 2 lcd which I purchased recently for a
project. I have no idea who the maker is and the only visible marking is "1602A" on back of pcb on which the LCD is mounted (apart from "QAPASS")
I have based my code for the LCD on the library: <LiquidCrystal.h>
I would like to display Temperature *C and Humidity % on top line and MQ5 value in ppm on lower line of lcd.
So far my code looks like this (it is also attached)
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 13 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int MQ5 = A4;//////MQ5///////
int potValue = 0;
int redLED = 6; // red LED simulates alarm, once active, can only be acknowledged by pressing reset on Arduino.
float sensor=A4; // MQ5 Connected to A4
float gas_value;
void setup() {
Serial.begin(9600);
// Initialize device.
lcd.begin(16,2); // lcd rows and columns
pinMode(6, OUTPUT);// red led indication
pinMode(sensor,INPUT);
dht.begin();
Serial.println("----------------------------ECR-Sensor Monitor-------------------------------");
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println("-----------------------------------------------------");
Serial.println("Temperature");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" *C");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" *C");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" *C");
Serial.print ("Sensor ");Serial.println(A4);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println("ppm");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println("ppm");
Serial.println("------------------------------------");
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println("------------------------------------");
Serial.println("Humidity");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println("%");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println("%");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println("%");
Serial.println("------------------------------------");
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
lcd.setCursor(0, 0);
// Delay between measurements.////////////////////////////////////////
delay(1000);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
}
else {
Serial.print("Temperature: ");
Serial.print(event.temperature);
Serial.println(" *C");
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
}
else {
Serial.print("Humidity: ");
Serial.print(event.relative_humidity);
Serial.println("%");
potValue = analogRead(MQ5);
Serial.print("Gas Level ppm:");Serial.println(gas_value);
////////////////////////////////////////////////////////////////////////////
void displaylcd();
lcd.setCursor(0, 0);
switch (0)
case 0:
lcd.print("Gas:");
lcd.setCursor(0,1);
lcd.print(potValue);
if (potValue>15)
digitalWrite(6,HIGH);
delay(1000); //Delay 1 sec.
lcd.print("Temp");
lcd.setCursor(0, 1);
lcd.print(sensor,INPUT);
lcd.print("C");
lcd.print("RH");
lcd.setCursor(0, 1);
lcd.print(sensor,INPUT);
lcd.print("%");
lcd.clear();
gas_value=analogRead(sensor);
lcd.clear();
}
}
The problem is that at the moment it is only displaying a 'Gas' on top line and it's corresponding 'Value' on lower line. I have attached a picture of what I would like to have on the lcd.
Can somone here help me as I have spent loads of time trying to get the code to work but more often than not its like 2 steps forward then 3 or maybe 4 back! :o
AirMonProject.ino (3.58 KB)