Hasan SAVUN Blog

Bir Elektronikçinin Günlüğü

Wifi Sıcaklık-Nem Dataloger

Wifi Sıcaklık-Nem Dataloger

Wifi Sıcaklık-Nem Dataloger

Merhaba,

Arduino ile yapılmış Wifi Sıcaklık-Nem Datalogerı anlatacağım.

Arduino Wifi ile servera bağlanarak sıcaklık ve nem bilgilerini kayıt etmektedir.

Server asp.net te yazılmıştır. burada ıp ve key bilgileri kontrol edilerek kayıt işlemi yapılmaktadır.


Malzemeler

2 adet Arduino Nano

esp8266

ds18b20 Sıcaklık ölçer

dh22 nem ölçer

ds3231 saat entegresi

1 adet P10 led panel

img_0128
img_0124
img_0132
  1. Kodları İndir
  2. Kodları indir

kodlar 2 bölümden oluşmaktadır.

  1. wifi dataloger
  2. P10 panel gösterme

1 ) Arduino Wifi Dataloger Kodlar

//*****************************************************************************************//
// SICAKLIK NEM DATALOGLER
// HASAN SAVUN
//
//
//*****************************************************************************************//

//*****************************************************************************************//
#define build 5
#define revision 3
//*****************************************************************************************//

// ARDUINO PIN USAGE
// D2 -> ESP8266 TX
// D3 -> 1k/2k (to GND) -> ESP8266 RX
// D4 -> diode, 4k7 (to 3.3v) -> ESP8266 RST
// D5 -> S1 >> 1. DS18b20 sıcaklık sensor
// D6 -> S2 >> DHT11 NEM
// D7 -> S3 >> 2. DS18b20 sıcaklık esnsörü
// D8 -> S4 >> kontak
// D9 -> S5 >> kontak
// D10 -> ARDUINO RESET
// D11 ->
// D12 ->

#include <avr/pgmspace.h> // for memory storage in program space
#include <stdlib.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/wdt.h>

//#define SSID “******”
//#define PASS “********”
//#define HOST “dataupdate.hasan-3e.net” // IP address of thingspeak.com
#define ESP8266rst 4 // ESP8266 reset pin
//String KEYstring = “GET /save.aspx?anahtar=”; // unique key for hingspeak.com channel
//#define anahtar “TRK1001”;
SoftwareSerial WiFiSerial(2, 3); // RX, TX (connected to ESP8266 TX/RX resp.)
String SSID,PASS;
String HOST = “oks.hasansavun.net”;
String KEYstring1 = “GET /”; // unique key for hingspeak.com channel
String KEYstring2 = “?anahtar=”; // unique key for hingspeak.com channel
String ID = “ESK2601”;
String SAYFA=”DataSave.aspx”;
char sensorler[5]={‘K’,’K’,’K’,’K’,’K’};
String sensors=””;
/*
String tempC,humid; // temperature and humidity strings “xx.x”
char buffer[10]; // buffer to create strings
float tmp,hum; // actual readings from DHT
*/

#include <OneWire.h> // OneWire kütüphanesini ekliyoruz.
OneWire ds(5); // 5. Dijital pinde.
OneWire ds2(7); // 5. Dijital pinde.
char buffer[10],sensor[1]; // buffer to create strings
float sicI = 10, nem = 50, sicF=100,sicF2=100,sen4=0,sen5=0; // actual readings from DHT
String sicS=””,nemS=””;
String yaz = “”;
int kalibrasyon=0,hata_ayiklama=0;

#include “DHT.h”
#define DHTPIN 6 // what digital pin we’re connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

// operation
int loopcount=540,conn,loopcount2=0; // loop counter (seconds)
int errorCnt=0; // error counter
boolean data_gonder=false,ayarlar=false;

