Measure CURRENT WITH Esp 32 AND CURRENT SENSOR
Title: Measuring AC Current Using a 30A Current Sensor with ESP32 and OLED Display
Introduction: In this blog, I'll guide you through a simple project to measure AC current using a 30A current sensor, the ESP32 microcontroller, and an OLED display. This setup is perfect for monitoring power usage, allowing you to keep track of current consumption in your home appliances or other electronics.
Let’s dive into the components, circuit setup, code, and step-by-step instructions for creating this handy current measurement system.
Components Needed:
- ESP32 Microcontroller: A powerful, low-cost microcontroller with WiFi and Bluetooth capabilities.
- 30A AC Current Sensor: Designed to measure AC current up to 30 amps. For this project, I’m using a non-invasive current sensor.
- 0.96" OLED Display (I2C): A compact display for real-time current reading.
- Jumper Wires: For connecting components.
Circuit Connections:
Component | ESP32 Pin |
---|---|
Current Sensor | 34 |
OLED Display SDA | 21 |
OLED Display SCL | 22 |
Power (VCC/GND) | 3.3V/GND |
Step-by-Step Circuit Setup:
Connect the Current Sensor: Attach the current sensor’s output to GPIO 34 on the ESP32. This analog pin will read the current signal.
Connect the OLED Display: Use the I2C protocol to connect the OLED display.
- SDA pin goes to GPIO 21
- SCL pin goes to GPIO 22
- VCC and GND pins on the display go to the 3.3V and GND pins on the ESP32
Code Explanation
Libraries: The
Adafruit_GFX
andAdafruit_SSD1306
libraries are essential for the OLED display. Make sure to install them in the Arduino IDE.Setup: In the
setup()
function, we initialize the Serial monitor and OLED. A startup message appears on the OLED display for a brief moment.Reading and Converting the Current:
- The
analogRead
function reads the raw sensor data on pin 34. - This reading is converted to voltage based on the ESP32’s 3.3V reference.
- We calculate the current from the voltage reading, subtracting the offset and dividing by the sensitivity of the current sensor (typically around 0.066V/A for a 30A sensor).
- The
Display and Serial Output: The calculated current is displayed on the OLED screen and printed to the Serial monitor.
Project Tips:
- Calibrate: Test the sensor by measuring a known load to check the accuracy of your readings. Adjust the sensitivity value if necessary.
- Safety First: When dealing with AC current, always prioritize safety. Ensure all connections are secure and keep your hands away from any live AC parts.
- Power Supply: For stable operation, power the ESP32 using an external USB power source or a dedicated power adapter.
Comments
Post a Comment