ESP32-S3 DevKit, 74HC4051 and voltsensor. EPS32 stop running when plug/unplug battery

3 min read 24-09-2024
ESP32-S3 DevKit, 74HC4051 and voltsensor. EPS32 stop running when plug/unplug battery


The ESP32-S3 DevKit, combined with a 74HC4051 analog multiplexer and a voltage sensor, can create exciting projects by allowing multiple sensor readings through a single pin. However, many users encounter an issue where the ESP32 stops functioning when the battery is plugged or unplugged. This article will explore this problem, analyze its causes, and provide potential solutions.

Original Code for the Problem Scenario

To give context to this issue, consider a simplified version of the code that one might use with an ESP32-S3 DevKit and a 74HC4051:

#include <Arduino.h>

// Define the pin connections
const int muxSelectPinA = 12; // MUX select pin A
const int muxSelectPinB = 13; // MUX select pin B
const int muxSelectPinC = 14; // MUX select pin C
const int analogPin = 34;      // Analog input pin

void setup() {
    Serial.begin(115200);
    pinMode(muxSelectPinA, OUTPUT);
    pinMode(muxSelectPinB, OUTPUT);
    pinMode(muxSelectPinC, OUTPUT);
}

void loop() {
    // Your logic to read voltage from sensors goes here
}

Understanding the Problem

When the battery is plugged or unplugged, the ESP32 can unexpectedly reset or stop running. This behavior could stem from several factors including power supply stability, improper grounding, or a lack of decoupling capacitors.

Causes of the ESP32 Power Issue

  1. Power Supply Instability: The ESP32 requires a stable power supply, and sudden disconnections can lead to voltage spikes or drops that reset the microcontroller.

  2. Grounding Issues: If the ground connection is not consistent when plugging or unplugging the battery, it may lead to erratic behavior or resets.

  3. Capacitance: Capacitors can help smooth out voltage fluctuations. If they are not present, the abrupt changes in voltage when connecting/disconnecting the battery can cause a reset.

Possible Solutions

To address the problem of the ESP32 stopping when the battery is connected or disconnected, consider the following solutions:

  • Add Decoupling Capacitors: Place a capacitor (e.g., 1000uF electrolytic) across the power and ground terminals of the ESP32. This capacitor helps to buffer the voltage when the battery is connected or disconnected, providing a more stable supply.

  • Check Connections: Ensure all connections are secure. Loose connections can lead to unexpected behavior, especially with the MUX.

  • Use a Voltage Regulator: If you're powering your ESP32 with a battery, consider using a voltage regulator that can provide a steady voltage output. This can help eliminate voltage spikes or drops that might occur when the battery is plugged or unplugged.

  • Enable Brownout Detection: In your code, enable the brownout detection feature of the ESP32 to avoid unwanted resets caused by brownouts. You can do this by configuring it in the menuconfig.

menuconfig -> ESP32-specific -> Enable Brownout Detection

Additional Explanation

When working with electronics, understanding how the components interact is crucial. The 74HC4051 is an analog multiplexer, which allows you to read multiple analog signals with fewer pins. When using this component in conjunction with the ESP32-S3, you rely on a stable power source to ensure that the readings are accurate. The microcontroller's behavior is highly sensitive to power supply fluctuations, making the capacitors and stable connections crucial for smooth operation.

Practical Example

Imagine you are designing a weather station using this setup, where you want to read temperature, humidity, and light levels using various sensors connected through the 74HC4051. If your ESP32 resets every time you change the battery, it disrupts the entire data logging process, leading to gaps in your dataset. By implementing the solutions discussed, you can ensure that your station runs smoothly without interruptions.

Conclusion

The issue of the ESP32-S3 DevKit stopping when a battery is plugged or unplugged is common, yet solvable. By understanding the electrical characteristics of your components and ensuring a stable power supply, you can prevent unexpected resets and build reliable projects.

Useful Resources

By applying these strategies, you'll be well on your way to building robust projects with your ESP32-S3, 74HC4051, and voltage sensor!