Egg incubator menu arduino!

hi! I need to work a function menu for my egg incubator, i want

root menu choose
|
|
|

chicken > 21 days, 37.7c, 45-50h,

turkey > 28days,37.7, 60-75h,

goose >30days,37,6,60-80h

e.g. > if i choose chicken avoid all options for turkey and goose and run machine in 21days 37.7c,45-50h

Display the 3 options and prompt the user to enter 1, 2 or 3
Call a function that takes 3 parameters to do what you want based on the option chosen.

Where are you stuck ?

UKHeliBob:
Display the 3 options and prompt the user to enter 1, 2 or 3
Call a function that takes 3 parameters to do what you want based on the option chosen.

Where are you stuck ?

i display the 3 options, my problem is the function . . look the example code can you help me? i have 5 buttons

#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 2                              // Define the temp sensor data pin
#define DHTTYPE DHT22                         // define the temp/hum sensor type
#define RELAY  0                              // define the relay control pin
DHT dht(DHTPIN, DHTTYPE);                     //initialize the temp sensor
// LCD Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 1
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 1);    //set up what port the LCD will use
int backLight = 13;                           // pin 13 will control the backlight
void setup()
{
  dht.begin();                                //start the temp sensor
  pinMode(RELAY, OUTPUT);        
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH);              // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20,4);                            // columns, rows.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                                // start with a blank screen
  lcd.setCursor(0,0);                         // set cursor to column 0, row 0 (the first row)
  lcd.print("Incubator 1.0");                 // opening line
  lcd.setCursor(0,1);                         // set cursor to column 0, row 1
  lcd.print("Hatch Them!");
  delay(2000);
// Uncomment if you want more text on the 4 line LCD (not used in 2 line LCDs)
// lcd.setCursor(0,2);                        // set cursor to column 0, row 2
// lcd.print("Row 3");                        //Text for line 3
//lcd.setCursor(0,3);                         // set cursor to column 0, row 3
//lcd.print("Row 4");                         // Text for line 4
}
//loop to read the sensor and display
void loop(){
float h = dht.readHumidity();                 // Read the humidity
float t = dht.readTemperature();              // Read temperature in celsius
float f = dht.readTemperature(true);          // get the temperature in Fahreheit
// uncomment to compute heat index in Fahrenheit (the default)
//float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
//float hic = dht.computeHeatIndex(t, h, false);
int is,im,ih,id,ida;                          // variables for time
float time,s1,m1,h1,d1;                       //  Set up variables to calculate time
  time=millis();                              //  Get time in milliseconds since tunit turn on
  s1=time/1000;                               //  Convert time to seconds, minutes, hours, days
  m1=s1/60;
  h1=m1/60;
  d1=h1/24;  
  id=int(d1);                                 //  Strip out remainder to leave Days:Hours:Minutes:Seconds
  ih=int((d1-int(d1))*24);
  im=int((h1-int(h1))*60);
  is=int((m1-int(m1))*60);
// Calculate approximate days till hatch (assume 21 days to hatch)
  ida=21-id;
if (isnan(h) || isnan(t) || isnan(f)){   
// if sensor can't be read
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("failed to read");
  delay(50000);
  return;
  }
else {
//sensor was read succesfully so print values to LCD
  lcd.clear();                                // Clear the LCD
//Print temperature and humidity in first two lines
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.print(f,1);
  lcd.print(" F");
  lcd.setCursor(0,1);
  lcd.print("Humidity:");
  lcd.print(h,0);
  lcd.print(" %");
  lcd.setCursor(0,2);         
  lcd.print("Time:");
// Print time in format Time: xxd:xxh:xxm:xxs
  lcd.print(id);
  lcd.print("d:");
  lcd.print(ih);
  lcd.print("h:");
  lcd.print(im);
  lcd.print("m:");
  lcd.print(is);
  lcd.print("s");  
  lcd.setCursor(0,3);
// Print days left till hatch
  lcd.print("Days left:");
  lcd.print(21-id);
//Temperature controller
  if(f<91){                         //  Set the temperature for the relay to come on (somewhere around 90-101F to get eggs to hatch)
  digitalWrite(RELAY,LOW);           // Turns ON Relay
  }
  else{
  digitalWrite(RELAY,HIGH);          // Turns Relay Off
  }
// Puase for 5 seconds
  delay(5000);
 }
}

I don't see any functions in your code. Do you know how to use them?

BTW... I've hatched a few broods of chickens in my homemade arduino incubator. The DHT temperature probe will work, but it has a slow response time which can cause problems if you don't compensate for it. The BMP temp sensors are much faster and don't require any compensation for the lag time.

I had another thought to share...

You MUST have an understanding of functions in order to program your Arduino. Read and understand this: Functions

A function is a little snippet of code that is only executed on an as-needed basis. In fact, it may never be executed at all. Typically, something in the body of your sketch (in the loop()) will "call" that snippet after an "if/then" statement (or similar) determines that function is necessary.

What I suggest is that you design your loop() with as little code as possible. Something like:

void loop(){
check temperature
if temperature is < 99 then call the function to add heat
if temperature is > 100 then call function to turn off heat
// next, add similar calls to functions as needed
if button x is pressed call function But1pressed()
if button y is pressed... call function But2pressed()
if time to turn the eggs call function eggTurn()
.
.
.
etc
delay(2000);
}

It's absolutely imperative that you structure your code something like that to avoid problems down the road and make your code easy to follow for editing. I wrote the above loop() in a pseudo-code style for clarity since the code you posted shows no kind of logical flow. I hope it's easier to understand.

Also, I want to point out that trying to time your incubator to turn on, execute a particular temperature protocal and then turn off on day 21 for chickens, is dangerous. More complex code must be included in the sketch to accommodate the very real possibility that you will lose power, a wire will get damaged/pulled out or that your board simply freezes. In that event, you must have some process by which you can restart the arduino board and set the remaining days again to pick up the temperature protocol where it left off before the failure. Personally, I avoided that aspect in my design. If you're just using the day count down for display on the lcd, of course that's okay :slight_smile: I suggest you have an alarm for if the temperature is out of the expected range, a beeper goes off. I lost my first batch of eggs for some unanticipated over-heating.

here is my code