Bluetooth voltmeter based on arduino. Digital voltmeter on Arduino with connection to a PC via a serial port Arduino voltmeter with data output to a computer

Multifunctional Arduino assemblies are of wide interest to fans of homemade electronically programmable devices, allowing them to bring interesting ideas to life.

The main advantage of ready-made Arduino circuits is the unique block-modular principle: each board can be added with additional interfaces, endlessly expanding the possibilities for creating different projects.

Arduino modules are built on a universal microcontroller with its own bootloader, which makes it easy to flash it with the necessary program code, without the use of additional devices. Programming is carried out in standard C++ language.

One of the simplest examples of using Arduino can be the implementation, based on this assembly, of a high-precision DC voltmeter with a measurement range from 0 to 30 V.

Arduino analog inputs are designed for a constant voltage of no more than five volts, therefore, using them at voltages exceeding this value is possible with a voltage divider.


Connection diagram of Areduino via voltage divider

A voltage divider consists of two resistances connected in series. It is calculated using the formula:

External USB connector in car radio

A useful diagram is presented for those who like to experiment with Arduino. This is a simple digital voltmeter that can reliably measure DC voltage in the range 0 - 30V. The Arduino board, as usual, can be powered by a 9V battery.

As you probably know, Arduino's analog inputs can be used to measure DC voltage in the range of 0 - 5V and this range can be increased,
using two resistors as a voltage divider. The divider will reduce the measured voltage to the level of the Arduino analog inputs. And then the program will calculate the real voltage value.

The analog sensor on the Arduino board detects the presence of voltage at the analog input and converts it into digital form for further processing by the microcontroller. In the figure, voltage is supplied to the analog input (A0) through a simple voltage divider consisting of resistors R1 (100 kOhm) and R2 (10 kOhm).

With these divider values, the Arduino board can be supplied with voltage from 0 to
55V. At input A0 we have the measured voltage divided by 11, i.e. 55V / 11=5V. In other words, when measuring 55V at the Arduino input, we have a maximum allowable value of 5V. In practice, it is better to write the range “0 - ​​30V” on this voltmeter so that it remains
Safety margin!

Notes

If the display readings do not coincide with the readings of an industrial (laboratory) voltmeter, then it is necessary to measure the value of resistances R1 and R2 with an accurate instrument and insert these values ​​instead of R1=100000.0 and R2=10000.0 in the program code. Then you should measure the real voltage between the 5V and “Ground” pins of the Arduino board with a laboratory voltmeter. The result will be a value less than 5V, for example, it will be 4.95V. This real value should be inserted in the line of code
vout = (value * 5.0) / 1024.0 instead of 5.0.
Also, try to use precision resistors with a 1% tolerance.

Resistors R1 and R2 provide some protection against increased input voltages. However, remember that any voltages above 55V can damage the Arduino board. In addition, this design does not provide other types of protection (against voltage surges, polarity reversal or overvoltage).

Digital voltmeter program

/*
DC Voltmeter
An Arduino DVM based on voltage divider concept
T.K.Hareendran
*/
#include
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) – see text!
int value = 0;
void setup())(
pinMode(analogInput, INPUT);
lcd.begin(16, 2);
lcd.print(“DC VOLTMETER”);
}
void loop()
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) {
vin=0.0;//statement to quash undesired reading !
}
lcd.setCursor(0, 1);
lcd.print(“INPUT V= “);
lcd.print(vin);
delay(500);
}

Schematic diagram of Arduino-voltmeter

List of components

Arduino Uno board
100 kOhm resistor
10 kOhm resistor
100 ohm resistor
10kOhm Trimmer Resistor
LCD display 16?2 (Hitachi HD44780)

Schematic diagram of a homemade bipolar voltmeter on Arduino Uno and with a 1602A display. In the article “Double voltmeter on ARDUINO UNO” (L.1), the author proposed a description of the voltmeter and a program for simultaneous measurement and indication of two constant voltages. Which is very convenient if you need to simultaneously measure two constant voltages and compare them.

This may be required, for example, when repairing or setting up a DC voltage stabilizer in order to measure the voltage at its input and output, or in other cases.

However, there are circuits with bipolar power supply, when the voltage at some point in the circuit relative to the common “zero” can be either positive or negative.

Schematic diagram

Here we describe the modification of the circuit and program so that the device can measure and indicate both positive and negative voltage.

To begin with, the measured voltages are supplied to two analog inputs A1 and A2. There are six analog inputs in total, A0-A5, you could select any two of them. In this case, A1 and A2 are selected. The voltage on analog ports can only be positive and only in the range from zero to the microcontroller supply voltage, that is, nominally, up to 5V.

