It works perfectly, the use I give it is to measure the battery voltage and thus know the charge level.
My problem is that I am going to switch from Arduino UNO to ESP32, and ESP32 does not have an analog pin like the Arduino UNO which has multiple pins. So... I'm looking for a solution with digital pins.
The sensor you have is fine as you know. It has a 1-5 ratio so 5V in gives you 1V out. The A/D on the other micros will not tolerate 5V. You will have to check what is allowed on the one you pick. Then divide your input voltage by 5 to see if it is in range of the A/D. If not you will have to either change one of the resistors or purchase a new one. The current modules do give you voltage but it is a waste of money to purchase them for just that.
Note: I am not an expert, in Arduino it says: A0, A1, A2, etc. I'm guessing ESP32 doesn't have it because it doesn't say so, but, I'm reading it says ADC, is that the analog pin that does the same thing as A0?
Because if so I use the same code that I had in Arduino Uno.
I dare not connect anything so as not to burn my ESP32.
Be sure to research the caveats of the ESP32's A/Ds. For example, ADC2 is unavailable once you've started WiFi. It's also difficult to get stable 12-bit readings with WiFi running due in part because the WROOM/WROVER modules don't separate logic and analog grounds.
Ask:
If at the input vin- and vin+ (the ones that are not connected above in the image), if I connect it to my battery, is the voltage that the following code will tell me the voltage of my battery?
#include "Wire.h"
#include "Adafruit_INA219.h"
Adafruit_INA219 ina219;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
if (! ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
}
Serial.print("BV"); Serial.print("\t"); // Bus Voltage
Serial.print("SV"); Serial.print("\t"); // Shunt Voltage
Serial.print("LV"); Serial.print("\t"); // Load Voltage
Serial.print("C"); Serial.print("\t"); // Current
Serial.println("P"); // Power
}
void loop() {
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print(busvoltage); Serial.print("\t");
Serial.print(shuntvoltage); Serial.print("\t");
Serial.print(loadvoltage); Serial.print("\t");
Serial.print(current_mA); Serial.print("\t");
Serial.println(power_mW);
delay(1000);
}
I'm just asking to see if I can measure the voltage or not before I buy it. I think so, but I want to ask because I'm not an expert.
The INA219 will do what you ask, but I never used the board with an ESP32.
I suppose it will work with this or with code for an ESP32.
busvoltage will give you battery voltage if you connect +12volt to V+ of the INA219.
You must of course also have 12volt ground connected to INA219 ground.
Leo..
The problem is that the tutorials don't show exactly what I'm looking for, just one battery. That is, only measure the voltage, not the current that X device consumes.
I can try without knowing when the order arrives, but I'm afraid of burning something because I'm inexperienced, that's why I'm looking for assurance and that's why I ask:
Like I said before... I want to measure the battery voltage, that is my current main problem, because I want to know the charge level. Later I will see how to know how much is being consumed, but now I am only concerned with the voltage.
Thanks for your answer. I already know that volts can be read, thanks to @Wawa. Now my question is regarding the connections. After I have it well connected I will experiment with the code, but I must have it well so as not to burn anything.
I just want to know if this is how I ask, I want to know that I am right. Because I see that there are 2 connections of vin + and vin -. Where does the battery go? In the connections above or in those below?