Hello,
I am developing a custom board using the Mega2560 chip. and i am stuck reading to analog voltage. One of the voltages is the voltage coming out of a bank of 5 1.5F capacitors (through A1) connected in parallel. These capacitors serve as the source of power for the board and are feed through a screw terminal which will have a solar panel connected to it. Right now I am using a bench power supply. The other one is to measure the voltage of a 12v battery (A2).
The problem is first that no matter what the capacitor voltage is analogRead(A1) reports 514 if the voltage is more than 4.9V and if i Lower the voltage to anything below 4.8 it goes to 512 but it does not move from there.
A2 is even stranger. the actual battery voltage measured with a multimeter is approximately 12.39V. If the source voltage to the board is above 4.8V the analogRead(A2) starts at 380 but it steady declines to lower and lower values ie 200. However, when I lower the supply voltage to the board it immediately starts going up and in a few minutes it can go over 800.
There is no connection between pin A1 and A2. This board is manufactured by jlcpcb and is the second batch that exibits this weird behavious so i have to assume that is not a bad chip and it has something to do with my design. I just can see it.
Here is my code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
Serial.println(" STARTING" );
lcd.begin();
lcd.backlight();
analogReference(DEFAULT);
}
void loop() {
// put your main code here, to run repeatedly:
int v = analogRead(A1);
delay(100);
Serial.print(" v=" );
Serial.println(v );
int e=analogRead(A2);
lcd.setCursor(0, 1);
lcd.print("C=");
lcd.print(v);
lcd.print(" E=");
lcd.print(e);
delay(1000);
}
Here is the part of the design that represents A1
A1 is connected to the label BATT_MEAS
As for A2, here is the design, is a simple voltage divider VEM is connected to A2
Any suggestions would be very much appreciated