IoT A (copy) — ESP32 simulation

Aquaculture monitoring system with temperature, pH, and motor control.

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by balu.

Components

Sketch code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

#define DHTPIN 4
#define DHTTYPE DHT22
#define PH_PIN 34

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

DHT dht(DHTPIN, DHTTYPE);

Adafruit_SSD1306 display(
  SCREEN_WIDTH,
  SCREEN_HEIGHT,
  &Wire,
  OLED_RESET
);

void setup() {
  Serial.begin(115200);

  Wire.begin(21, 22);
  dht.begin();
  analogReadResolution(12);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("OLED not detected!");
    while (true);
  }

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("Aquaculture System");
  display.println("Starting...");
  display.display();

  delay(2000);
}

void loop() {
  // Temperature reading from DHT22
  float temperature = dht.readTemperature();

  // pH sensor analog reading
  int phRaw = analogRead(PH_PIN);
  float voltage = phRaw * (3.3 / 4095.0);

  // Temporary estimated pH formula
  // Actual sensor calibration is required
  float pH = 7.0 + ((1.65 - voltage) / 0.18);

  // Serial Monitor
  Serial.println("--------------------");

  if (isnan(temperature)) {
    Serial.println("Temperature sensor ERROR!");
  } else {
    Serial.print("Temperature: ");
    Serial.print(temperature, 1);
    Serial.println(" C");
  }

  Serial.print("pH Raw Value: ");
  Serial.println(phRaw);

  Serial.print("pH Voltage: ");
  Serial.print(voltage, 2);
  Serial.println(" V");

  Serial.print("Estimated pH: ");
  Serial.println(pH, 2);

  // OLED Display
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);

  display.println("POND MONITORING");
  display.println("----------------");

  if (isnan(temperature)) {
    display.println("Temp: Sensor ERROR");
  } else {
    display.print("Temp: ");
    display.print(temperature, 1);
    display.println(" C");
  }

  display.print("pH: ");
  display.println(pH, 2);

  display.display();

  delay(2000);
}

More projects by balu