//*****************************************************************************************//
// Initial Setup
//*****************************************************************************************//
void setup() {
//FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); // LED Strip
pinMode(8, INPUT); // sets the digital pin 7 as input
pinMode(9, INPUT); // sets the digital pin 7 as input
Serial.begin(9600);
Serial.println(F(“Turksat Sicaklik/Nem Kontrol Cihazi 2016 Hasan SAVUN”));
Serial.print(F(“Build “));
Serial.print(build);
Serial.print(F(“.”));
Serial.println(revision);
Serial.print(F(“Free RAM: “));
Serial.print(freeRam());
Serial.println(F(“B\r\n”));
dht.begin();

delay(1000);

EEPROM.write(210, 5); //5 ADET SENSOR ICIN KAYIT YAPILDI
//EEPROM_write(sensorler,5,210); //SENSORLER KAPATILDI

// ESP HAZIRLA
ayarlar=EpromAyarOku();
Sicaklik_Nem_Oku_Gonder();
if (ayarlar==true)
{
Serial.println(F(” “));
Serial.println(F(“*****************************************”));
Serial.println(F(“Kablosuz Ag Baslatiliyor….”));
Serial.println(F(“*****************************************”));
Serial.println(F(” “));
resetWiFiModule(); // reset WiFi module
startWiFiModule(); // start it up
connectWiFiModule(); // connect to local wifi
//updateTempHum();

}
else
{
Serial.println(F(“Dikkat Ayarlar tamamlanmamistir!!! Once ayarlari yukleyin.”));
}

Serial.println(F(” “));
Serial.println(F(“*****************************************”));
Serial.println(F(“Sistem ayarlamasi basarili… Basliyor…”));
Serial.println(F(“*****************************************”));
Serial.println(F(” “));

}

void(* resetFunc) (void) = 0; //declare reset function @ address 0

//*****************************************************************************************//
// MAIN LOOP
//*****************************************************************************************//
void loop() {
if (ayarlar==true)
{
if(errorCnt >= 10) { // if too many simultaneous errors
resetFunc(); //call reset
errorCnt=0;
resetWiFiModule(); // reset WiFi module
startWiFiModule(); // restart serial connection to module
connectWiFiModule(); // connect to local wifi
}

conn=0;
if(loopcount == 0) {
while (conn<=5)
{
if (!updateTempHum()) // sample, connect and upload data
{
Serial.println(F(“Data gonderilemedi !!!”));
delay(3000);
}
else
{
conn=10;
Serial.println(F(“Data basariyla gonderildi.”));
}
conn++;
}

}

if(loopcount2 == 1)
{
Sicaklik_Nem_Oku_Gonder();

}
}
delay(1000); // pulse data LED as seconds counter
//wdt_reset();
loopcount = (loopcount+1)%600;
loopcount2 = (loopcount2+1)%30;

}

// ********************************************************************************** //
// SUBROUTINES
// ********************************************************************************** //

// ********************************************************************************** //
// updateTempHum(): starts TCP connection and uploads data…
// ********************************************************************************** //

boolean updateTempHum(){
data_gonder=false;

//*************************************************************************
if (!TCP_concect())
{
//Serial.println(F(” TCP connection error”));
errorCnt++;
ConnKapat();
return false;
}
//Serial.println(F(” TCP connection OK”));
delay(1000);

//**************************************************************************
if(SendData())
{
//Serial.println(F(” Data sent OK\r\n”));
//doLED(data,green);
errorCnt=0;

cevap_bekle(1000,”+IPD”,true);
//GetTime1(1000,”saat”,true);
ConnKapat();
//Serial.println(F(” =======================================\r\n”));
clearESP8266SerialBuffer(1000);
return true;
} else {
//Serial.println(F(” Data send Error\r\n”));
errorCnt++;
ConnKapat();
clearESP8266SerialBuffer(1000);
return false;
}

}