The output of the analog port is converted into digital form by the microcontroller's ADC. To get the result in units of volts, you need to multiply it by 5 (by the reference voltage, that is, by the supply voltage of the microcontroller) and divide by 1024.

Rice. 1. Schematic diagram of a bipolar voltmeter on Arduino Uno and 1602A.

In order to be able to measure voltages greater than 5V, or rather, greater than the supply voltage of the microcontroller, because the actual voltage at the output of the 5-volt stabilizer on the ARDUINO UNO board may differ from 5V, and usually a little lower, you need to use conventional resistive dividers at the input.

Here these are voltage dividers across resistors R1, R3 and R2, R4. But what if the voltage needs to be measured less than zero? In this case, there is only one way out of the situation - to raise the level of the input zero. Ideally, you need half the supply voltage, that is, up to 2.5V. In this case, 2.5V data will be added to the input voltage.

Then, programmatically, simply subtract this voltage from the measured one. But, this will require an additional source of this voltage. In principle, this is not difficult to do, but there is a simpler solution.

In addition to the 5V voltage stabilizer, the ARDUINO UNO board has a 3.3V voltage source. So it can be used as a “virtual zero” for entry.

Changes in the circuit are visible in Figure 1. Compared to the first option, the input “zero” is simply rearranged from the common zero to the +Z.ZV source. Therefore, when the input voltage is positive, at the input it is more than 3.3V (but not more than 5V - this is the upper limit of measurement), and when negative - less than 3.3V (but not less than OV - this is the lower limit of measurement).

An increase in the measurement limits (modulo) is achieved by a resistive divider, and the indication of the actual input voltage supplied to X2 and X3 is achieved by software subtraction of a value of 3.3V from the voltage at the microcontroller inputs.

The program is shown in Table 1. This can be seen in the lines:

volt=(vout*5.0/1024.0-3.3)/0.048 ;

voltl=(voutl*5.0/1024.0-3.3)/0.048;

The number 3.3 is exactly this voltage of the “virtual zero” input.

In these lines, the number 5.0 is the voltage at the output of the stabilizer of the ARDUINO UNO board. Ideally, it should be 5V, but for the voltmeter to work accurately, this voltage must first be measured. Connect the power source and measure the +5V voltage at the POWER connector of the board with a fairly accurate voltmeter.

What happens, then enter in these lines instead of 5.0. The same applies to the voltage +3.3V - it needs to be measured at the board connector, because in fact it may differ slightly from 3.3V. For example, if "5V" is actually 4.85V and "3.3V" is actually 3.32V the lines would look like this:

volt=(vout*4.85/1024.0-3.32)/0.048;

voltl=(voutl*4.85/1024.0-3.32)/0.048;

At the next stage, you will need to measure the actual resistances of resistors R1-R4 and determine the K coefficients (indicated as 0.048) for these lines using the formulas:

K1 = R3 / (R1+R3) and K2 = R4 / (R2+R4)

Let's say K1 = 0.046, and K2 = 0.051, so we write:

volt=(vout*4.85/1024.0-3.32)/0.046;

voltl=(voutl*4.85/1024.0-3.32)/0.051;

Thus, changes must be made to the program text according to the actual voltage at the output of the 5-volt and 3.3-volt stabilizers of the ARDUINO UNO board, and according to the actual division coefficients of the resistive dividers.

After this, the device will work accurately and will not require any adjustment or calibration. When measuring a negative voltage on the LCD indicator, there will be a minus sign in front of the voltage value in the corresponding line. When measuring positive voltage, there is no sign.

By changing the division coefficients of the resistive dividers (and, accordingly, the “K” coefficients), you can make other measurement limits, and not necessarily the same for both inputs.

I would like to remind you that the H1 type 1602A liquid crystal display module is connected to the digital ports D2-D7 of the ARDUINO UNO board. The LCD indicator is powered by a 5V voltage stabilizer located on the 5V voltage stabilizer board.

In order for the indicator to interact with ARDUINO UNO, you need to load a subroutine into the program to control it. Such routines are called "libraries", and there are many different "libraries" in the ARDUINO UNO software package. To work with an LCD indicator based on the HD44780, you need the LiquidCrystal library. Therefore, the program (Table 1) begins by loading this library:

This line gives the command to load this library into ARDUINO UNO. Then, you need to assign ARDUINO UNO ports that will work with the LCD indicator. I chose ports D2 through D7. You can choose others. These ports are assigned by the line:

LiquidCrystal led(2, 3, 4, 5, 6, 7);

After which, the program proceeds to the actual operation of the voltmeter.

