MICHAEL CADIZPaul Rodolf P. Castor
Published

Coin Cell Voltage Monitor

Developing a range volt meter that uses an ADC.

IntermediateFull instructions provided4 hours39
Coin Cell Voltage Monitor

Things used in this project

Hardware components

Coin Cell Battery CR2032
Coin Cell Battery CR2032
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 1M ohm
Resistor 1M ohm
×2

Story

Read more

Schematics

Pin Diagram

Code

main.c

C/C++
/* USER CODE BEGIN PV */
volatile uint16_t rawValue = 0;
volatile float sourceVoltage = 3.3;
volatile float halvedVoltage = 0;
volatile float voltage = 0;
/* USER CODE END PV */

////////////////////////////////////////////////////////////

/* USER CODE BEGIN 3 */
    HAL_ADC_Start(&hadc1);
    HAL_ADC_PollForConversion(&hadc1, 10);
    rawValue = HAL_ADC_GetValue(&hadc1);
    halvedVoltage = (rawValue * sourceVoltage) / 4095.0;
    voltage = halvedVoltage * 2;

    (void)voltage; 
}
/* USER CODE END 3 */

Credits

MICHAEL CADIZ
5 projects • 0 followers
Paul Rodolf P. Castor
21 projects • 9 followers

Comments