📜 ⬆️ ⬇️

Bluetooth voltmeter based on arduino

Hi, Habr! Today I want to continue the theme of "crossing" arduino and android. In a previous publication I talked about a bluetooth typewriter , and today we’ll talk about DIY bluetooth voltmeter. Another such device can be called a smart voltmeter, “smart” voltmeter or just a smart voltmeter, without quotes. The latter name is incorrect from the point of view of Russian grammar, nevertheless it is often found in the media. Voting on this topic will be at the end of the article, and I propose to start with a demonstration of the operation of the device, in order to understand what the article is about.

Disclaimer: The article is designed for the average arduino amateur, who is usually not familiar with programming under android, so, like in the previous article, we will be able to create a smartphone application using the Inventor 2 Android visual development environment.
To make a DIY bluetooth voltmeter, we need to write two programs relatively independent of each other: a sketch for arduino and an application for android. Perhaps we’ll start with a sketch.
First of all, you should know that there are three basic options for measuring voltage with the help of arduino, regardless of where you need to display information: to the com-port, to the screen connected to the Arduino, or to a smartphone.
The first case: measuring voltage up to 5 volts. Here, one or two lines of code are enough, and the voltage is applied directly to the pin A0:
int value = analogRead (0); // read readings from A0
voltage = (value / 1023.0) * 5; // true only if Vcc = 5.0 volts
The second case: a voltage divider is used to measure voltages greater than 5 volts. The scheme is very simple, code too.

Sketch
int analogInput = A0;
float val = 0.0;
float voltage = 0.0;
float R1 = 100000.0; // Battery Vin-> 100K -> A0
float R2 = 10000.0; // Battery Gnd -> Arduino Gnd and Arduino Gnd -> 10K -> A0
int value = 0;

void setup () {
Serial.begin (9600);
pinMode (analogInput, INPUT);
}

void loop () {
value = analogRead (analogInput);
val = (value * 4.7) / 1024.0;
voltage = val / (R2 / (R1 + R2));
Serial.println (voltage);
delay (500);
}

Arduino uno
Bluetooth module
The third case. When you need to get more accurate about voltage, you should use not the supply voltage, which can vary slightly when powered from acb, for example, but the voltage of the Arduino internal stabilizer is 1.1 volts. The circuit is the same, but the code is slightly longer. I will not analyze this option in detail, since it is already well described in thematic articles, and the second method is quite enough for me, since I have a stable power supply from the usb port of the laptop.
So with the voltage measurement, we figured out, now let's move on to the second half of the project: the creation of an android application. The application will be made directly from the browser in the visual development environment of Android-based applications App Inventor 2. Go to the appinventor.mit.edu/explore website, log in with your Google account, click the create button, new project, and create something like this by dragging and dropping design:
I made the graphics very simple, if someone wants more interesting graphics, let me remind you that for this you need to use .png files with a transparent background instead of .jpeg files.
Now go to the Blocks tab and create the application logic there like this:

If everything worked out, you can click the Build button and save .apk to my computer, and then download and install the application on your smartphone, although there are other ways to fill the application. here is someone more comfortable. In the end, I got this application:

I understand that very few people use the App Inventor 2 visual development environment for Android applications in their projects, so there may be a lot of questions about working in it. To remove some of these questions, I made a detailed video on how to make such an application from scratch (you need to go to YouTube to watch):

PS Collection of more than 100 training materials on arduino for beginners and pros here
PPS Online course on arduino to giktaimes here.
Well, at the end of the vote I promised in the beginning of the article.

')

Source: https://habr.com/ru/post/253175/


All Articles