MicroBit Meter

Tell us the story of your project: 

The project pairs the BBC Microbit with external conditioning electronics to create a simple voltmeter that displays the resulting voltage in numerical values.

It was the follow up to a wholly electronic circuit were discrete LED's indicated the voltage range but not the values, this project enables actual values to be diaplayed but at the same time keeping it simple.

The external electronics where already a tried and trusted method which just needed a means to display the result simply. Without recourse to using a DMM which would have defeated the object of the excercise.

It was one of a number of projects undertaken become more familiar with the BBC Microbit.

The external electronics were soldered to a small piece of Veroboard including 2 serial in line sockets to connected to a Pronto-PIC breakout board into which the Microbit sits

 

 

 
 
 
 
 
 
 

 

How-to: 

The project uses the MicroBit to measure DC voltages <=20V, using the Analogue to Digital Converter (ADC).

There are 6 ADC's available on the MicroBit but this project will only utilise one.

The ADC by default has a maximum input voltage range of 0 to 3.3 converted into a bit range of 0 to 1023.

However, for this project we want to make use of it over the voltage range 0 to 20V but not allow the voltage to exceed the maximum input voltage range.. In order to prevent damage the user should ensure all precautions are taken ti ensure the maximum ADC input voltage is not  exceeded.

We achieve this using a potential divider circuit on the ADC input to present a fixed percentage of the input voltage to the ADC. In this case 10% of the input voltage is applied to the ADC input.

Therefore, with a 20V voltage the ADC will see 2V maximum. 

Capping the input maximum to 20V allows headroom  to ensure we are well away from the maximum ADC input. Additionally, in the event that >20V, is applied in the order of ~28V this will activate  2 series connected LED's to clamp the input. 

How do we realise the circuit to do this:

Taking the basic potentail divider circuit which consists on 2 resistors in series.

Vout = (R2/(R1+R2))*Vin

If R1 = 10K,  R2 = 2K7 & Vin  = 20V

Vout = (2k7/(2k7+10k))*20

Vout = 4.252V but this is >3.3V ADC maximum so we need to reduce this ADC input voltage.

This is achieved with two series resistors  (R3 & R4), in parallel with R2, which also allows fine adjustment of the output voltage for calibration purposes 

Therefore:

R2p = 1/((1/R3)+(1/R4))

Vout = (R2p/(R1+R2p))*Vin
R4 is a variable resistor with maximum value of 2K
By adjusting R4 we can trim Vout to an exact value.
Vout = 2V with Vin =20V
 
 
We have a circuit to condition the input voltage next we require some coding to take the input and convert it for output and display.
 
BLOCKS is used to code the micoccontroller although is is just one of many applications that can be used.
This is can display the code graphically and textually, the javascript code is displayed below as its easier to display this in this editor
 
input.onButtonPressed(Button.A, function () {
    basic.clearScreen()
    vin = 0
    vin = pins.analogReadPin(AnalogPin.P0)
    if (vin < 0) {
        basic.showString("ERR")
    } else {
        basic.showString("" + convertToText((vin - 3) * vpbit * 10 + 0).substr(0, 6) + "V")
    }
})
input.onButtonPressed(Button.B, function () {
    basic.clearScreen()
    vin = 0
    vin = pins.analogReadPin(AnalogPin.P0)
    basic.showNumber(vin)
})
let vin = 0
let vpbit = 0
basic.showString("Bchk")
vpbit = 3.3 / 1023
basic.forever(function () {
    basic.showString("<A")
})
 
There are 3 main sections to the code.
1: Initialisation - vin which is used to capture the bit data corresponding to the input voltage, vpbit which is the voltage per bit based on ADC maximum and full scale bit range, menu indicating that button A should be pressed which displays the voltage.
 
2: Button A - Clear the screen, reset Vin, pass the input from AnalogPin, P0, perform an error check if there are no errors calculate the value and display in volts. Its multiplied by 10 as the potential divider divides the input by 10.
Note vin-3 this is the offset error compensation derived from comparing the real value to the calculated value.
Three is a compromise as the error may vary over the extremes of the range but in this experiment worst care error was 5.1%. If necessary spot compensation could be applied over specific ranges to minimise errors either as discrete values or using a trendline calculation
 
3: Button B - Clear the screen, reset Vin, pass the input from AnalogPin, P0 and display the bit data without conversion. Used to compare actual to calculated to enable offset compensation.
 
Calibration.
Firstly, the external electronic circuit is calibrated using a known fixed voltage from a variable supply or fixed voltage battery. 
Set the input voltage and verify with a DMM.
Verify the output of the circuit and adjust R4 until the output is 1/10th of the input voltage.
Then with the Microbit connected and powered up 
Press button A to get the voltage, ideally the voltage will be displayed as the input voltage but will likely measure too high or low.
Press button B to get the bit value.
The following calculation displays the corresponding bit value based on the voltage to be measured.
 
bit = ((Vin/(3.3/1023)/10)
Therefore for Vin = 1V
bit = ((1/(3.3/1023)/10) = 31
If the bit value is higher (35), than the difference (35-31) is subtracted from Vin and if low the difference is added.
Calibration complete.
 
Measurements can begin.
 
Using the current values of resistors the burden current is 1.8mA.
Therfore, any circuit this is connected to will have this current drawn from the circuit.
If you are measuring a battery or a power supply output this may not be an issue but if measuring at a circuit node it may affect the circuit opperation due to cirrent being robbed from the circuit.
This effect can be minimised by increasing all the resistors by 10 resulting in a burden current of 180uA.
This can be minimised further by isolating the circuit with a buffer amplifier.
 
 
 
 
 
 
 
Difficulty: 
Duration: 
Collaborators: 
uk4dshouse
Number of Forks: 
0
Tools: 
Name: 
Soldering Iron
Quantity: 
1
Name: 
Wire Cutters
Quantity: 
1
Name: 
DC Power Supply
Quantity: 
1
Name: 
digital multimeter
Quantity: 
1
Materials: 
Name: 
Resistor 10K ohm
Quantity or amount: 
1
Name: 
Resistor, 1K Ohm
Quantity or amount: 
1
Name: 
Resistor, 2k7
Quantity or amount: 
1
Name: 
2K, Potentiometer
Quantity or amount: 
1
Name: 
Low current LED, RED
Quantity or amount: 
2
Boards & Kits: 
Name: 
Pronto-Pic Bread:Bit
Quantity: 
1
Name: 
Veroboard
Quantity: 
1
Name: 
BBC Microbit
Quantity: 
1
Team Members: 
Team member name: 
uk4dshouse
What role did this person play on the project?: 
Project Lead
Public
Sort Order: 
0
Teaser: 
This project uses a BBC MicroBit and a small selection of components to create a simple DC volt meter.
Aha! moment: 
Keeping it simple
Uh-oh! moment: 
A better display would improve usability.
Show & Tell video as default: 
Creation Date: 
Sunday, January 26, 2020 - 01:46