Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Powered Fuel Level Indicator with OLED Display

Image of ESP32-Powered Fuel Level Indicator with OLED Display

Circuit Documentation

Summary

This circuit is designed to interface an ESP32C3 Supermini microcontroller with an OLED display, multiple pushbuttons, and a potentiometer. The circuit allows for the reading of the potentiometer value to determine a fuel level, which is then displayed on the OLED screen. The pushbuttons can be used to reset the fuel level or perform other actions.


Component List

1. ESP32C3 Supermini

  • Description: A compact microcontroller with Wi-Fi and Bluetooth capabilities.
  • Pins: GPIO05, GPIO06, GPIO07, GPIO08, GPIO09, GPIO10, GPIO20, GPIO21, GPIO00, GPIO01, GPIO02, GPIO03, GPIO04, 3.3V, GND, +5V

2. OLED 1.3"

  • Description: A small OLED display used for visual output.
  • Pins: GND, VCC, SCL, SDA

3. Pushbutton

  • Description: A momentary switch used for user input.
  • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)

4. Potentiometer

  • Description: A variable resistor used to adjust the voltage level.
  • Pins: GND, Output, VCC

5. Resistor (20k Ohm)

  • Description: A passive component that limits current flow.
  • Pins: pin1, pin2

6. Resistor (5k Ohm)

  • Description: A passive component that limits current flow.
  • Pins: pin1, pin2

Wiring Details

ESP32C3 Supermini

  • GPIO05 connected to Pin 3 (out) of Pushbutton

  • GPIO06 connected to Pin 3 (out) of Pushbutton

  • GPIO07 connected to Pin 3 (out) of Pushbutton

  • GPIO08 connected to SDA of OLED 1.3"

  • GPIO09 connected to SCL of OLED 1.3"

  • GPIO00 connected to Output of Potentiometer

  • GPIO01 connected to pin1 of Resistor (5k Ohm)

  • 3.3V connected to VCC of Potentiometer and VCC of OLED 1.3"

  • GND connected to GND of Pushbutton, GND of Potentiometer, and GND of OLED 1.3"


Pushbutton

  • Pin 4 (out) connected to GND of ESP32C3 Supermini

  • Pin 4 (out) connected to pin1 of Resistor (20k Ohm)

  • Pin 4 (out) connected to Pin 4 (out) of Pushbutton


Potentiometer

  • GND connected to GND of ESP32C3 Supermini

  • Output connected to GPIO00 of ESP32C3 Supermini

  • VCC connected to 3.3V of ESP32C3 Supermini


Resistor (20k Ohm)

  • pin1 connected to GND of ESP32C3 Supermini

  • pin2 connected to Pin 4 (out) of Pushbutton


Resistor (5k Ohm)

  • pin1 connected to GPIO01 of ESP32C3 Supermini

  • pin2 connected to GND of ESP32C3 Supermini


Documented Code

ESP32C3 Supermini Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Potentiometer Code

/*
 * This code reads the potentiometer value to determine the fuel level and
 * displays the remaining fuel and estimated distance on an OLED screen.
 * Pushbuttons can be used to reset the fuel level or perform other actions.
 */

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define POT_PIN A0
#define BUTTON1_PIN 5
#define BUTTON2_PIN 6
#define BUTTON3_PIN 7

void setup() {
  pinMode(POT_PIN, INPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);
  pinMode(BUTTON3_PIN, INPUT_PULLUP);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Initializing...");
  display.display();
  delay(2000);
}

void loop() {
  int potValue = analogRead(POT_PIN);
  float fuelLevel = map(potValue, 0, 1023, 0, 100);
  float distance = fuelLevel * 10; // Assume 10 km per unit of fuel

  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Fuel Level: ");
  display.print(fuelLevel);
  display.print("%");
  display.setCursor(0, 10);
  display.print("Distance: ");
  display.print(distance);
  display.print(" km");
  display.display();

  if (digitalRead(BUTTON1_PIN) == LOW) {
    // Reset fuel level or perform other actions
  }
  if (digitalRead(BUTTON2_PIN) == LOW) {
    // Perform other actions
  }
  if (digitalRead(BUTTON3_PIN) == LOW) {
    // Perform other actions
  }

  delay(500);
}

This documentation provides a comprehensive overview of the circuit, detailing each component, its connections, and the code used for operation.