Moderators: adafruit_support_bill, adafruit
robodude666 wrote:Very nice jigsawnz! So, you just have the heat plate on a relay, controlled by an arduino and a temperature sensor? Are you using a PID controller? If so, what coefficients did you select?
And thanks everyone for the ideas. I recently got a job offer, so I have less time available to me.. However I will look into starting work on this project next month, after some of the upcoming crazyness is worked out.
#include "DHT.h"
//#include <LiquidTWI.h>
#include <Wire.h>
#include "Chronodot.h"
#include <SD.h>
#include <Adafruit_RGBLCDShield.h>
/*
Pins used:
LCD:
Connect via i2c, default address #0 (A0-A2 not jumpered)
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
SDshield
* CS to D8
* MOSI to D11
* MISO to D12
* SCK to D13
RGB Backlight
RED to D3
GREEN to D5
BLUE to D6
Humidity Warning to D2
DHT22 to D4
Heating to D9
*/
Chronodot RTC;
DateTime now = RTC.now();
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
File dataFile;
const int chipSelect = 8; //Sparkfun SD shield pin 8, Adafruit SD shield pin 4.
#define DHTPIN 4 // Pin to read from DHT22 sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
int maxT=0, minT=100; //temperature range
int maxH=0, minH=100; //Humidity range
DHT dht(DHTPIN, DHTTYPE);
//here's where the temp and hum setpoints are changed
float tempset=36.50, tempreset=37.50;
float humset=60, humreset=58;
int tmem=0, hmem=0;
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
SD.begin(chipSelect);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
lcd.setBacklight(WHITE);
pinMode(9, OUTPUT); //Heating
pinMode(10, OUTPUT); //Needed for the SDbreakout board to work.
digitalWrite (9, HIGH); //This keeps the relay turned off during setup
lcd.begin(16, 2); //set up the LCD's number of columns and rows:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Incubator");
lcd.setCursor(0,1);
lcd.print("Controler");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("By George");
lcd.setCursor(0,1);
lcd.print("Timmermans");
delay(2000);
Serial.println("Initializing Chronodot.");
Serial.println("Date\t\tTime\t\tHumidity\tTemperature\tTempRTC");
dataFile = SD.open("DHT22.txt", FILE_WRITE); // open the file. note that only one file can be open at a time,
dataFile.println("Date\t\tTime\t\tHumidity\tTemperature");
dataFile.close(); // so you have to close this one before opening another.
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
}
delay(500);
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT22");
lcd.clear(); //Display error on vfd display.
lcd.setCursor(0,0);
lcd.print("Failed to read");
lcd.setCursor(0,1);
lcd.print("from DHT22");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
dataFile = SD.open("DHT22.txt", FILE_WRITE);
dataFile.println("Failed to read from DHT22"); //Write error message too MicrSD.
dataFile.close(); //Close the file.
lcd.setBacklight(RED);
}
else {
temperature(h, t); //Check temerature and humidity and control relays.
if (now.second() == 0) { //Log data every minute(RTC needed)
debug(h, t, RTC.now());
Log(h, t, RTC.now());
}
else {
LCD(h, t, RTC.now());
}
}
}
void temperature (float h, float t) {
if (tempreset<=t && t<=tempset && tmem==1) {
digitalWrite (9, HIGH);
}
if (t>=tempset) {
tmem==1,
lcd.setBacklight(GREEN);
digitalWrite (9, HIGH);
}
if (t<tempreset) {
tmem==0,
lcd.setBacklight(BLUE);
digitalWrite (9, LOW);
}
if (humreset<=h && h<=humset && hmem==1) {
digitalWrite (2, LOW);
}
if (h>humset) {
hmem==1,
digitalWrite (2, LOW);
}
if (h<humreset) {
hmem==0,
digitalWrite (2, HIGH);
}
}
void Log(float h, float t, DateTime now) {
dataFile = SD.open("DHT22.txt", FILE_WRITE);
if(now.day() < 10) dataFile.print("0");
dataFile.print(now.day(), DEC);
dataFile.print('/');
if(now.month() < 10) dataFile.print("0");
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print('\t');
if(now.hour() < 10) dataFile.print("0");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
if(now.minute() < 10) dataFile.print("0");
dataFile.print(now.minute(), DEC);
dataFile.print(':');
if(now.second() < 10) dataFile.print("0");
dataFile.print(now.second(), DEC);
dataFile.print("\t");
dataFile.print(h);
dataFile.print("\t\t");
dataFile.println(t);
dataFile.close(); //Close the file.
delay(100);
}
void debug(float h, float t, DateTime now) {
if(now.day() < 10) Serial.print("0");
Serial.print(now.day(), DEC);
if(now.month() < 10) Serial.print("0");
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print('/\t');
if(now.hour() < 10) Serial.print("0");
Serial.print(now.hour(), DEC);
Serial.print(':');
if(now.minute() < 10) Serial.print("0");
Serial.print(now.minute(), DEC);
Serial.print(':');
if(now.second() < 10) Serial.print("0");
Serial.print(now.second(), DEC);
Serial.print("\t");
Serial.print(h);
Serial.print("\t\t");
Serial.print(t);
Serial.print("\t\t");
Serial.println(now.tempC());
delay(100);
}
void LCD(float h, float t, DateTime now) {
lcd.clear(); //Display Time, Humidity and Temperature on LCD.
lcd.setCursor(0,0);
if(now.hour() < 10) lcd.print("0");
lcd.print(now.hour(), DEC);
lcd.setCursor(2,0);
lcd.print(":");
lcd.setCursor(3,0);
if(now.minute() < 10) lcd.print("0");
lcd.print(now.minute(), DEC);
lcd.setCursor(5,0);
lcd.print(":");
lcd.setCursor(6,0);
if(now.second() < 10) lcd.print("0");
lcd.print(now.second(), DEC);
lcd.setCursor(10,0);
lcd.print("H");
lcd.setCursor(11,0);
lcd.print(h,1);
lcd.setCursor(15,0);
lcd.print("%");
lcd.setCursor(0,1);
if(now.day() < 10) lcd.print("0");
lcd.print(now.day(), DEC);
lcd.setCursor(2,1);
lcd.print('/');
lcd.setCursor(3,1);
if(now.month() < 10) lcd.print("0");
lcd.print(now.month(), DEC);
lcd.setCursor(5,1);
lcd.print('/');
lcd.setCursor(6,1);
lcd.print(now.year()-2000, DEC);
lcd.setCursor(10,1);
lcd.print("T");
lcd.setCursor(11,1);
lcd.print(t,1);
lcd.setCursor(15,1);
lcd.print((char)223); // degree symbol
}
Return to General Project help
Users browsing this forum: Google [Bot] and 9 guests