boolean TCP_concect()
{
//Serial.println(F(“3. Set up TCP connection “));
String cmd = “AT+CIPSTART=\”TCP\”,\””; // set up TCP connection to…
cmd += HOST; // this IP address and…
cmd += “\”,80″; // this port
WiFiSerial.println(cmd); // send command
//Serial.print(F(” SEND: “));
//Serial.println(cmd); // send command
cevap_bekle(1000,”CONNECT”,true);
return cevap_bekle(1000,”OK”,true);

}

boolean SendData()
{
String cmd = KEYstring1+SAYFA+KEYstring2+ID; // unique key for thingspeak.com channel
cmd +=sensor_oku();
//cmd += dtostrf(sicF, 4, 1, buffer); // add string containing temperature (xx.x)

//cmd +=”&S3=”;
//cmd += dtostrf(nem, 4, 1, buffer); // add string containing humidity (xx.x)

//cmd +=”&alan3=”;
//tempC = dtostrf(sic_lm35, 4, 1, buffer);
//cmd+= tempC;
cmd += ” HTTP/1.1\r\n”;
cmd += “Host: “;
cmd+=HOST;
cmd+=”\r\n\r\n”;
//Serial.println(F(“4. Report number of bytes to send”));
WiFiSerial.print(“AT+CIPSEND=”);
WiFiSerial.println(cmd.length()); // tell TCP connection how many bytes to send
//Serial.print(F(” SEND: AT+CIPSEND=”));
//Serial.println(cmd.length(),DEC);

if(cevap_bekle(2000,”>”,true)) // if ready to accept data, look for “>”
{
//Serial.println(F(“5. Ready to send”));
//Serial.println(saat_oku());
delay(500);
WiFiSerial.println(cmd); // send data string
if (hata_ayiklama==1)
{
Serial.print(F(” SEND cmd:”));
Serial.println(cmd); // send data string
}
cmd.replace(‘\r’,’ ‘);
cmd.replace(‘\n’,’ ‘);
//Serial.println(F(“Server’a Gonderildi.”));
//delay(2000);
return cevap_bekle(3000,”SEND”,true);

}
else
return false;

}

String sensor_oku()
{

String rt=””;
if (sensorler[0]==’A’)
{
rt +=”&S1=”;
rt += dtostrf(sicF, 4, 1, buffer); // add string containing temperature (xx.x)
}

if (sensorler[1]==’A’)
{
rt +=”&S3=”;
rt += dtostrf(nem, 4, 1, buffer); // add string containing humidity (xx.x)
}

if (sensorler[2]==’A’)
{
rt +=”&S2=”;
rt += dtostrf(sicF2, 4, 1, buffer); // add string containing humidity (xx.x)
}

if (sensorler[3]==’A’)
{
rt +=”&S4=”;
sen4=digitalRead(7);
rt += dtostrf(sen4, 4, 1, buffer); // add string containing humidity (xx.x)
}

if (sensorler[4]==’A’)
{
rt +=”&S5=”;
sen5=digitalRead(8);
rt += dtostrf(sen5, 4, 1, buffer); // add string containing humidity (xx.x)
}

return rt;
}

boolean ConnKapat()
{
WiFiSerial.println(“AT+CIPCLOSE”);
cevap_bekle(1000,”OK”,true);
delay(1000);
}

void clearESP8266SerialBuffer(const int timeout)
{
long int time = millis();
for (int i=0;i<5;i++)
{
time = millis();
while( (time+timeout) > millis())
{
while(WiFiSerial.available())
{
char c = WiFiSerial.read(); // read the next character.
}
}
}

}

