Bilgiler > Çaycı Termostat Devresi Programı
Çaycı Termostat Devresi Programı
#include "Wire.h"
#include "SPI.h"
#include "OneWire.h"
#include "DallasTemperature.h"
#include "EEPROM.h"
#define DS1307_ADDRESS 0x68
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define DS1307_ADDRESS 0x68
#define MAX7219_DIN 5
#define MAX7219_CS 6
#define MAX7219_CLK 7
bool kaynat=true;
int a = 0;
float temp = 0;
void(* resetFunc) (void) = 0;
void initialise()
{
digitalWrite(MAX7219_CS, HIGH);
pinMode(MAX7219_DIN, OUTPUT);
pinMode(MAX7219_CS, OUTPUT);
pinMode(MAX7219_CLK, OUTPUT);
}
void output(byte address, byte data)
{
digitalWrite(MAX7219_CS, LOW);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, address);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, data);
digitalWrite(MAX7219_CS, HIGH);
}
void setup()
{
pinMode(12,OUTPUT);
digitalWrite(12,1);
Serial.begin(9600);
Wire.begin();
sensors.begin();
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
Wire.begin();
// put your setup code here, to run once:
initialise();
output(0x0f, 0x00); //display test register - test mode off
output(0x0c, 0x01); //shutdown register - normal operation
output(0x0b, 0x07); //scan limit register - display digits 0 thru 7
output(0x0a, 0x0f); //intensity register - max brightness
output(0x09, 0x00); //decode mode register - CodeB decode all digits
//sicaklik onlar-birler
output(0x08, 0x00); //minus sign
output(0x07, 0x00); //tens digit
//sicaklık ondabirler-yuzdebirler
output(0x06, 0x00); //ones digit
output(0x05, 0x00); //1/tens digit
output(0x04, 0x00); //1/100 digit
output(0x03, 99); //Degree sign
output(0x02, 78); //C Celcius character
output(0x01, 0); //space
}
byte bcdToDec(byte val)
{
// Convert binary coded decimal to normal decimal numbers
return ( (val / 16 * 10) + (val % 16) );
}
//Converting digits to 7 Segment
int donustur(int a)
{
switch(a)
{
case 0: return 126 ;
break;
case 1: return 48;
break;
case 2: return 109;
break;
case 3: return 121;
break;
case 4: return 51;
break;
case 5: return 91;
break;
case 6: return 95;
break;
case 7: return 112;
break;
case 8: return 127;
break;
case 9: return 123;
break;
default: return 0;
break;
}
}
//ones
int birlergetir(int a)
{
return donustur(a % 10);
}
//tens
int onlargetir(int a)
{
return donustur(((a%100) / 10));
}
//hunderds
int yuzlergetir(int a)
{
return (donustur((a%1000) / 100));
}
//thousands
int binlergetir(int a)
{
return donustur(a / 1000);
}
void printTemp() {
Serial.begin(9600);
Wire.begin();
sensors.begin();
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
//minus sign for temp
if(temp<0)
{
output(0x08, 1);
temp=temp*(-1);
}
else
{
output(0x08, 0);
}
int sayi= temp;
Serial.println(temp);
output(0x07, binlergetir(sayi));
output(0x06, yuzlergetir(sayi));
output(0x05, onlargetir(sayi));
output(0x04, birlergetir(sayi));
//ısıtıcıyı kapat
if(temp>86)
{
//su daha önce hiç kaynamamışsa ısıtıcıyı 60 saniye fazla açık tut.
if(EEPROM.read(1)==0)
{
delay(60000);
EEPROM.write(1,1);
}
pinMode(12,OUTPUT);
digitalWrite(12,1);
}
//kaynamadi bilgisini gir
if(temp<60&&EEPROM.read(1)==1)
{
EEPROM.write(1,0);
}
//ısıtıcıyı aç
if(temp<70)
{
digitalWrite(12,0);
}
}
int sayac=0;
void loop()
{
sayac++;
//10 dakikada bir reset at
if(sayac>1200)
{
resetFunc();
}
printTemp();
delay(400);
}
Devre linki: http://temelelektronik.info/devre.aspx?devre=734
***