LCD + LDR


code 1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int aVal=0,tempaVal=0;
void setup()
{

  lcd.begin(16,2);
}
void loop()
{
 aVal = analogRead(A0);

if (tempaVal != aVal)
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("LDR");
  lcd.setCursor(0,1);
  lcd.print(aVal);
  delay(300);
}
tempaVal = aVal;
}
ทดลอง
พอเอา ภาษา C ไปใส่ Arduino จะแสดงค่าความต้านทาน LDR ตามที่เราปรับ

code 2
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int aVal=0,tempaVal=0;
void setup()
{
  lcd.begin(16,2);
}
void loop()
{
  aVal = analogRead(A0);
  if (tempaVal != aVal)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(aVal);
    lcd.setCursor(0,1);
    if (aVal<100)
      lcd.print("Dark");
    else
      lcd.print("Light");
    delay(300);
  }
  tempaVal = aVal;
}
ทดลอง
พอเอา ภาษา C ไปใส่ Arduino จะแสดงค่าแสงที่ได้รับจาก LDR ตามที่เราปรับ ถ้าน้อยกว่า 100 จะขึ้นคำว่า Dark

ความคิดเห็น

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

Coin Validator เครื่องรับเหรียญ เครื่องหยอดเหรียญ Multi Coin รุ่น SG-6

Learning 7 Segment + Arduino