This project demonstrates precision power monitoring using the STM32F103C6 microcontroller’s ADC in conjunction with the ACS712 Hall Effect-Based Current Sensor.
The ACS712 provides accurate current sensing, while the STM32 ADC captures high-resolution analog values, enabling developers to build reliable real-time power monitoring solutions. By integrating these two components, embedded systems can efficiently measure and analyze power consumption across applications such as industrial automation and IoT deployments.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (8 MHz clock)
- ADC1 Configuration:
-
Channel: IN9
-
Mode: Continuous Conversion
-
Regular Conversion Mode: Enabled
-
Number of Conversions: 1
-
External Trigger: Software Start
-
Sampling Time: 1.5 Cycles
- UART1 Configuration:
-
Mode: Asynchronous
-
Baud Rate: 115200
-
Word Length: 8 bits
-
Parity: None
-
Stop Bits: 1
- Generate initialization code in STM32CubeIDE
Key Functions
- ACS712 Initialization
-
void ACS712_Init(void);
-
Configures the ADC channel for continuous current measurement.
- Read Current Value
-
float Read_ACS712_Current(void);
-
Reads ADC value, converts it to current (A), and returns the measurement.
- Main Loop
float current = Read_ACS712_Current();
printf("Current: %.2f A\r\n", current)
Required Components:
- STM32F103C6 microcontroller
- ACS712 current sensor
- Battery & Load (e.g., resistor or capacitor)
- Virtual Terminal (UART display)
- DC Ammeter
Steps:
- Create a new Proteus project.
- Add components: STM32F103C6, ACS712, Battery, Capacitor/Load.
- Add Virtual Terminal and DC Ammeter.
- Connect UART1 (PA9 → TX) to Virtual Terminal.
- Wire ACS712 output to ADC1 Channel 9 (PA1).
- Add Power & Ground terminals.
- Load the .hex file from CubeIDE into STM32.
- Run simulation and observe real-time current readings on the Virtual Terminal and DC Ammeter.
That's all!
If you have any questions or suggestions don't hesitate to leave a comment below
Comments