Maple Lesson 08 - A multimeter with the range of 0 to 5 volts

From Microduino Wiki
Jump to: navigation, search

Objective

We have introduced the reading (0-1024) of the analog port before. Now, we will use the analog port of microduino to make a voltmeter with the range of 0-5 V.

Notice: The circuit design of the experiment has no relatively complicated protection circuit. So please don't use more than two AA batteries and don't use the circuit to measure the lithium battery or other power supply!!

Equipment

Microduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules.

  • Other hardware equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • 1kΩ resistor one
    • USB Data cable one


==Schematic

Program

const int analogInPin = 14;
 
float sensorValue = 0;        // value read from the port
float Voltage=0;
 
void setup() {
    pinMode(analogInPin, INPUT_PULLDOWN);
//Use the internal pull-down, and set the GND to measure port which can avoid the Interface dangling received interference.

}
 
void loop() {
    // read the analog in value:
    sensorValue = analogRead(analogInPin);
    // map it to the range of the analog out:
    Voltage = sensorValue*5/4095;
 
    SerialUSB.print("Voltage = ");
    SerialUSB.print(Voltage);
    SerialUSB.println("V ");
    delay(500);
}


Serial monitor

Use to communicate between Maple and STM32.

  • Click the serial monitor button and pop up a serial port monitoring interface.
  • SerialUSB will print your value that you want, easy to debug.
    • If you want to print specific character, you can refer :“SerialUSB.print("XXX");”,XXX is the character you want to print;
    • If you want to print changed character, you can refer :“SerialUSB.print(XXX);”,XXX is the character you want to print;
    • If you want to print in a new row, you can refer :“SerialUSB.println(XXX);”

Result

When the measured voltage changed, refresh the date every 1s. If there is a gap between two voltage values, this is normal. Because this is a low accuracy test.

Video