Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Power Monitoring System with OLED Display and Wi-Fi Connectivity

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Power Monitoring System with OLED Display and Wi-Fi Connectivity

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that includes various sensors, pushbuttons, an OLED display, and an ESP32 microcontroller. The circuit is designed to measure current and voltage, display the readings on an OLED screen, and potentially send data over WiFi.

Component List

  1. Pushbutton

    • Description: A simple pushbutton switch.
    • Pins: Pin 1 (in), Pin 2 (in), Pin 3 (out), Pin 4 (out)
  2. ACS712 Current Sensor 5A 20A 30A

    • Description: A current sensor capable of measuring up to 30A.
    • Pins: 1, 2, GND, OUT, VCC
  3. Voltage Sensor DC 25V

    • Description: A voltage sensor capable of measuring up to 25V.
    • Pins: +, -, output, gnd, vcc
  4. 0.96" OLED

    • Description: A small OLED display for visual output.
    • Pins: GND, VDD, SCK, SDA
  5. USB Male 2 Pin Connection

    • Description: A USB male connector with 2 pins.
    • Pins: Negative -, Positive +
  6. USB Female

    • Description: A USB female connector.
    • Pins: VCC, GND, -D, +D
  7. ESP32 Devkit V1

    • Description: A development board based on the ESP32 microcontroller.
    • Pins: 3V3, GND, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, VIN

Wiring Details

Pushbutton

ACS712 Current Sensor 5A 20A 30A

Voltage Sensor DC 25V

0.96" OLED

USB Male 2 Pin Connection

USB Female

ESP32 Devkit V1

Documented Code

ESP32 Devkit V1 Code

#include "secrets.h"
#include <WiFiClientSecure.h>
#include <MQTTClient.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <time.h>

// Display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C

// Button pins
#define DOWN_BUTTON 12
#define SELECT_BUTTON 13

// Sensor pins
#define VOLTAGE_SENSOR_PIN 34
#define ACS_PIN 35
#define REF_VOLTAGE 3.3
#define ADC_RESOLUTION 4096.0

// Voltage sensor resistors
#define R1 30000.0
#define R2 7500.0
const float FACTOR = 0.100;
const float ADC_SCALE = 4095.0;
const float VCC = 4.0;
const int SAMPLES = 100;

// WiFi credentials
const char* ssid = "wifiname";
const char* password = "wifipassword";

// NTP server and time offset
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 19800; // GMT +5:30 for IST

// Screen state
enum ScreenState {
  HOME,
  SETTINGS,
  RESET_CONFIRM,
  WIFI_SETUP,
  CALIB