// |———————————————————————————————————————————————————————|
// | made by Arduino_uno_guy 11/13/2019 |
// | https://create.arduino.cc/projecthub/arduino_uno_guy|
// |———————————————————————————————————————————————————————|
#include <LiquidCrystal_I2C.h>
//#include Wire.h
#define led_pin 13
//initialize the liquid crystal library
//the first parameter is the I2C address
//the second parameter is how many rows are on your screen
//the third parameter is how many columns are on your screen
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// 設定 A0 為輸入
pinMode(A0, INPUT);
pinMode(led_pin, OUTPUT);
//initialize lcd screen
lcd.init();
// turn on the backlight
lcd.backlight();
}
void loop() {
//wait for a second
delay(1000);
// tell the screen to write on the top row
//lcd.setCursor(0,0);
// tell the screen to write “hello, from” on the top row
//lcd.print("Hello, From");
// tell the screen to write on the bottom row
lcd.setCursor(0,1);
// tell the screen to write “Arduino_uno_guy” on the bottom row
// you can change whats in the quotes to be what you want it to be!
lcd.print("Arduino_uno_guy");
printVolts();
}
void printVolts()
{
int sensorValue = analogRead(A0); //read the A0 pin value
float voltage = sensorValue * (5.00 / 1023.00) * 2; //convert the value to a true voltage.
lcd.setCursor(0,0);
lcd.print("voltage = ");
lcd.print(voltage); //print the voltage to LCD
lcd.print(" V");
if (voltage < 6.50) //set the voltage considered low battery here
{
digitalWrite(led_pin, HIGH);
}
}Voltage divider is not
working in wokwi due to no support.