Battery Voltage Indicator
อุปกรณ์
- Arduino UNO
- 10 Segment LED Bar Graph
- LCD (16*2)
- Potentiometer-10k
- Resistor (100ohm-10;330ohm)
- Battery (to be tested)
- Connecting wires
- 12v adapter for Arduino
Circuit Diagram
Code
#include <LiquidCrystal.h> //เรียกใช้จอLCD
//กำหนดตัวแปร
const int rs = 12, en = 13, d0 = A0, d1 = A1, d2 = A2, d3 = A3;
LiquidCrystal lcd(rs, en, d0, d1, d2, d3);
const int analogPin = A4;
float analogValue;
float input_voltage;
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // อาร์เรย์แสดงขาของLED
int pinCount = 10; // จำนวนของLED
void setup()
{
Serial.begin(9600); // การรับส่งข้อมูล9600บิทต่อวินาที
lcd.begin(16, 2); //// ตั้งให้LCDมีขนาด16x2
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,INPUT);
lcd.print("Voltage Level");
}
void LED_function(int stage)
{
for (int j=2; j<=11; j++)
{
digitalWrite(j,LOW);
}
for (int i=1, l=2; i<=stage; i++,l++)
{
digitalWrite(l,HIGH);
//delay(30);
}
}
void loop()
{
// คำนวณปริมาณแบต
analogValue = analogRead (A4);
Serial.println(analogValue);
delay (1000);
input_voltage = (analogValue * 5.0) / 1024.0;
lcd.setCursor(0, 1);
lcd.print("Voltage= ");
lcd.print(input_voltage);
Serial.println(input_voltage);
delay(100);
if (input_voltage < 0.50 && input_voltage >= 0.00 )
{
digitalWrite(2, HIGH);
delay (30);
digitalWrite(2, LOW);
delay (30);
}
else if (input_voltage < 1.00 && input_voltage >= 0.50)
{
LED_function(2);
}
else if (input_voltage < 1.50 && input_voltage >= 1.00)
{
LED_function(3);
}
else if (input_voltage < 2.00 && input_voltage >= 1.50)
{
LED_function(4);
}
else if (input_voltage < 2.50 && input_voltage >= 2.00)
{
LED_function(5);
}
else if (input_voltage < 3.00 && input_voltage >= 2.50)
{
LED_function(6);
}
else if (input_voltage < 3.50 && input_voltage >= 3.00)
{
LED_function(7);
}
else if (input_voltage < 4.00 && input_voltage >= 3.50)
{
LED_function(8);
}
else if (input_voltage < 4.50 && input_voltage >= 4.00)
{
LED_function(9);
}
else if (input_voltage < 5.00 && input_voltage >= 4.50)
{
LED_function(10);
}
}
Credit By : https://circuitdigest.com/microcontroller-projects/battery-voltage-indicator-using-arduino-and-led-bar-graph
ความคิดเห็น
แสดงความคิดเห็น