I recently bought an S2 Mini and a Arudino Voltmeter 10 stücke/1pc intelligente elektronik dc 0 25v standard spannung sensor modul test elektronische steine smart roboter für arduino diy kit| | - AliExpress but can't get it to work.
Goal
I have an 3,7V Lipo Battery that I want to measure the voltage from. The actual voltage currently is 3,9V.
Wiring
I connected + and - to the Voltmeter PCB input and the outputs like this: - to S2 Mini ground, + unconnected and S to pin 2.
Since I am getting a reading, I guess the wiring doesnt seem to be the problem.
Interpreting the results
As far as I understand, the S2 mini does not really have a Pin to read analog voltages, but an ADC (analog to digital converter). Yet I read that you dont have to convert the numbers but use the code analogReadMilliVolts(2). So now, only the Voltmeter needs to be converted since it reduces the input of the battery.
On the product page it gives the code:
Float temp;
Val11 = analog read (1);
Temp = val11/4.092;
Val11 =(int)temp;//
Val2 =((val11 % 100)/10);
Serial.println(val2);
Programming
int val11;
int val2;
void setup() {
pinMode(2, INPUT);
Serial.begin(9600);
analogReadResolution(12);
}
void loop() {
float temp;
val11 = analogReadMilliVolts (2);
temp = val11/4.092;
val11 =(int)temp;//
val2 =((val11 % 100)/10);
Serial.println(val11);
Serial.println(val2);
delay(100); // delay in between reads for clear read from serial
}
Results
val11 gives me a value of 112 when battery is not connected and 201 when the battery is connected
val2 gives me 1 when batters is not connected and 0 when its connected
also I tried
int sensorValue = analogRead(2);
int analogVolts = analogReadMilliVolts(2);
but all give me weird numbers both when the battery is or is not connected
Question
How can I fix my code to get the voltage of my battery?