I've searched the web for the code to make my voltage sensor work. If you've struggled like me to find a working code, look no farther. This code is the simplest way to make the sensor work. The delay is very high on my code because I don't need it to update the voltage as fast. This is a charge regulator for a battery and 5 seconds to run the loop is as fast as I need it to be.
#include <Wire.h>
int val11;
float val2;
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
}
void loop()
{
val11=analogRead(0);
val2=val11/39.85;
Serial.print("Voltage: ");
Serial.println(val2,4);
delay(5000);
}