boolean cevap_bekle(const int timeout, String cmd, boolean debug)
{
String s1=””;
int t2;
long int time = millis();
boolean sonuc=false;
for (int i=0;i<5;i++)
{
time = millis();
while( (time+timeout) > millis())
{
while(WiFiSerial.available())
{
char c = WiFiSerial.read(); // read the next character.
s1+=c;
if (hata_ayiklama==1)
Serial.print(c);
}

if (s1.indexOf(cmd)>-1)
{
if (hata_ayiklama==1)
{
Serial.print(F(” OK OK “));
Serial.println(cmd);
}
sonuc= true;
return true;
}

}

}

s1.replace(‘\n’,’ ‘);
s1.replace(‘\r’,’ ‘);
//Serial.print(F(” HATA BILGISI [“));
//Serial.println(cmd+”] :”+s1);
//Serial.println(Serial.availableForWrite());
//Serial.println(F(” ERROR ERROR”));
return sonuc;

}

// ********************************************************************************** //
// resetWiFiModule: reset ESP8266 module by pulling RST line low..
// ********************************************************************************** //
void resetWiFiModule() {
//doLED(power,red);
pinMode(ESP8266rst, OUTPUT);
digitalWrite(ESP8266rst,LOW); // hold reset line low for 100ms
delay(100);
digitalWrite(ESP8266rst,HIGH); // release
delay(2000); // wait for module to recover
//doLED(power,yellow); // Ok for now

cevap_bekle(1500,”ready”,true);
/*
if (cevap_bekle(1500,”ready”,true))
Serial.println(F(” Wifi modul Ready”));
else
Serial.println(F(” Wifi modul Not ready”));
*/

}

// ********************************************************************************** //
// startWiFiModule: open serial connection and check for AT command response
// ********************************************************************************** //
boolean startWiFiModule(){
WiFiSerial.begin(9600);
delay(100); // wait for it…
//Serial.println(F(“1. Resetting ESP8266 module”));
//Serial.println(F(” SEND: AT”));
WiFiSerial.println(“AT”); // send AT reset command, the response should include “System Ready”
delay(1000); // wait for it…
if(WiFiSerial.find(“OK”)){ // if “Ready” received then we’re all good to go
//Serial.println(F(” RESET complete”));
//doLED(power,green);
return true;
} else {
//Serial.println(F(” RESET error”));
//doLED(power,red);
errorCnt++;
return false;
}
}

// ********************************************************************************** //
// connectWiFi: attempts to set up WiFi connection to the ESP8266 module..
// ********************************************************************************** //
boolean connectWiFiModule() {
//Serial.println(F(“2. Connecting to WiFi”));
WiFiSerial.println(“AT+CWMODE=1”); // set the WiFi to STA (station) & AP (acceee point) mode
//Serial.println(F(” SEND: AT+CWMODE=1″)); // set the WiFi to STA (station) & AP (acceee point) mode
//delay(1000);
cevap_bekle(1000,”OK”,true);

//WiFiSerial.println(“AT+CIPSTO=100”); // set the WiFi to STA (station) & AP (acceee point) mode
//Serial.println(F(” SEND: AT+CIPSTO=100″)); // set the WiFi to STA (station) & AP (acceee point) mode
//delay(1000);
//cevap_bekle(1000,”OK”,true);

// wait for response
String cmd=”AT+CWJAP=\””; // create join access point message
cmd+=SSID; // SSID of WiFi connection
cmd+=”\”,\””;
cmd+=PASS; // Password
cmd+=”\””;
WiFiSerial.println(cmd); // send command
//Serial.println(F(” SEND: ****”)); // wait
//delay(2000); // wait for connection to be completed

// if(WiFiSerial.find(“OK”)) { // if OK then return true

if (cevap_bekle(3000,”WIFI GOT IP”,true)) { // if OK then return true
//Serial.println(F(” Wifi Connection OK”));
delay(1000);
return true;
} else {
//Serial.println(F(” Wifi Connection Error”));
errorCnt++;
delay(1000);
return false;
}
}

// ********************************************************************************** //
// OPERATION ROUTINES
// ********************************************************************************** //
// FREERAM: Returns the number of bytes currently free in RAM

int freeRam(void) {
extern int __bss_end, *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) – ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) – ((int)__brkval);
}
return free_memory;
}

