Arduino UNO Based Gas Detection and Temperature Monitoring System with SMS Alerts
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit in question is designed around an Arduino UNO microcontroller and includes various sensors and output devices. The primary purpose of this circuit is to monitor environmental conditions using gas sensors (MQ6) and a temperature and humidity sensor (DHT11). It also includes a buzzer and an LED for alerts, and a SIM800L module for potential communication capabilities. The circuit is powered by the Arduino's 5V output and shares a common ground.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
MQ6 Gas Sensor
- A gas sensor designed for detecting LPG, butane, propane, methane, alcohol, hydrogen, and smoke.
- It has four pins: VCC, GND, A0 (analog output), and DO (digital output).
DHT11 Temperature and Humidity Sensor
- A basic, ultra low-cost digital temperature and humidity sensor.
- It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on the data pin.
LED: Two Pin (red)
- A basic red LED for indication purposes.
- It has two pins: anode and cathode.
Resistor
- A passive two-terminal electrical component that implements electrical resistance as a circuit element.
- In this circuit, a 1.5 Ohm resistor is used, likely for current limiting to the LED.
Buzzer
- An audio signaling device, which may be mechanical, electromechanical, or piezoelectric.
- It has two pins: PIN (signal input) and GND.
Sim800l
- A GSM/GPRS module that can provide SMS, call, and Internet services via AT commands.
- It has six pins: NET, RST, VCC, RXD, TXD, and GND.
Wiring Details
Arduino UNO
- 5V: Connected to VCC of all MQ6 sensors, DHT11, and Sim800l.
- GND: Connected to GND of all MQ6 sensors, DHT11, buzzer, LED, and Sim800l.
- A1: Connected to A0 of the first MQ6 sensor.
- A2: Connected to A0 of the second MQ6 sensor.
- A3: Connected to A0 of the third MQ6 sensor.
- D4: Connected to the PIN of the buzzer.
- D5: Connected to the DATA pin of the DHT11 sensor.
- D7: Connected to RXD of Sim800l.
- D8: Connected to TXD of Sim800l.
MQ6 Gas Sensor
- VCC: Connected to 5V on Arduino UNO.
- GND: Connected to GND on Arduino UNO.
- A0: Connected to an analog input on Arduino UNO (A1, A2, or A3 depending on the sensor).
DHT11 Temperature and Humidity Sensor
- DATA: Connected to D5 on Arduino UNO.
- VCC: Connected to 5V on Arduino UNO.
- GND: Connected to GND on Arduino UNO.
LED: Two Pin (red)
- Anode: Connected to pin2 of the resistor.
- Cathode: Connected to GND on Arduino UNO.
Resistor
- Pin1: Connected to D3 on Arduino UNO.
- Pin2: Connected to the anode of the LED.
Buzzer
- PIN: Connected to D4 on Arduino UNO.
- GND: Connected to GND on Arduino UNO.
Sim800l
- TXD: Connected to D8 on Arduino UNO.
- RXD: Connected to D7 on Arduino UNO.
- VCC: Connected to 5V on Arduino UNO.
- GND: Connected to GND on Arduino UNO.
Documented Code
#include <U8glib.h>
#include <DHT.h>
#define DHTPIN 2 // Pin where DHT11 is connected
#define DHTTYPE DHT11 // DHT 11
#define MQ3_PIN A0 // MQ-3 analog pin
#define MQ4_PIN A1 // MQ-4 analog pin
#define BUTTON_PIN 3 // Push button pin
#define RED_LED_PIN 4 // Red LED pin
#define GREEN_LED_PIN 5 // Green LED pin
#define BUZZER_PIN 6 // Buzzer pin
DHT dht(DHTPIN, DHTTYPE);
U8GLIB_SH1106_128X64 u8g; // Initialize display
bool measuring = false;
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP); // Use internal pull-up resistor
u8g.begin();
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
delay(200); // Debounce delay
measuring = true;
startMeasurement();
}
if (!measuring) {
// Show press to start message
displayMessage("Press to start");
}
}
void startMeasurement() {
int mq3Value = 0;
int mq4Value = 0;
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read sensor values for 20 seconds
for (int i = 0; i < 20; i++) {
mq3Value += analogRead(MQ3_PIN);
mq4Value += analogRead(MQ4_PIN);
// Update display with readings
updateDisplay(mq3Value / (i + 1), mq4Value / (i + 1), humidity, temperature);
delay(1000); // Wait 1 second between readings
}
mq3Value /= 20; // Average
mq4Value /= 20; // Average
// Check against threshold values (set these as needed)
int thresholdMQ3 = 400; // Example threshold for MQ-3
int thresholdMQ4 = 100; // Example threshold for MQ-4
// Determine spoilage
if (mq3Value > thresholdMQ3 || mq4Value > thresholdMQ4) {
handleSpoilage(mq3Value, mq4Value, humidity, temperature);
} else {
handleFreshness(mq3Value, mq4Value, humidity, temperature);
}
}
void updateDisplay(int mq3Value, int mq4Value, float humidity, float temperature) {
u8g.firstPage();
do {
u8g.setFont(u8g_font_ncenB08);
u8g.drawStr(0, 10, "MQ3 Value:");
u8g.setPrintPos(0, 20);
u8g.print(mq3Value);
u8g.drawStr(0, 30, "MQ4 Value:");
u8g.setPrintPos(0, 40);
u8g.print(mq4Value);
u8g.drawStr(0, 50, "Temp: ");
u8g.setPrintPos(0, 60);
u8g.print(temperature);
u8g.drawStr(60, 50, "Humidity: ");
u8g.setPrintPos(60, 60);
u8g.print(humidity);
} while (u8g.nextPage());
}
void handleSpoilage(int mq3Value, int mq4Value, float humidity, float temperature) {
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
for (int i = 0; i < 5; i++) {
tone(BUZZER_PIN, 1000); // Beep sound
delay(500);
noTone(BUZZER_PIN);
delay(500);
}
// Display spoilage message
displayMessage("Food Spoilage");
delay(8000); // Show message for 2 seconds
// Show results for 10 seconds
displayResults(mq3Value, mq4Value, humidity, temperature);
}
void handleFreshness(int mq3Value, int mq4Value, float humidity, float temperature) {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
// Display freshness message
displayMessage("Food is fresh!");
delay(8000); // Show message for 2 seconds
// Show results for 10 seconds
displayResults(mq3Value, mq4Value, humidity, temperature);
}
void displayResults(int mq3Value, int mq4Value, float humidity, float temperature) {
unsigned long startTime = millis();
while (millis() - startTime < 10000) { // 10 seconds
updateDisplay(mq3Value, mq4Value, humidity, temperature);
}
// Reset LEDs and measuring state
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
measuring = false; // Reset measuring state
displayMessage("Press to start"); // Prompt to start again
}
void displayMessage(const char* message) {