Open Green Energy

Open Source DIY Projects on Green energy

How to Measure Current Using XIAO ESP32 and ACS758 Sensor | A step by step guide

 

In this article, we will see how to Measure Current Using XIAO ESP32 and ACS758 Sensor.

Current measurement is an essential aspect of various electronic projects and systems, particularly in power measurement and control applications. In this blog, we will explore how to use the ACS758 Hall Effect-based linear current sensor in conjunction with the XIAO ESP32 microcontroller for accurate current measurement.

We will walk you through the necessary steps, from connecting the hardware to writing and uploading the code to your ESP32. We will start by introducing the basic concepts of current measurement and the principles behind the ACS758 sensor. We will then move on to the hardware and software requirements for setting up a current measurement system using XIAO ESP32 and ACS758 sensor. We will provide a step-by-step guide on how to connect the sensor to the XIAO ESP32 board and how to write a simple code to read the current data on the Serial monitor. We will also cover some practical tips and tricks for calibrating the sensor and optimizing its performance.

Whether you are a hobbyist, a student, or a professional engineer, this blog post will provide you with the knowledge and skills you need to measure current using XIAO ESP32 and ACS758 sensor. So, let’s get started and discover the power of current measurement with XIAO ESP32 and ACS758 sensor!

Note: You may also like our previous post on Solar Charge Controller

Now as I say this you may wonder, Why this is required?

Well here is the answer.

Measuring current using ACS758 sensors can be useful in many different applications, such as

Energy monitoring: By measuring the current flowing through an electrical circuit, you can monitor the energy usage of a device or system. This can be useful in applications such as home automation, where you may want to track the energy consumption of different appliances.  Solar photovoltaic (PV) systems is an excellent choice for monitoring and managing the energy generated by your solar panels. By measuring the current flowing from the solar panels to the battery or load, you can gather important information about the efficiency and performance of your solar PV system. You may see my post on DIY Solar Panel Monitoring System – V1.0

Motor control: Measuring the current flowing through a motor can help you monitor its performance and ensure that it is operating correctly. This can be useful in applications such as robotics or industrial automation.

Power management: By monitoring the current draw of a device, you can optimize its power consumption and extend its battery life. This can be useful in applications such as portable electronics or IoT devices.

Fault detection: Measuring the current flowing through a circuit can help you detect faults or malfunctions, such as short circuits or overloads. This can be useful in applications such as electrical safety systems or automotive electronics.

 

Bill Of Materials ( BOM )

 

SL No
Components Quantity Buying Link
1 XIAO ESP32 1 Amazon | Aliexpress
2 ACS758 1  Amazon
3 Breadboard 1 Amazon | Aliexpress
4 Jumper wires Around 20 Amazon | Aliexpress

Overview Of ACS758 Current Sensor

 

The ACS758 is a highly accurate and linear current sensor with a wide sensing range. It is available in different current ranges, such as ±50A, ±100A, and ±200A. Some versions are bidirectional sensors and the others are unidirectional. Bidirectional means that the sensor can be used to measure current flow in both directions, they are most used with AC loads (it may be used also with DC loads). Unidirectional means the sensor can sense current flow in one direction only, this type is suitable for DC loads. The IC is housed in a small, surface-mount package and provides a ratiometric analog voltage output, which is easy to interface with microcontrollers.

For more details on ACS758, you may go through the Datasheet

 

ACS758 Markings:

The chip I have has the markings:    ACS758LCB-050B   ( This is the default chip on breakout boards )

The 050 means that the current capability is 50 amps. You can get other versions in the range of 50- 200Amps.

The B in LCB means bi-directional i.e.  ±50Amps. You can get a unidirectional version (050U) where you can only measure current in one direction.

The L in LCB can be changed to K or E. It refers to the operational temperature range ( -40°C – 85°C ).

 

ACS758 Pinout Diagram:

To better understand the ACS758, let’s dive deeper into its pinout diagram and the functionality of each pin.

