The Smart Diaper Management System is designed to monitor moisture and gas levels using an Arduino UNO as the central processing unit. The system integrates a soil moisture sensor (SparkFun gator:soil) and a gas sensor (MQ-5) to detect the respective levels. The moisture sensor's signal is connected to the Arduino's analog input A0, while the gas sensor's analog output is connected to A1 and its digital output to digital pin D2. The Arduino reads the sensor values and outputs the data to the Serial Monitor. If the moisture or gas levels exceed predefined thresholds, an alert is triggered.
/*
* Smart Diaper Management System
* This Arduino sketch interfaces with a soil moisture sensor and a gas sensor
* to monitor moisture and gas levels in a smart diaper. The soil moisture
* sensor is connected to analog pin A0, and the gas sensor is connected to
* analog pin A1 (analog output) and digital pin 2 (digital output). The system
* reads the sensor values and prints them to the Serial Monitor. If moisture or
* gas levels exceed certain thresholds, an alert is triggered.
*/
const int moistureThreshold = 500; // Example threshold for moisture level
const int gasAnalogThreshold = 300; // Example threshold for gas level (analog)
const int gasDigitalThreshold = HIGH; // Example threshold for gas level (digital)
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT); // Soil moisture sensor
pinMode(A1, INPUT); // Gas sensor analog output
pinMode(2, INPUT); // Gas sensor digital output
}
void loop() {
int moistureValue = analogRead(A0); // Read moisture level
int gasAnalogValue = analogRead(A1); // Read gas level (analog)
int gasDigitalValue = digitalRead(2); // Read gas level (digital)
// Print values to Serial Monitor
Serial.print("Moisture Level: ");
Serial.println(moistureValue);
Serial.print("Gas Level (Analog): ");
Serial.println(gasAnalogValue);
Serial.print("Gas Level (Digital): ");
Serial.println(gasDigitalValue);
// Check if moisture level exceeds threshold
if (moistureValue > moistureThreshold) {
Serial.println("Alert: Moisture level too high!");
}
// Check if gas level (analog) exceeds threshold
if (gasAnalogValue > gasAnalogThreshold) {
Serial.println("Alert: Gas level (analog) too high!");
}
// Check if gas level (digital) exceeds threshold
if (gasDigitalValue == gasDigitalThreshold) {
Serial.println("Alert: Gas level (digital) too high!");
}
delay(1000); // Wait for 1 second before next reading
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the sensor inputs and continuously reads the moisture and gas levels, comparing them against set thresholds. If the readings exceed these thresholds, the system outputs an alert to the Serial Monitor.