Karavkin V. RK-06-17.

Literature: 1. Karavkin V. - Double voltmeter on ARDUINO UNO. RK-01-17.

Idea

Idea devices for measuring voltage, current, capacity, discharge, and maybe charge arose a long time ago and not only for me. You can find many toys called USB Tester (Doctor) for testing various USB devices. I’m interested in a somewhat more universal device, independent of the interface, but simply designed for certain voltages and currents. For example, 0 - 20.00v, 0 - 5.00a, 0 - 99.99Ah. As for functions, I see it like this

  • Displays current voltage and current, that is, a volt-ampere meter. In principle, you can immediately reflect the power.
  • Counting and displaying accumulated capacity. In ampere hours and most likely in watt hours.
  • Process time display
  • And, most likely, adjustable lower and upper voltage cut-off thresholds (discharge and charge limits)

Development

To implement calculations and measurements we need a controller. I remembered this idea as part of my acquaintance with Arduino, so the controller will be a simple popular Atmega328 and it will be programmed in the environment Arduino. From an engineering point of view, the choice is probably not the best - the controller is a bit fat for the task, and its ADC cannot be called measuring, but... we'll try.

  • We won't solder much in this project. As a basis, we’ll take a ready-made Arduino Pro Mini module, since the Chinese are ready to supply them for $1.5 retail.
  • The display device will be a 1602 display - another $1.5. I have an option with an I2C interface module, but in this project it is not really needed ($0.7).
  • For development we need a breadboard. In my case, this is a small BreadBoard for $1.
  • Of course, you will need wires and a number of resistors of different values. For a 1602 display without I2C, you also need to select the contrast - this is done with a variable resistor of 2 - 20 kOhm.
  • To implement an ammeter you will need a shunt. To a first approximation, it could be a 0.1 Ohm, 5 W resistor.
  • To implement automatic shutdown, you will need a relay with contacts designed for the maximum current of the device and a voltage equal to the supply voltage. To control the relay you need an NPN transistor and a protective diode.
  • The device will be powered from an external power source, obviously at least 5 V. If the power supply varies greatly, then an integrated stabilizer type 7805 will also be required - it will determine the relay voltage.
  • When Arduino Pro Mini requires a USB-TTL converter to upload the firmware.
  • For setup you will need a multimeter.

Voltmeter

I am implementing a simple voltmeter with one range of approximately 0 - 20V. This note is important because the ADC of our controller has a 10-bit capacity (1024 discrete values), so the error will be at least 0.02 V (20 / 1024). To implement the hardware, we need an analog input of the controller, a divider made of a pair of resistors and some kind of output (a display in the finished version, a serial port can be used for debugging).

The principle of ADC measurement is to compare the voltage at the analog input with the reference VRef. The ADC output is always integer - 0 corresponds to 0V, 1023 corresponds to voltage VRef. The measurement is implemented by a series of sequential voltage readings and averaging over the period between updates of the value on the screen. The choice of reference voltage is important because it defaults to the supply voltage, which may not be stable. This does not suit us at all - we will take as a basis a stable internal reference source with a voltage of 1.1V, initializing it by calling analogReference(INTERNAL). We will then calibrate its value using the multimeter readings.

The diagram on the left shows a variant with direct control of the display (it is simply controlled - see the standard LiquidCrystal\HelloWorld sketch). On the right is the I2C option, which I will use further. I2C allows you to save on wires (of which there are 10 in the usual version, not counting the backlight). But this requires an additional module and more complex initialization. In any case, the display of characters on the module must first be checked and the contrast adjusted - to do this, you simply need to display any text after initialization. The contrast is adjusted by resistor R1, or a similar resistor of the I2C module.

The input is a 1:19 divider, which allows you to get a maximum voltage of about 20V at Vref = 1.1 (usually a capacitor + a zener diode is placed parallel to the input for protection, but this is not important to us for now). Resistors have a spread, and so does the reference Vref of the controller, so after assembly we need to measure the voltage (at least the supply) in parallel with our device and a reference multimeter and select Vref in the code until the readings match. It’s also worth noting that any ADC has a zero offset voltage (which spoils the readings at the beginning of the range), but we won’t go into that for now.

It will also be important to separate the supply and measuring ground. Our ADC has a resolution slightly worse than 1mV, which can create problems if the wiring is incorrect, especially on a breadboard. Since the layout of the module board has already been done and we only have to select the pins. The module has several “ground” pins, so we must make sure that power enters the module through one “ground”, and measurements through the other. In fact, to make changes, I always use the ground pin closest to the analog inputs.

