Can someone go over my code please? 16ch chicken incubator
hi everyone,
i'm new programming, , have project i'm doing father. asked me control chicken incubator, 16 of them. decided use dht22 sensors being reads temp. , humidity. keep internal temperature @ constant 100 deg f, using 100w 120/220v light bulb in each of 16 incubators. 16 relays controlled sainsmart 16ch relay board. along climate control have 24v linear actuator in each incubator tilt egg trays @ 45 deg each way. actuator tilts tray 45 deg every 1hour. need help, far can log temp , humidity 2 sensors (the rest or in mail) , light bulbs turning on , off according set temps. millis function still little hard grasp, i've saw first arduino code or type of code, 3 weeks ago. anyhow, here's code far. oh, in advance
ps. saintsmart lcd display going integrated, later.


i'm new programming, , have project i'm doing father. asked me control chicken incubator, 16 of them. decided use dht22 sensors being reads temp. , humidity. keep internal temperature @ constant 100 deg f, using 100w 120/220v light bulb in each of 16 incubators. 16 relays controlled sainsmart 16ch relay board. along climate control have 24v linear actuator in each incubator tilt egg trays @ 45 deg each way. actuator tilts tray 45 deg every 1hour. need help, far can log temp , humidity 2 sensors (the rest or in mail) , light bulbs turning on , off according set temps. millis function still little hard grasp, i've saw first arduino code or type of code, 3 weeks ago. anyhow, here's code far. oh, in advance
ps. saintsmart lcd display going integrated, later.
code: [select]
/* 16 channel incubator
created/ modified apr 20 2012
by roth ly
also bits of code has been used "frostin" of arduino forum:
http://arduino.cc/forum/index.php?topic=70742.0
this code 16 channel chicken incubator, total of
16 seperate incubator controlled via 1 arduino mega.
16 dht22 senor inputs run in digital i/o 23,25,27...37.
a 16 channel relay board sain smart takes care of switching
the heating element(100watt bulb) needed in each of 16 incubators keep
internal temp of 100f. along side sensor data , relay switching
there code turning separate dpdt relay on , off activate
a linear actuator every hour.
modified blink without delay
turns on , off dpdt relay connected digital pin (off 1hr, on 1hr)
without using delay() function. means other code
can run @ same time without being interrupted led code.
blink without delay circuit:
* relay pin connected @ pin a15 , ground, tip102 tran , 1n4004 diode.
* relay acts h-bridge on/off linear actuator every hour.
blink without delay
created 2005
david a. mellis
modified 8 feb 2010
paul stoffregen
example code in public domain.
http://www.arduino.cc/en/tutorial/blinkwithoutdelay
*/
//***************************************************************************
// constants won't change. used here to
// set pin numbers:
const int relaypin = a15; // number of led pin
// variables change:
int ledstate = low; // ledstate used set led
long previousmillis = 0; // store last time led updated
// follow variables long because time, measured in miliseconds,
// become bigger number can stored in int.
long interval = 19000; // interval @ blink (milliseconds)
#include <dht.h>
#define dhtpin1 23 // sets dht22 sensor #1 @ pin digital 23
#define dhtpin2 25 // sets dht22 sensor #2 @ pin digital 25
#define dhttype dht22
dht dht1(dhtpin1, dhttype);
dht dht2(dhtpin2, dhttype);
#define bulbpin1 22 // pin number relay/heater #1
#define bulbpin2 24 // pin number relay/heater #2
#define temp_high 29 //at temp (c*) turn off relay/heater
#define temp_low 28 //at temp turn on relay/heater
//#define humid_high 60
//#define humid_low 20
float mintemp = 100;
float maxtemp = 0;
//float minhumid = 100;
//float maxhumid = 0;
int bulbvalue = 0;
void setup() {
// set digital pin output:
pinmode(relaypin, output);
serial.begin(9600);
serial.println("program start");
dht1.begin();// starts sensor 1
dht2.begin(); // starts sensor 2
pinmode(bulbpin1, output); //sets bulbpin output
pinmode(bulbpin2, output);
}
void loop()
{
// read data
float t1 = dht1.readtemperature();
float h1 = dht1.readhumidity();
//int temperaturef = (t1 * 9 / 5) +32.5; // converts farenhiet, not sure how use yet
// min/max
mintemp = min(mintemp, t1);
maxtemp = max(maxtemp , t1);
// displat data
if (isnan(t1) || isnan(h1)){ // sensor reading check
serial.println("sensor 1");
} else {
serial.print("#1 temp:");
serial.print(t1);
serial.println("*c");
serial.print("#1 humid:");
serial.print(h1);
serial.println("%\t");
// relay/heater
if (t1 > temp_high) bulbvalue = 1;
else if (t1 < temp_low) bulbvalue = 0;
digitalwrite(bulbpin1, bulbvalue);
delay(2000); // dht's need delay between readings ...
}
//****************************************************
{
// read data
// read data
float t2 = dht2.readtemperature();
float h2 = dht2.readhumidity();
//int temperaturef = (t2 * 9 / 5) +32.5;
// min/max
mintemp = min(mintemp, t2);
maxtemp = max(maxtemp , t2);
// displat data
if (isnan(t2) || isnan(h2)){
serial.println("sensor 2");
} else {
serial.print("#2 temp:");
serial.print(t2);
serial.println("*c");
serial.print("#2 humid:");
serial.print(h2);
serial.println("%\t");
// crockpot
if (t2 > temp_high) bulbvalue = 1;
else if (t2 < temp_low) bulbvalue = 0;
digitalwrite(bulbpin2, bulbvalue);
delay(2000); // dht's need delay between readings ...
}
//*****************************************************************
}
// here you'd put code needs running time.
// check see if it's time blink led; is, if the
// difference between current time , last time blinked
// led bigger interval @ want to
// blink led.
unsigned long currentmillis = millis();
if(currentmillis - previousmillis > interval) {
// save last time blinked led
previousmillis = currentmillis;
// if led off turn on , vice-versa:
if (ledstate == low)
ledstate = high;
else
ledstate = low;
// set led ledstate of variable:
digitalwrite(relaypin, ledstate);
}
}
hi
i've not gone through in detail, since log temperature , humidity correctly now. couple of comments.
rather replicating variables 16x times full scale version, consider using array each of them.
http://arduino.cc/en/reference/array
then can use loop address each in turn, keep sketch organised , easier read. , allow expand further when time comes changing few lines.
and, in line have delay block code doing else 2sec. not long time, if you're using non-blocking method (with millis) turning relays off , on, may consider here too.
love build - looks impressive !
geoff
i've not gone through in detail, since log temperature , humidity correctly now. couple of comments.
rather replicating variables 16x times full scale version, consider using array each of them.
http://arduino.cc/en/reference/array
then can use loop address each in turn, keep sketch organised , easier read. , allow expand further when time comes changing few lines.
and, in line have delay block code doing else 2sec. not long time, if you're using non-blocking method (with millis) turning relays off , on, may consider here too.
code: [select]
delay(2000); // dht's need delay between readings ...love build - looks impressive !
geoff
Arduino Forum > Using Arduino > Project Guidance > Can someone go over my code please? 16ch chicken incubator
arduino
Comments
Post a Comment