Egy termosztát programmal kísérletezgetek. A program működését csak nagyjából értem.
Kód: Egész kijelölése
#include <EEPROM.h>
#include <LiquidCrystal.h>// include the library code
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 6 on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int led =9; // led is at pin
int temp; // make a variable called temp
int settemp; // make a variable called temp
int swtu = 7; // switch up is at pin 7
int swtd = 8; // switch down is at pin 8
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2
void setup() {
pinMode (led,1); // make led or pin13 an output
lcd.begin(16, 2); // set up all the "blocks" on the display
lcd.setCursor(0,0); // set the cursor to colum 0 row 0
lcd.print("Temp:");
lcd.setCursor(12,0);
lcd.print((char)223);
lcd.setCursor(13,0);
lcd.print("C");
EEPROM.read (1); // make the eeprom or atmega328 memory address 1
}
void loop() {
sensors.requestTemperatures(); // beolvas a DS18B20- tol
int temp = sensors.getTempCByIndex(0);
lcd.setCursor (9,0);
lcd.print (temp); // Print the current temp
settemp = EEPROM.read(1); // read the settemp on the eeprom
delay (250); // wait for the lcd to refresh every 250 milliseconds
if // if we se the switch up pin reading on 1 or 5 volts
(digitalRead(swtu)== 1 )
{
settemp ++ // add one to the settemp, the settemp is the ideal temperature for you
;
}
else{// other wise do nothing
}
if
(digitalRead (swtd) == 1)// if we detect a 1 on the other switch pin
{
(settemp --);// subtract one fromm the settemp
}
else {
// else, do nothing
}
if (temp > settemp) // if the temperature exceeds your chosen settemp
{
digitalWrite (led, 1); // turn on the led
}
else // if that doesn't happen, then turn the led off
{
digitalWrite (led,0);
}
lcd.setCursor (0,1); // set the cursor to 0,1
lcd.print ("Set to:"); // Print set to and your ideal temperature in f
lcd.setCursor (9,1);
lcd.print (settemp);
lcd.setCursor(12,1);
lcd.print((char)223);
lcd.setCursor(13,1);
lcd.print("C");
EEPROM.write (1,settemp); /* write the most recent settemp in eeprom data stoage
so that if the power is disconnected, you settemp is saved!*/
delay (250); // wait 250 milliseconds
} // we're done
Egy másik probléma, hogy az alaplapon levő13-as LED állandóan ég, fogalmam sincs miért.
A program eredetije itt található http://www.instructables.com/id/Arduino ... /?ALLSTEPS , ebbe piszkáltam bele, hogy tudjam használni a DS18B20 –al.