XIAO ESP32 and ACS758 Sensor

  1. Vcc (Pin 1): This is the power supply pin of the ACS758. It requires a supply voltage of 3.0V to 5.5V, depending on the specific model. To ensure stable operation, it is recommended to use a decoupling capacitor (typically 0.1µF) between the Vcc and GND pins.
  2. VIOUT (Pin 2): This is the analog voltage output pin of the ACS758. It provides a ratiometric output voltage proportional to the current flowing through the sensor. The voltage at this pin can be measured using an ADC channel of a microcontroller, such as the XIAO ESP32.
  3. IP+ (Pin 3) and IP- (Pin 4): These are the current input pins of the ACS758. The current to be measured flows through these pins, and they are connected to the primary conductor of the current sensor. The pins are labeled as IP+ and IP-, indicating the direction of current flow for positive output voltage.
  4. FILTER (Pin 5): This pin is used to connect an external capacitor for noise filtering. The recommended capacitor value is typically 1nF. Connecting a capacitor to this pin can help reduce high-frequency noise and improve the accuracy of the sensor’s output.
  5. GND (Pin 6): This is the ground pin of the ACS758. It should be connected to the ground plane of the system for proper operation.

 

Why ACS758 Over the Most Popular Current Sensor ACS712

The ACS758 and ACS712 are both popular Hall-effect-based linear current sensors from Allegro Microsystems. They have their advantages and disadvantages, which make them suitable for different applications. In this comparison, we will highlight the key differences between the two sensors to help you make an informed decision when selecting the appropriate current sensor for your project.

  1. Sensing Range: The ACS758 is available in various current sensing ranges, such as ±50A, ±100A, and ±200A. In contrast, the ACS712 comes in three different versions: ±5A, ±20A, and ±30A. The ACS758 has a wider sensing range, making it suitable for applications with higher current requirements.
  2. Sensitivity: The ACS758 typically has a higher sensitivity compared to the ACS712. The sensitivity of the ACS758 ranges from 20 to 60 mV/A, depending on the specific model. The ACS712 has a sensitivity of 185 mV/A, 100 mV/A, or 66 mV/A for the 5A, 20A, and 30A versions, respectively. Higher sensitivity allows for more accurate current measurements, especially at lower current levels.
  3. Supply Voltage: The ACS758 operates with a supply voltage range of 3.0V to 5.5V, while the ACS712 requires a 5V supply voltage. The lower minimum supply voltage requirement of the ACS758 makes it more compatible with low-voltage microcontrollers and systems.
  4. Package and Size: The ACS712 comes in a smaller surface-mount package which is more compact, while the ACS758 is available in a larger through-hole package.
  5. Noise Filtering: The ACS758 includes an external filter pin that can be used to connect a capacitor for high-frequency noise filtering. This feature can improve the accuracy of the sensor’s output in noisy environments. The ACS712 does not have a dedicated external filter pin.
  6. Price: The ACS758 is generally more expensive than the ACS712 due to its higher performance and wider sensing range. However, the additional cost might be justifiable depending on the specific requirements of your application.

If you need a wider sensing range, higher sensitivity, or a more compact package, the ACS758 might be the better choice. However, if you are looking for a more affordable option with a lower sensing range, the ACS712 could be a suitable alternative.

 

Overview Of  XIAO ESP32-C3 Board

 

 

The XIAO ESP32-C3 is a compact and powerful microcontroller board based on the ESP32-C3 chip, which is a cost-effective, highly integrated System-on-Chip (SoC) solution from Espressif Systems. The ESP32-C3 is built on the RISC-V architecture, which provides a highly efficient and flexible platform for IoT applications. It offers a rich set of features, including Wi-Fi and Bluetooth Low Energy (BLE) capabilities, making it suitable for various IoT projects.

If you are interested to know more about the XIAO ESP32-C3 board, please check out my earlier post on How to Use ADS1115 16-Bit ADC Module with XIAO ESP32C3

Example Project

