ข้ามไปที่เนื้อหาหลัก

ส่งงานครั้งที่ 6

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

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ส่งงานครั้งที่ 9

Gyro Sensor Interfacing Gyro Sensor  คือเซ็นเซอร์ที่มีไว้สำหรับตรวจจับลักษณะการหมุน โ ดยเป็นการตรวจจับแบบ  3  แกน  (3-Axes) อุปกรณ์ Arduino Uno MPU-6050 10K POT Jumper wire Breadboard USB cable Power supply Diagram Code #include<LiquidCrystal.h> //ประกาศเมื่อใช้จอ LiquidCrystal lcd(8,9,10,11,12,13); //ขาที่ต่อจอ #include <Wire.h> #include <MPU6050.h> #define period 10000 MPU6050 mpu; int count=0; char okFlag=0; byte degree[8] = {   0b00000,   0b00110,   0b01111,   0b00110,   0b00000,   0b00000,   0b00000,   0b00000 }; void setup()  {   lcd.begin(16,2);   lcd.createChar(0, degree);   Serial.begin(9600);   Serial.println("Initialize MPU6050");   while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))   {     lcd.clear();     lcd.print("Device not Found"...

ส่งงานครั้งที่ 16

Smoke Detector Using MQ2 อุปกรณ์ Arduino UNO Smoke Detector Arduino Shield (Self Designed) Power Supply Smoke Sensor (MQ2) Resistors (10K and 1K) Buzzer 16x2 LCD 10k POT LED LM358 Burg strips Diagram Code #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define buzzer 9 #define sensor A0   #define load_Res 10   #define air_factor 9.83                                                   float SmokeCurve[3] ={2.3,0.53,-0.44};    // (x, y, slope) x,y พิกัดของจุดหนึ่งและความลาดชันระหว่างสองจุด                                                                                     ...

ส่งงานครั้งที่ 1

Traffic Light Project Code int emergency = 0; void setup() {   pinMode(3, OUTPUT);  //ตั้งให้ขา 3 เป็น Output   pinMode(4, OUTPUT);  //ตั้งให้ขา 4 เป็น Output   pinMode(5, OUTPUT);  //ตั้งให้ขา 5 เป็น Output   pinMode(13, OUTPUT); //ตั้งให้ขา 13 เป็น Output   pinMode(2, INPUT); //ตั้งให้ขา 2 เป็น Input } void loop() {   emergency = digitalRead(2); //ตั้งตัวแปรชื่อ emergency ให้มีค่าเท่ากับค่าที่อ่านได้จากขา 2   if (emergency == LOW) {   // ถ้าemergencyมีค่าเป็น Low ให้ทำงานตามระบบ R10G10Y3 digitalWrite(13, LOW); digitalWrite(3 , HIGH); delay(10000); digitalWrite(13, HIGH); digitalWrite(3 ,LOW); digitalWrite(5 ,HIGH); delay(10000); digitalWrite(5 ,LOW); digitalWrite(4 ,HIGH); delay(3000); digitalWrite(4 , LOW);   }     else{ //ถ้า emergency มีค่าเป็น High ให้ ไฟเขียวติดกระพริบ    digitalWrite(3, HIGH);     digitalWrite(13, LOW);     delay(1000);   ...