float DSgetTemp(OneWire ds_sensor)
{
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds_sensor.search(addr)) {
//no more sensors on chain, reset search
ds_sensor.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
//Serial.println(F(“CRC is not valid!”));
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
//Serial.print(F(“Device is not recognized”));
return -1000;
}

ds_sensor.reset();
ds_sensor.select(addr);
ds_sensor.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds_sensor.reset();
ds_sensor.select(addr);
ds_sensor.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds_sensor.read();
}

ds_sensor.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

void Sicaklik_Nem_Oku_Gonder()
{
int loop1=0;
if (sensorler[0]==’A’)
{
sicF= DSgetTemp(ds);

while (sicF>70 or loop1<5)
{
sicF= DSgetTemp(ds);
delay(250);
loop1++;
}
}
loop1=0;

if (sensorler[2]==’A’)
{
sicF2= DSgetTemp(ds2);
while (sicF2>70 or loop1<5)
{
sicF2= DSgetTemp(ds2);
delay(250);
loop1++;
}
}
if (sicF2==-1000)
sicF=0;

if (sicF==0)
sicF=0;
sicI=sicF;
int sc=sicI;
if ((sicF-sc)>=0.6)
sc=sc+1;
if (sc<50)
{
sicI=sc;
sicS=sicF;

nem = dht.readHumidity();
float t = dht.readTemperature();
nemS=nem;

String s3=”(sicaklik)[“;
s3+=sicS;
s3+=”][“;
s3+=nem;
s3+=”]”;
Serial.println(s3);
}

}

bool EpromAyarOku()
{

SSID=EEPROM_read(30);
PASS=EEPROM_read(60);
HOST=EEPROM_read(100);
SAYFA=EEPROM_read(150);
ID=EEPROM_read(180);
yaz=EEPROM_read(90);
kalibrasyon=yaz.toInt();
yaz=EEPROM_read(220);
hata_ayiklama=yaz.toInt();

Serial.println(F(” “));
Serial.println(F(“AYARLAR”));
Serial.println(F(“====================================================”));
Serial.println(“Kablosuz Ag : “+SSID);
Serial.println(“Sifre : “+PASS);
Serial.println(“Server : “+HOST);
Serial.println(“Sayfa : “+SAYFA);
Serial.println(“ID : “+ID);
Serial.print(“Kalibrasyon : “);
Serial.println(kalibrasyon);
Serial.print(“Hata Ayiklama: “);
Serial.println(hata_ayiklama);

yaz=EEPROM_read(210);
for (int i=0;i<5;i++)
{
Serial.print(“Sensor “);
Serial.print(i+1);
if (yaz.substring(i,i+1)==”A”)
{
sensorler[i]=’A’;
Serial.println(” : Acik”);
}
else
{
sensorler[i]=’K’;
Serial.println(” : Kapali”);
}
}

Serial.println(F(“====================================================”));
Serial.println(F(” “));
if (SSID==”” or PASS==”” or HOST==”” or SAYFA==”” or ID==””)
return false;
else
return true;

}

void EEPROM_write(char * data, int datasize,int bas) {
int addr = bas;
EEPROM.write(addr++, datasize);
for (int i=0; i<datasize; i++) {
EEPROM.write(addr++, (byte)data[i]);
}

}

String EEPROM_read(int bas )
{
int _addrByte = bas;
String str=””;
int value,datasize;
datasize=(int) EEPROM.read(bas);
//Serial.println(“datasize : “+String(datasize));
if (datasize<200)
{
for (int i=bas+1;i<bas+datasize+1;i++)
{
value = EEPROM.read( i );
str += (char)(value);
}
}

//Serial.println(str);
return str;
}

