Arduino Saat Isı Nem LCD
Arduino nano ile Lcd ekrana gerçek zamanlı saat, ısı ve nem bilgilerini yazdırma projesi
Gerekli Malzemeler;
Arduino Nano
DS1307 Rtc modül
LCD 1602 LiquidCrystal
DHT21 sensör
CR2032 pil
5K pot
220 ohm direnç
Buton
Arduino ile LCD pin bağlantısı;
Nano Pin LCD Pin
GND = RV
9 = E
8 = RS
7 = 7
6 = 6
5 = 5
4 = 4
10 = A
Arduino ile DS1307 Pin Bağlantısı;
Nano Pin RTC Pin
A4 = SDA
A5 = SCL
Arduino ile DHT21 Sensör Bağlantısı;
Nano Pin DHT21 Pin
13 = 2
LCD Ekranın Kontrastını 5K pot yardımıyla ayarlıyoruz. LCD.nin Vo (C) pinini pot.un orta ucuna bağlıyoruz. pot.un diğer bacaklarını arduinonun +5v ve gnd bacaklarına bağlıyoruz.
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
DHT dht(13, DHT21);
RTC_DS1307 rtc;
int _day, _month, _year, _hour24, _hour12, _minute, _second, _dtw;
int hr24;
String st;
char nameoftheday[7][12] = {"Paz", "Pts", "Sal", "Car", "Per", "Cma", "Cts"};
char month_name[12][12] = {"Oca","Sub", "Mar", "Nis", "May", "Haz", "Tem", "Agu", "Eyl", "Eki", "Kas", "Ara"};
int i=0;
unsigned long zaman1 =0;
unsigned long zaman2 =0;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //-> select the pins used on the LCD panel
void setup() {
pinMode(10, OUTPUT);
lcd.begin(16, 2); //-> start the LCD library
dht.begin();
lcd.setCursor(0,0);
lcd.print("Arduino morhanx");
lcd.setCursor(0,1);
lcd.print(" Saat ISI Nem ");
delay(1000);
lcd.clear();
if (! rtc.begin()) {
lcd.setCursor(0,0);
lcd.print("RTC Not Found ");
while (1);
}
if (! rtc.isrunning()) {
lcd.setCursor(0,0);
lcd.print("RTC is NOT ");
lcd.setCursor(0,1);
lcd.print("running!!!!");
// ilk yüklemede alt satırı güncelleyip arduinoyu yükleyin. sonrasında aynı satırı yorum yapıp değişikliklerinizi yapın
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// üst satır saati güncellemezse ilk yüklemede alt satırı güncelleyip arduinoyu yükleyin. sonrasında aynı satırı yorum yapıp değişikliklerinizi yapın
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop() {
digitalWrite(10, HIGH);
zaman1= millis();
if (zaman1-zaman2 >=5000)
{
if(i==0) { i=1 ;} else { i=0 ;}
lcd.clear();
zaman2=millis();
}
if(i==0)
{
saatGoster();
}
else
{
dhtGoster();
}
}
//---ubroutine to retrieve or update the time and date from DS1307
void GetDateTime() {
DateTime now = rtc.now();
_day=now.day();
_month=now.month();
_year=now.year();
_hour24=now.hour();
_minute=now.minute();
_second=now.second();
_dtw=now.dayOfTheWeek();
hr24=_hour24;
if (hr24>12) {
_hour12=hr24-12;
}
else if (hr24==0) {
_hour12=12;
}
else {
_hour12=hr24;
}
if (hr24<12) {
st="AM";
}
else {
st="PM";
}
}
void saatGoster()
{
GetDateTime(); //-> Retrieve or update the time and date from DS1307
//------------------------------------------Displays Time 24 Hour Format
lcd.setCursor(4,0);
if (_hour24<10) {
lcd.print("0");
lcd.print(_hour24, DEC);
}
else {
lcd.print(_hour24, DEC);
}
lcd.print(":");
if (_minute<10) {
lcd.print("0");
lcd.print(_minute, DEC);
}
else {
lcd.print(_minute, DEC);
}
lcd.print(":");
if (_second<10) {
lcd.print("0");
lcd.print(_second, DEC);
}
else {
lcd.print(_second, DEC);
}
lcd.setCursor(0,1);
lcd.print(nameoftheday[_dtw]);
lcd.print(",");
lcd.setCursor(5,1);
if (_day<10) {
lcd.print("0");
lcd.print(_day, DEC);
}
else {
lcd.print(_day, DEC);
}
lcd.print("-");
lcd.print(month_name[_month-1]);
lcd.print("-");
lcd.print(_year, DEC);
delay(100);
}
void dhtGoster()
{
float temperature, humidity;
humidity = dht.readHumidity();
temperature = dht.readTemperature();
char tempF[6];
char humF[6];
dtostrf(temperature, 5, 1, tempF);
dtostrf(humidity, 2, 0, humF);
lcd.setCursor(0, 0); // KURSORU LCD 1. SATIR 1. SUTUNUNA AL
lcd.print("SICAKLIK: ");
lcd.setCursor(0, 1);// KURSORU LCD 2. SATIR 1. SUTUNUNA AL
lcd.print("NEM: ");
lcd.setCursor(9, 0);
lcd.print(tempF);// SICAKLIK YAZ
lcd.print(" c");
lcd.setCursor(9, 1);
lcd.print(humF);// NEM YAZ
lcd.print(" %");
delay(2000);
}



Yorumlar
Yorum Gönder