#include //For I2C #include //for DS18B20 #include //for DS18B20 #include //for SSD1306 OLED #include //for SSD1306 OLED #define DHT_NODE_ADDRESS 1 // I2C address of the DHT22 node module #define MQ2_NODE_ADDRESS 2 // I2C address of the MQ2 node module #define ONE_WIRE_BUS 21 // Pin for DS18B20 sensor #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels OneWire oneWire(ONE_WIRE_BUS); //for DS18B20 DS18B20_INT sensor(&oneWire); //for DS18B20 // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); int temperature, humidity, gasValue, soilTemp; void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(115200); // start serial for output sensor.begin(); //begin DS18B20 sensor if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 Serial.println(F("SSD1306 allocation failed")); for(;;); } delay(2000); display.clearDisplay(); } void loop() { sensor.requestTemperatures(); // get temperature from DS18B20 while (!sensor.isConversionComplete()); // (BLOCKING!!) wait until sensor is ready soilTemp = sensor.getTempC(); /* Serial.print("Temp: "); Serial.println(sensor.getTempC()); */ // Request data from the DHT22 sensor node Wire.requestFrom(DHT_NODE_ADDRESS, sizeof(int) * 2); // Request 2 integers if (Wire.available() >= sizeof(int) * 2) { temperature = Wire.read(); humidity = Wire.read(); /* // Process and display the received data from DHT22 Serial.print("DHT22 - Temperature: "); Serial.print(temperature); Serial.print(" °C, Humidity: "); Serial.print(humidity); Serial.println(" %"); */ } // Request data from the MQ2 gas sensor node Wire.requestFrom(MQ2_NODE_ADDRESS, sizeof(int)); // Request 1 integer if (Wire.available() >= sizeof(int)) { gasValue = Wire.read(); /* // Process and display the received data from MQ2 gas sensor Serial.print("MQ2 Gas Sensor - Gas Value: "); Serial.println(gasValue); */ } display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); // Display static text display.println("Air Temperature:"); display.setCursor(100, 8); display.println(temperature); display.setCursor(0, 8); // Display static text display.println("Air Humidity"); display.setCursor(100, 8); display.println(humidity); // Display static text display.setCursor(0, 16); display.println("Gas Value: "); display.setCursor(100, 16); // Display static text display.println(gasValue); display.setCursor(100, 32); // Display static text display.println(gasValue); display.display(); delay(1000); }