FlamingRCAirplanes
Elite member
When it is done I will show you and explain it.
Yep. I am working on that now.this is the code that is working so far.....
at the moment it is just using a delay for the length of time the motor must run for....
prefeably it should monitor the leftsw and rightsw so that when one of those switches are pressed it will stop turning...
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include <DHT.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Servo.h>
Servo myservo;
//declare global variables
float dt, counter;
unsigned long current_time, prev_time;
bool toggle = 0;
#define heat 4
#define leftsw 5
#define rightsw 6
#define alarm 7
#define humid 8
//
void setup() {
Serial.begin(9600);
sensors.begin();
dht.begin();
lcd.begin();
lcd.backlight();
myservo.attach(9);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void temp()
{
if (sensors.getTempCByIndex(0) < 37)
{
digitalWrite (heat, LOW);
}
else if (sensors.getTempCByIndex(0) >= 38)
{
digitalWrite (heat, HIGH);
}
}
void humidity()
{
if (dht.readHumidity() < 65)
{
digitalWrite(humid, LOW);
}
if (dht.readHumidity() >= 70)
{
digitalWrite(humid, HIGH);
}
}
void loop() {
prev_time = current_time; //set previous loop prev_time to current_time
current_time = micros(); //measure the current time
dt = (current_time - prev_time)/1000000.0; //calculate the change in time from the previous time this line was run until now, in seconds
counter = counter + dt; //add dt to the counter to count the time
if (counter >= 7200)
{
}
counter = 0; //reset the counter
if (toggle == 0)
{
toggle = 1;
myservo.attach(9);
myservo.write(180);
delay(200);// need to monitor switches here, must turn until right switch on. or use a delay....
myservo.detach();
}
else {
toggle = 0;
myservo.attach(9);
myservo.write(0);
delay(200);// need to monitor switches here, must turn until left switch on.
myservo.detach();
}
sensors.requestTemperatures(); // Send the command to get temperature readings
lcd.clear();
lcd.setCursor(0,0);
lcd.print (sensors.getTempCByIndex(0), " *");
lcd.setCursor(0,1);
lcd.print(dht.readHumidity(), " %");
temp();
humidity();
if (sensors.getTempCByIndex(0) >= 40 || sensors.getTempCByIndex(0) <= 35)
{
digitalWrite(alarm, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ALERT TEMP!");
lcd.setCursor(0,1);
lcd.print(sensors.getTempCByIndex(0), "*");
}
}
just checked and i think the while statement could work pretty easily.....Yep. I am working on that now.
that is true... but if it only halts the system for about 2 seconds (time it take to rotate egg trays by 60 degrees, i don't think it would really harm the eggs....that whole while loop idea completely breaks your 'do 2+ things at once' initial request. Which is why you want to do some sort of FSM with changes
obviously using an FSM would be the perfect solution... but right now my dad really wants his quail egg incubator to be workingthat whole while loop idea completely breaks your 'do 2+ things at once' initial request. Which is why you want to do some sort of FSM with changes
But over time that will build up.that is true... but if it only halts the system for about 2 seconds (time it take to rotate egg trays by 60 degrees, i don't think it would really harm the eggs....
???? what do you mean? it only turns every 2 hoursBut over time that will build up.
Yes but over time that little delay will turn into a big delay... Like the turning time will become hours off.???? what do you mean? it only turns every 2 hours
hmmm... true....Yes but over time that little delay will turn into a big delay... Like the turning time will become hours off.
cool.. can't wait to see what you have.Almost done!