Lithium monitor

Hello

i am new to arduino and one of my first projects is the lithium battery monitor.

I have a basic knowledge on lcd and inputs and outputs but i searched the web with no results.

I would like to make a monitor that would just measure the voltage on A0 and VIN and display everything on a 16X2 LCD via I2C.

Can any one help me with the connections and the code because i have tried almost everything i know with no real results.

I just need the LCD to display the Voltage and the percentage and maybe a little battery indicator.

Thank you

i have tried almost everything i know with no real results.

So post that as a starting point.

Tell us what you expected it to do, and what it actually did.

/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.begin(16, 2);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (4.2 / 1023.0);
// print out the value you read:
Serial.println(voltage);
lcd.setCursor(0, 0);
lcd.print(“Voltage is:”);
lcd.print(voltage);
lcd.print(“V”);
delay(1500);
}

Now, when you've added the [code][/code] tags, how about you tell us the

Tell us what you expected it to do, and what it actually did.

bit ?

I connected the lcd and the probes to gnd and A0.

I want to measure the voltage of a 18650 cell with it.

The display must display for example:
Voltage is: 4.15V
:IIIII|

Voltage is: 3.9V
:IIII |

Voltage is: 3.7V
:III |

Voltage is: 3.5V
:II |

Voltage is: 3.3V
:I |

Voltage is: 3.1V
: |

Ok some progress but if i go under 3.8V the displaz still shows only 75%

/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.begin(16, 2);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (4.82 / 1023.0);
// print out the value you read:
Serial.println(voltage);
lcd.setCursor(0, 0);

if (voltage > 4.0 ){
lcd.print(“100%”);
}
else if (voltage > 3.8 || voltage < 4.0 ){
lcd.print(“75%”);
}
else if (voltage > 3.6 || voltage < 3.8 ){
lcd.print(“50%”);
}
else if (voltage > 3.4 || voltage < 3.6 ){
lcd.print(“25%”);
}
else if (voltage > 3.4 || voltage < 3.0 ){
lcd.print(“0-25%”);
}
delay(1500);
lcd.clear();
}

else if (voltage > 3.8 || voltage < 4.0 ){

Don’t you mean else if (voltage > 3.8 && voltage < 4.0 ){

I finally did it if some one wants to use the code they can do so

/*
  ReadAnalogVoltage
  Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.
*/
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//konec
byte newChar1[8] = {
  B11111,
  B00001,
  B11101,
  B11101,
  B11101,
  B11101,
  B00001,
  B11111
};

//Vmes
byte newChar2[8] = {
  B11111,
  B00000,
  B11111,
  B11111,
  B11111,
  B11111,
  B00000,
  B11111
};

//yacetek
byte newChar3[8] = {
  B01111,
  B01000,
  B01011,
  B11011,
  B11011,
  B01011,
  B01000,
  B01111
};
//PRAZEN
byte newChar4[8] = {
  B11111,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11111
};

//Prazna kapica
byte newChar5[8] = {
  B01111,
  B01000,
  B01000,
  B11000,
  B11000,
  B01000,
  B01000,
  B01111
};

//Prazen konec
byte newChar6[8] = {
  B11111,
  B00001,
  B00001,
  B00001,
  B00001,
  B00001,
  B00001,
  B11111
};

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  lcd.begin(16, 2);
}

// the loop routine runs over and over again forever:
void loop() {
  lcd.createChar(0, newChar1);
  lcd.createChar(1, newChar2);
  lcd.createChar(2, newChar3);
  lcd.createChar(3, newChar4);
  lcd.createChar(4, newChar5);
  lcd.createChar(5, newChar6);
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (4.82 / 1023.0);
  // print out the value you read:
    Serial.println(voltage);
  lcd.setCursor(0, 0);
  lcd.print("Voltage: ");
  lcd.print(voltage);
  lcd.print("V");

  lcd.setCursor(0, 1);
  
  if (voltage > 4.1 ){
  
    lcd.print("100%     ");
    lcd.write(byte(2));
    lcd.write(byte(1));
    lcd.write(byte(1));
    lcd.write(byte(1));
    lcd.write(byte(0));
  }
  
  if (voltage > 3.8 && voltage < 4.1 ){
  
    lcd.print("75%      ");
    lcd.write(byte(4));
    lcd.write(byte(1));
    lcd.write(byte(1));
    lcd.write(byte(1));
    lcd.write(byte(0));
  }
  
  if (voltage > 3.5 && voltage < 3.8 ){
  
    lcd.print("50%      ");
    lcd.write(byte(4));
    lcd.write(byte(3));
    lcd.write(byte(1));
    lcd.write(byte(1));
    lcd.write(byte(0));
  }
  if (voltage > 3.3 && voltage < 3.5 ){
  
    lcd.print("25%      ");
    lcd.write(byte(4));
    lcd.write(byte(3));
    lcd.write(byte(3));
    lcd.write(byte(1));
    lcd.write(byte(0));
  }
  
  if (voltage > 3.0 && voltage < 3.3 ){
  
    lcd.print("0-25%    ");
    lcd.write(byte(4));
    lcd.write(byte(3));
    lcd.write(byte(3));
    lcd.write(byte(3));
    lcd.write(byte(0));
  }
  if (voltage > 2.5 && voltage < 3.0 ){
  
    lcd.print("Warning! ");
    lcd.write(byte(4));
    lcd.write(byte(3));
    lcd.write(byte(3));
    lcd.write(byte(3));
    lcd.write(byte(5));
  }
    delay(500);
    lcd.clear();
}