arduino egg incubator problem

Hi, i started an automatic egg turner incubator for my final year project. there is a problem where the temperature varies automatically and changes within 5 to 10 seconds.. it went up to 40++ degree Celsius then it went down to 20 degree Celsius.

The components I used are as follows:
Arduino Uno R3
I2C LCD1602
28BYJ-48 Stepper Motor with ULN-2003 Driver
5v Relay module
12v DC Fan
2N2222 Transistor
LM35 Temperature Sensor
25W Bulb
9V battery

I include my code and circuit diagram on my project. Thankyou in advance.

#include <LiquidCrystal.h>
#include <Stepper.h>
#define steps 4096
#define heater 12
#define fan 13
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

int sensor = A0;

Stepper stepper(steps, 8, 10, 9, 11);

void setup() {
  lcd.init(); // initialize the lcd
  lcd.backlight();

  pinMode(sensor, INPUT);
  pinMode(heater, OUTPUT);
  pinMode(fan, OUTPUT);
  lcd.begin(16,2);
 
}

void loop() {
  float reading=analogRead(sensor);
  float temperature=reading*(5.0/1023.0)*100;
  delay(10);
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("Temperature");
  lcd.setCursor(4,1);
  lcd.print(temperature);
  lcd.print((char)223);
  lcd.print("C");
  delay(10);

  if (temperature < 38){
    digitalWrite(heater, LOW);
    digitalWrite (fan, LOW) ;
  }

  if (temperature >= 38){
    digitalWrite(heater, HIGH);
    digitalWrite(fan, HIGH);
  }

  stepper.setSpeed(6);
  stepper.step(4096);
}

The step() function blocks. How long does it take for the stepper to move 4096 steps? You can't measure or control temperature while the stepper is moving. Do the movement in a series of small steps, measuring and controlling between movements.

thankyou for the info. Tt first i was thinking of insufficient voltage due to many components connected with the Arduino. When i disconnect the stepper from the Arduino the problem has been solved.. the temperature varies stopped. i am thinking to add another separate Arduino just for the stepper motor. or maybe is there any possible ways to use one Arduino?

I wouldn't try running a stepper powered by that battory. Too low current capacity of that battory.

sorry bout that, this is the latest circuit diagram i refer

Hi,
Definitely power the stepper from another 5V supply as you have shown on your Fritzy diagram
You need to forget about Fritzy images and draw a circuit diagram using component symbols and labels.

You may need to add hysteresis in your code, at the moment you have the light turning ON if below 38C and OFF if above or equal to 38C.
It may give you better control to allow for lag between lamp on and the sensor seeing a temperature change to do this.

Temp above 2C + setpoint(38) Lamp OFF
Temp below 2C - setpoint(38) Lamp ON.
You may need to adjust the +/- 2C value to tune any oscillations.

Also;

 float temperature=reading*(5.0/1023.0)*100;

need all values/constants floating;

 float temperature=reading*(5.0/1023.0)*100.0;

Tom... :slight_smile:

thankyou very much for the knowledge sir. Really appreciate it

You do not want to power this from batteries, an incubator will obviously have access to electrical power.

Running a mixed 5V/12V system off 9V batteries is asking for problems of course.

Get a 5V power supply for the Arduino and stepper and other 5V stuff (of course it goes to the 5V pin of the Arduino, not the Vin) and a separate 12V supply for your 12V fan.

Also you should not be reading your LM35 with Vcc as reference, that's another major source of errors. It's an absolute voltage sensor. Read it against the fixed 1.1V internal reference (and get almost 5x resolution in the process to boot).

thankyou very much sir. Will definitely correct my mistakes

It looks if you have your " < >" mixed up.

if (temperature < 38){ //less than 38, Low, Low.
digitalWrite(heater, LOW);
digitalWrite (fan, LOW) ;

Good luck..

Hi,
Please draw a proper circuit diagram, including labels on components.

The two BJTs they need base current limit resistors.

Thanks.. Tom.. :slight_smile:

thankyou everyone. will try all your advice

helpme11:
thankyou everyone. will try all your advice

May I add, you actually did a good job on the Fritz. I am sure that you would have the same skill with circuit diagrams. I'm starting to use Kicad for that, but pencil and paper work wonders... it's cliche but honestly even backs of envelopes will do.

But, you should look at how standard schematics are usually drawn, initially just to get a feel for the conventional ways of laying things out. They are actually time honoured time savers.

thankyou for the advice sir..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.