

This circuit is designed to monitor environmental parameters such as temperature, humidity, CO2 levels, and soil moisture. It utilizes an Arduino Mega 2560 as the central microcontroller to read data from DHT22 sensors, MQ135 sensors, a capacitive soil moisture sensor, and to control a 4-channel relay module and an RGB LED matrix. The data is displayed on both an LCD and an OLED display. A rotary encoder allows the user to navigate through different data pages on the OLED display. The circuit also includes an RTC module for timekeeping and an SD card module for data logging.
3V3 connected to SD card module +3.3V5V connected to various components' VCC pinsGND connected to various components' GND pinsA0 to A2 connected to analog pins of sensorsD21/SCL and D20/SDA connected to I2C devices (LCD, OLED, RTC)D17 PWM/RX2 to D14/TX3 connected to relay module inputs IN 1 to IN 4D5 PWM to D11 PWM connected to rotary encoder pins CLK, DT, SWD12 PWM connected to WS2812 RGB LED matrix DIND52, D50, D51, D46 connected to SD card module SCK, MISO, MOSI, CSD24, D22 connected to DHT22 sensors OUT pinsVCC+ and VCC- (GND) connected to 5V and GND respectivelyIN 1 to IN 4 controlled by Arduino pins D14/TX3 to D17 PWM/RX2VDD and GND connected to 5V and GND respectivelySCK and SDA connected to Arduino D21/SCL and D20/SDAVCC and GND connected to 5V and GND respectivelySDA and SCL connected to Arduino D20/SDA and D21/SCL+ and GND connected to 5V and GND respectivelySW, DT, CLK connected to Arduino pins D7 PWM, D6 PWM, D5 PWM for one encoder and D11 PWM, D10 PWM, D9 PWM for the otherVCC and GND connected to 5V and GND respectivelyA0 connected to Arduino A1 and A2VCC and GND connected to 5V and GND respectivelyA connected to Arduino A0VCC and GND connected to 5V and GND respectivelySCL and SDA connected to Arduino D21/SCL and D20/SDAVCC and GND connected to 5V and GND respectivelyOUT connected to Arduino D22 and D24VCC and GND connected to 5V and GND respectivelyDIN connected to Arduino D12 PWM+3.3V, GND, +5V connected to Arduino 3V3, GND, 5V respectivelyCS, MOSI, SCK, MISO connected to Arduino D46, D51, D52, D50/*
* This Arduino Sketch reads data from DHT22 sensors for temperature and
* humidity, MQ135 sensors for CO2 levels, and a soil moisture sensor. It
* displays the data on an LCD and OLED screen. The LCD shows the date and
* time, while the OLED cycles through pages displaying temperature, humidity,
* CO2 levels, and soil moisture. A rotary encoder is used to switch between
* the pages on the OLED display. The code also controls a relay module and an
* RGB LED matrix based on specific conditions.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
#include <RTClib.h>
#include <Adafruit_NeoPixel.h>
#include <SD.h>
#define DHTPIN0 22
#define DHTPIN1 24
#define DHTTYPE DHT22
#define MQ135PIN0 A2
#define MQ135PIN1 A1
#define SOILMOISTUREPIN A0
#define OLED_RESET -1
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define RELAY1 14
#define RELAY2 15
#define RGB_PIN 12
#define NUMPIXELS 8
#define SD_CS 46
DHT dht0(DHTPIN0, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS1307 rtc;
Adafruit_NeoPixel pixels(NUMPIXELS, RGB_PIN, NEO_GRB + NEO_KHZ800);
File dataFile;
int page = 0;
const int totalPages = 4;
unsigned long previousMillis = 0;
const long interval = 20000;
bool relay2State = false;
void setup() {
Wire.begin();
lcd.begin();
lcd.backlight();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
dht0.begin();
dht1.begin();
rtc.begin();
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pixels.begin();
if (!SD.begin(SD_CS)) {
lcd.print("SD init failed!");
return;
}
dataFile = SD.open("datalog.txt", FILE_WRITE);
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 0);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');