In this example, we will use the ACS758 current sensor to measure the current flowing through a light bulb powered by a 12V battery using the ACS758 current sensor. Here, I’m going to use a bidirectional sensor with a rated DC current of 50A, its full name is ACS758LCB-050B. Since this sensor is bidirectional, it allows us to measure AC and DC currents with a typical sensitivity of 40 mV/A. However, you can use any other ACS758 versions as per your requirement and use the above Selection Guide table to find out the sensitivity.

Step 1: Building the circuit

 

 

 

 

 

Connect the 12V battery to the light bulb:

  • Connect the positive terminal of the 12V battery to one terminal of the light bulb.
  • Connect the other terminal of the light bulb to the ACS758’s IP+ pin (where the current flows in).
  • Connect the IP- pin of the ACS758 (where the current flows out) to the negative terminal of the 12V battery

Connect the ACS758 to the XIAO ESP32:

  • Connect the VCC pin of the ACS758 to the 3.3V pin of the XIAO ESP32
  • Connect the GND pin of the ACS758 to the GND pin of the XIAO ESP32.
  • Connect the VIOUT pin of the ACS758 to an analog input pin (D1, for example) of the XIAO ESP32.

 

ACS758 XIAO ESP32
VCC 3V3
GND GND
OUT D1

Power the XIAO ESP32:

  • Connect the XIAO ESP32 to a power source (e.g., USB cable or separate power supply). Make sure the power supply’s voltage matches the input voltage requirements of the XIAO ESP32.

Step2: Upload the code to the XIAO ESP32:

After the circuit is complete we can head over to the programming part.

  • Install the necessary libraries and board definitions for the XIAO ESP32 in the Arduino IDE.
  • Write the code to read the analog input pin, convert the reading to the corresponding current value, and print the result on the serial monitor.
  • Upload the code to the XIAO ESP32.

Before writing the code you have to understand the Offset Voltage and Sensitivity of ACS758 current sensor.

Offset Voltage: When the ACS758 is connected to a supply voltage of 5V and when the primary current is zero, then the output of the device is 2.5V (it’s just VCC/2), this voltage is called Offset Voltage.

Sensitivity: The sensitivity is defined as the change in device output in response to a 1 A change through the primary conductor. With a supply of 5V, the sensitivity is 40mV/A.

For example when a single supply is used and with a primary current of 5 Amps then the device output is Voffset + 5 x 0.04V = 2.5V +0.2V = 2.7V

 

Step 3: Testing and Calibration

 

 

 

Once the code is uploaded, open the serial monitor to see the current measurements. Initially, the readings might be slightly off due to sensor offsets or other factors.  If you have a multimeter or clamp meter, you can measure the actual current directly and compare it to the value read by the ACS758. In our case, the actual current measured by the clamp meter is 209mA whereas the serial monitor reading is 213mA which is very close to the actual reading.

If there’s a significant difference, you can adjust the OFFSET_VOLT and SENSITIVITY variables in the code to get a more accurate reading.

Note:  By using the ESP32 WiFi capability you can use serial monitor data to analyze and visualize through various platforms, such as ThingSpeak, Grafana, or Blynk web applications.

Conclusion

In conclusion, measuring current is an essential aspect of electronic projects, and the XIAO ESP32 and ACS758 sensor combination provides a simple and efficient way to achieve this. By following the steps outlined in this tutorial, We’ve successfully set up the breadboard circuit to measure the current of a LED light bulb by using the ACS758 current sensor

With the proper connections, programming, and calibration, you can measure current accurately using this setup. It’s essential to take the necessary precautions when working with electricity and ensure that you follow safety guidelines when building and testing your project.

Happy tinkering!

Related Posts

1. How to Use ADS1115 16-Bit ADC Module with XIAO ESP32C3

2.DIY Solar Panel Monitoring System – V1.0

3. Arduino Energy Meter – V2.0

Related Posts

Fig-12.2: Wire Gauge Systems Fig-12.4: Cable Sizing Example       Fig-12.5: DC Cable Size Chart   Fig-13.1: Battery and

Read More