void serialEvent()
{
String instr=””,str,tag;
int t=0,l1,l2;
char ch[30];
while (Serial.available())
{
//char inChar = (char)Serial.read();
instr += (char)Serial.read();
}

//Serial.println(instr);
//**********************************************************************
// instr (saat)[10:20]
// instr (tarih)[31-08-2016]
// instr (ssid)[kablosuz](sifre)[sifre]
// (ssid)[KABLOSUZ2](sifre)[turk@sat@blk]
// (HOST)[KABLOSUZ2]
// (SAYFA)[KABLOSUZ2]
// (ID )[KABLOSUZ2]
// (kalibrasyon)[-2]
// (sensorler)[10100]
///////////////////////////////////////////////////////////////////////////

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”ssid”)
{
t=instr.indexOf(“]”);
SSID=instr.substring(instr.indexOf(“[“)+1,t);
t=instr.indexOf(“[“,t);
PASS=instr.substring(t+1,instr.indexOf(“]”,t));
instr=””;
SSID.toCharArray(ch,SSID.length()+1);
EEPROM_write(ch,SSID.length(),30);
PASS.toCharArray(ch, PASS.length()+1);
EEPROM_write(ch,PASS.length(),60);
//SSID=ssid;
//PASS=sifre;
delay(1000);
Serial.println(F(“DEBUGOK”));
resetWiFiModule(); // reset WiFi module
startWiFiModule(); // restart serial connection to module
connectWiFiModule(); // connect to local wifi
//(ssid)[KABLOSUZ2](sifre)[turk@sat@blk]

}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”kalibrasyon”)
{
t=instr.indexOf(“]”);
str=instr.substring(instr.indexOf(“[“)+1,t);
str.toCharArray(ch,str.length()+1);
EEPROM_write(ch,str.length(),90);
Serial.println(F(“DEBUGOK”));
yaz=EEPROM_read(90);
kalibrasyon=yaz.toInt();
yaz=””;
}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”HATA-AYIKLAMA”)
{
t=instr.indexOf(“]”);
str=instr.substring(instr.indexOf(“[“)+1,t);
str.toCharArray(ch,str.length()+1);
EEPROM_write(ch,str.length(),220);
Serial.println(F(“DEBUGOK”));
yaz=EEPROM_read(220);
hata_ayiklama=yaz.toInt();
yaz=””;
}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”HOST”)
{
t=instr.indexOf(“]”);
str=instr.substring(instr.indexOf(“[“)+1,t);
str.toCharArray(ch,str.length()+1);
EEPROM_write(ch,str.length(),100);
Serial.println(F(“DEBUGOK”));
yaz=EEPROM_read(100);
HOST=str;
yaz=””;

}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”SAYFA”)
{
t=instr.indexOf(“]”);
str=instr.substring(instr.indexOf(“[“)+1,t);
str.toCharArray(ch,str.length()+1);
EEPROM_write(ch,str.length(),150);
Serial.println(F(“DEBUGOK”));
yaz=EEPROM_read(150);
SAYFA=str;
yaz=””;
}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”ID”)
{
t=instr.indexOf(“]”);
str=instr.substring(instr.indexOf(“[“)+1,t);
str.toCharArray(ch,str.length()+1);
EEPROM_write(ch,str.length(),180);
Serial.println(F(“DEBUGOK”));
yaz=EEPROM_read(180);
ID=str;
yaz=””;
}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”SENSORLER”)
{
t=instr.indexOf(“]”);
str=instr.substring(instr.indexOf(“[“)+1,t);
str.toCharArray(ch,str.length()+1);
EEPROM_write(ch,str.length(),210);
Serial.println(F(“DEBUGOK”));
//Serial.println(str);
yaz=EEPROM_read(210);
//Serial.println(“yaz : “+yaz);

for (int i=0;i<5;i++)
{
//Serial.println(yaz.substring(i,i+1));

if (yaz.substring(i,i+1)==”A”)
{
sensorler[i]=’A’;
//Serial.println(“sensor A”);
}
else
{
sensorler[i]=’K’;
//Serial.println(“sensor K”);

}
}

EpromAyarOku();
}

