The circuit in question is designed to monitor environmental conditions using a series of gas sensors interfaced with an Arduino Mega 2560 microcontroller and an Adafruit ADS1115 16-bit I2C ADC (Analog-to-Digital Converter). The gas sensors included are the MQ-2, MQ-3, MQ-7, and MQ-135, each capable of detecting different types of gases. The ADC is used to convert the analog signals from the gas sensors into digital values that the Arduino can process. The power supply provides the necessary voltage to the components. The circuit utilizes I2C communication between the Arduino and the ADC, and analog inputs to read the sensors' data.
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
// Create an ADS1115 object
Adafruit_ADS1115 ads; // Use default constructor
void setup() {
Serial.begin(9600);
// Initialize the ADS1115 module
if (!ads.begin(0x48)) { // Pass the I2C address here
Serial.println("Failed to initialize ADS1115.");
while (1);
}
Serial.println("ADS1115 initialized.");
}
void loop() {
// Read analog values from the MQ sensors
int16_t adc0 = ads.readADC_SingleEnded(0); // MQ-2 on A0
int16_t adc1 = ads.readADC_SingleEnded(1); // MQ-3 on A1
int16_t adc2 = ads.readADC_SingleEnded(2); // MQ-7 on A2
int16_t adc3 = ads.readADC_SingleEnded(3); // MQ-135 on A3
// Convert ADC values to voltage (optional, for reference)
float voltage0 = adc0 * 0.1875 / 1000; // ADS1115 16-bit, ±6.144V range, 0.1875mV per bit
float voltage1 = voltage0; // Same for other channels
float voltage2 = voltage0;
float voltage3 = voltage0;
// Print ADC values and voltage to the Serial Monitor
Serial.print("MQ-2 (A0) ADC: "); Serial.print(adc0);
Serial.print(", Voltage: "); Serial.print(voltage0); Serial.println(" V");
Serial.print("MQ-3 (A1) ADC: "); Serial.print(adc1);
Serial.print(", Voltage: "); Serial.print(voltage1); Serial.println(" V");
Serial.print("MQ-7 (A2) ADC: "); Serial.print(adc2);
Serial.print(", Voltage: "); Serial.print(voltage2); Serial.println(" V");
Serial.print("MQ-135 (A3) ADC: "); Serial.print(adc3);
Serial.print(", Voltage: "); Serial.print(voltage3); Serial.println(" V");
// Add delay for readability
delay(1000);
}
This code initializes the ADS1115 ADC and reads the analog values from the MQ series gas sensors. It then prints the raw ADC values and the corresponding voltages to the Serial Monitor. The I2C address of the ADS1115 is set to 0x48, which is the default when the ADDR pin is connected to GND. The code includes a delay for readability of the output.