To control I2C, a version of the LiquidCrystal_I2C library is used - in my case, the specific pinout of the I2C module is indicated (the Chinese produce modules with different controls). I also note that I2C in Arduino requires the use of pins A4 and A5 - on the Pro Mini board they are not located on the edge, which is inconvenient for prototyping on the BreadBoard.

Source

#include #include // Simple voltmeter with i2c display 1602. V 16.11 // Settings for i2c display 1602 with non-standard pinout #define LCD_I2C_ADDR 0x27 #define BACKLIGHT 3 #define LCD_EN 2 #define LCD_RW 1 #define LCD_RS 0 #define LCD_D4 4 #define LCD_D5 5 #define LCD_D6 6 #define LCD_D7 7 LiquidCrystal_I2C lcd(LCD_I2C_ADDR,LCD_EN,LCD_RW,LCD_RS,LCD_D4,LCD_D5,LCD_D6,LCD_D7); // Reading update time, ms (200-2000) #define REFRESH_TIME 330 // Analog input #define PIN_VOLT A0 // Internal reference voltage (select) const float VRef = 1.10; // Input resistive divider coefficient (Rh + Rl) / Rl. IN<-[ Rh ]--(analogInPin)--[ Rl ]--|GND const float VoltMult = (180.0 + 10.0) / 10.0; float InVolt, Volt; void setup() { analogReference(INTERNAL); // Инициализация дисплея lcd.begin (16, 2); lcd.setBacklightPin(BACKLIGHT, POSITIVE); lcd.setBacklight(HIGH); // включить подсветку lcd.clear(); // очистить дисплей lcd.print("Voltage"); } void loop() { unsigned long CalcStart = millis(); int ReadCnt = 0; InVolt = 0; // Чтение из порта с усреднением while ((millis() - CalcStart) < REFRESH_TIME) { InVolt += analogRead(PIN_VOLT); ReadCnt++; } InVolt = InVolt / ReadCnt; // Смещение 0 для конкретного ADC (подобрать или отключить) if (InVolt >0.2) InVolt += 3; // Convert to volts (Value: 0..1023 -> (0..VRef) scaled by Mult) Volt = InVolt * VoltMult * VRef / 1023; // Output data lcd.setCursor (0, 1); lcd.print(Volt); lcd.print("V "); )

This article provides an interesting diagram for those who like to experiment and Arduino. It features a simple digital voltmeter that can safely measure DC voltage between 0 and 30 V. The Arduino board itself can be powered by a standard 9 V supply.



As you know, using the Arduino analog input you can measure voltage from 0 to 5 V (with a standard reference voltage of 5 V). But this range can be expanded by using a voltage divider.


The divider reduces the measured voltage to a level acceptable for the analog input. Then specially written code calculates the actual voltage.



The analog sensor in Arduino detects the voltage at the analog input and converts it into a digital format that can be read by the microcontroller. We connect a voltage divider formed by resistances R1 (100K) and R2 (10K) to analog input A0. With these resistance values, up to 55 V can be supplied to the Arduino, since the division coefficient in this case is 11, so 55V/11 = 5V. In order to be sure that measurements are safe for the board, it is better to measure voltage in the range from 0 to 30 V.



If the display readings do not match the verified voltmeter readings, use a precision digital multimeter to find the exact values ​​of R1 and R2. In this case, in the code you will need to replace R1=100000.0 and R2=10000.0 with your own values. Then you should check the power supply by measuring the voltage on the board between 5V and GND. The voltage can be 4.95 V. Then in the code vout = (value * 5.0) / 1024.0 you need to replace 5.0 with 4.95. It is advisable to use precision resistors with an error of no more than 1%. Remember that voltage above 55V can damage the Arduino board!



#include LiquidCrystal lcd(7, 8, 9, 10, 11, 12); int analogInput = 0; float vout = 0.0; float vin = 0.0; float R1 = 100000.0; // resistance R1 (100K) float R2 = 10000.0; // resistance R2 (10K) int value = 0; void setup())( pinMode(analogInput, INPUT); lcd.begin(16, 2); lcd.print("DC VOLTMETER"); ) void loop())( // read the analog value value = analogRead(analogInput); vout = (value * 5.0) / 1024.0; vin = vout / (R2/(R1+R2)); if (vin<0.09) { vin=0.0;// обнуляем нежелательное значение } lcd.setCursor(0, 1); lcd.print("INPUT V= "); lcd.print(vin); delay(500); }


Elements used:


Arduino Uno board
Resistor 100 KOhm
Resistor 10 KOhm
100 ohm resistor
Potentiometer 10KOhm
LCD display 16×2