if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”AYARAL”)
{
EpromAyarOku();

}
if (instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”))==”DATAYUKLE”)
{

updateTempHum();
Serial.println(F(“Data basariyla yuklendi”));

}

}

2) P10 panel gösterme

#define build 1

#define revision 6

// ARDUINO PIN USAGE

// D2 -> ESP8266 TX

// D3 -> 1k/2k (to GND) -> ESP8266 RX

// D4 -> diode, 4k7 (to 3.3v) -> ESP8266 RST

// D5 -> DHT11/21 Data

// D6 -> DI of LED strip

#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)

#include <DMD.h> //

#include <TimerOne.h> //

#include “SystemFont5x7.h”

String sic=”—“,nem=”—“;

char buffer[10];

int loopcount=0;

#define DISPLAYS_ACROSS 1

#define DISPLAYS_DOWN 1

DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

char b[6];

char c[2];

char k[4];

#include <DS3231.h>

DS3231 rtc(SDA, SCL);

int saat,dak,gun,ay,yil,san;

String yaz = “”;

byte mode=0;

//*****************************************************************************************//

// Initial Setup

//*****************************************************************************************//

void setup() {

Serial.begin(9600);

//Serial.println(F(“Led Panel saat ve Sicaklik Uygulamsi – Hasan SAVUN Nisan 2016”));

//Serial.print(F(“Build “));

//Serial.print(build);

//Serial.print(F(“.”));

//Serial.println(revision);

//Serial.print(F(“Free RAM: “));

//Serial.print(freeRam());

//Serial.println(F(“B\r\n”));

rtc.begin();

Timer1.initialize( 5000 );

Timer1.attachInterrupt( ScanDMD );

dmd.clearScreen( true );

dmd.selectFont(System5x7);

panel_yaz(“sic”,”-“,”-“);

}

//*****************************************************************************************//

// MAIN LOOP

//*****************************************************************************************//

void loop()

{

if(loopcount == 0)

{

panel_yaz(“sic”,”-“,”-“); // after 5 seconds, turn off LEDs

}

if(loopcount == 10)

{

panel_yaz(“nem”,”-“,”-“); // after 5 seconds, turn off LEDs

}

delay(1000); // pulse data LED as seconds counter

loopcount = (loopcount+1)%20;

}

// ********************************************************************************** //

// OPERATION ROUTINES

// ********************************************************************************** //

// FREERAM: Returns the number of bytes currently free in RAM

int freeRam(void) {

extern int __bss_end, *__brkval;

int free_memory;

if((int)__brkval == 0) {

free_memory = ((int)&free_memory) – ((int)&__bss_end);

}

else {

free_memory = ((int)&free_memory) – ((int)__brkval);

}

return free_memory;

}

//*********************************************************************************//

// DMD PANAL + SAAT

//********************************************************************************//

void ScanDMD()

{

dmd.scanDisplayBySPI();

}

String saat_oku()

{

return rtc.getTimeStr();

}

void panel_yaz(String islem,String yazi,String yazi2)

{

if (islem==”sic”)

{

dmd.selectFont(System5x7);

sic.toCharArray(c, 3);

dmd.drawString( 1, 0, c, 2, GRAPHICS_NORMAL );

yaz = “C “;

yaz.toCharArray(c, 3);

dmd.drawString( 19, 0, c, 2, GRAPHICS_NORMAL );

}

if (islem==”nem”)

{

dmd.selectFont(System5x7);

nem.toCharArray(c, 3);

dmd.drawString( 1, 0, c, 2, GRAPHICS_NORMAL );

yaz = “% “;

yaz.toCharArray(c, 3);

dmd.drawString( 19, 0, c, 2, GRAPHICS_NORMAL );

}

yaz = saat_oku();

yaz.toCharArray(b, 6);

dmd.drawString( 1, 8, b, 6, GRAPHICS_NORMAL );

//Serial.println(yaz);

}

void tarih_ayarla()

{

//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)

rtc.setDate(ay, gun, yil); // Set the date to January 1st, 2014

}

void saat_ayarla(String instr)

{

if (instr.length()==8)

{

int t=instr.indexOf(“:”);

String str=instr.substring(0,t);

saat=str.toInt();

t=instr.indexOf(“:”,t+1);

str=instr.substring(instr.indexOf(“:”)+1,t);

dak=str.toInt();

str=instr.substring(t+1);

san=str.toInt();

instr=””;

}

//Serial.print(F(” Ayarlaan Saat: “));

//Serial.println(String(saat)+”:”+String(dak)+”:”+String(san));

rtc.setTime(saat, dak, san);

}

void serialEvent()

{

String instr=””,str,strKomut;

int t=0;

char ch[30];

while (Serial.available())

{

//char inChar = (char)Serial.read();

instr += (char)Serial.read();

}

Serial.println(instr);

strKomut=instr.substring(instr.indexOf(“(“)+1,instr.indexOf(“)”));

Serial.println(strKomut);

//**********************************************************************

// instr (saat)[10:20]

// instr (tarih)[31-08-2016]

// instr (ssid)[kablosuz](sifre)[sifre]

// (ssid)[KABLOSUZ2](sifre)[turk@sat@blk]

// (kalibrasyon)[-2]

// (sicaklik)[26.10][58]

///////////////////////////////////////////////////////////////////////////

if (strKomut==”saat”)

{

t=instr.indexOf(“:”);

str=instr.substring(instr.indexOf(“[“)+1,t);

saat=str.toInt();

t=instr.indexOf(“:”,t+1);

str=instr.substring(instr.indexOf(“:”)+1,t);

dak=str.toInt();

str=instr.substring(t+1,instr.indexOf(“]”));

san=str.toInt();

instr=””;

//Serial.println(String(saat)+”:”+String(dak)+”:”+String(san));

//Serial.println(F(“DEBUGOK”));

saat_ayarla(“”);

panel_yaz(“sic”,”-“,”-“);

}

if (strKomut==”tarih”)

{

t=instr.indexOf(“-“);

str=instr.substring(instr.indexOf(“[“)+1,t);

gun=str.toInt();

t=instr.indexOf(“-“,t+1);

str=instr.substring(instr.indexOf(“-“)+1,t);

ay=str.toInt();

str=instr.substring(t+1,instr.indexOf(“]”));

yil=str.toInt();

instr=””;

//Serial.println(String(gun)+”-“+String(ay)+”-“+String(yil));

//Serial.println(F(“DEBUGOK”));

tarih_ayarla();

}

if (strKomut==”sicaklik”)

{

t=instr.indexOf(“]”);

str=instr.substring(instr.indexOf(“[“)+1,t);

sic=str;

int t2=instr.indexOf(“]”,t+1);

str=instr.substring(instr.indexOf(“[“,t)+1,t2);

nem=str;

instr=””;

//panel_yaz(“sic”,”-“,”-“);

//Serial.println(sic);

//Serial.println(nem);

}

}

Hasan SAVUN

5 Yorum

Ayigitler Yayın tarihi8:17 am - Haz 26, 2018

Merhaba uygulamanızin kaynak kodlarıni paylasmayı dusunuyormusunjz??

    hsavun Yayın tarihi10:04 am - Şub 17, 2020

    kodlar paylaşılmıştır.
    takıldığınız noktaya yazabilrisiniz.

      kad,r Yayın tarihi9:40 pm - Şub 27, 2020

      tebrikler

Ali AYDOĞAN Yayın tarihi4:02 pm - Ağu 28, 2018

Çok başarılı görünüyor. Çalışmalarınızın devamını dilerim.

Gökhan Yayın tarihi9:33 am - Oca 4, 2020

merhabalar bu proje hakkında kullandığınız kodlar ve algoritma nedir anlatabilir misiniz ?

Bir Cevap Yazın