element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Noobie to arduino need help with incubator project
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 10 replies
  • Answers 1 answer
  • Subscribers 395 subscribers
  • Views 936 views
  • Users 0 members are here
  • incubator
  • arduino
Related

Noobie to arduino need help with incubator project

mk1manno
mk1manno over 10 years ago

Hey all im new to the site and to arduinos any help would be appreciated. Im building a incubator for incubating chicken egg just for the experience of setting up and programing. So far I have arduino uno with a dht22 temp/humidity I am planning on using a 55watt car bulb for heater (maybe two if I need them) a servo motor to tilt the bed every six hours (egg need to be turned every six hours to develop correctly). I have designed and printed a egg bed to hold 9 eggs and fittings to attach bed to servo motor. I have pc power supply converted to power bulb. Now im going to try to control 55 watt bulb with pwm from arduino to hold temp at 32 degrees c or some temp close depending on eggs im incubating. I have got mosfet (fqp30n06l) to control bulb.

 

My questions at this point are:

1. Is this the best way to approach this project (I do want to learn to use pwm from input from temp sensor).

2. What wiring circuit is correct for mosfet (Can I just use it direct).

3. I have put the 12volt pc power supply ground into arduino ground is this ok(correct way of doing it).

4. For timer to turn bed every six hours will I need something like a real time clock.

5. How do I use all the code together on arduino can I write them on different tabs

6. Any help with code would be a big help but please explain what is happening with comments as I do want to learn wats happening please.

 

Thanks in advance for any input.

  • Sign in to reply
  • Cancel

Top Replies

  • clem57
    clem57 over 10 years ago +2 suggested
    1. See https://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor 2/3. Follow this bildr » High-Power Control: Arduino + N-Channel MOSFET 4. A way to get time for your Arduino https://learn.adafruit.com…
Parents
  • mk1manno
    0 mk1manno over 10 years ago

    Hey all

     

    trying to get pid working in this using dht22 but cant get it to work any input heres my code

     

    // Example testing sketch for various DHT humidity/temperature sensors
    // Written by ladyada, public domain

    #include "DHT.h"
    #include <PID_v1.h>

    #define DHTPIN 12     // what pin we're connected to

    // Uncomment whatever type you're using!
    //#define DHTTYPE DHT11   // DHT 11
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    //#define DHTTYPE DHT21   // DHT 21 (AM2301)

    // Connect pin 1 (on the left) of the sensor to +5V
    // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
    // to 3.3V instead of 5V!
    // Connect pin 2 of the sensor to whatever your DHTPIN is
    // Connect pin 4 (on the right) of the sensor to GROUND
    // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

    // Initialize DHT sensor for normal 16mhz Arduino
    DHT dht(DHTPIN, DHTTYPE);
    // NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
    // might need to increase the threshold for cycle counts considered a 1 or 0.
    // You can do this by passing a 3rd parameter for this threshold.  It's a bit
    // of fiddling to find the right value, but in general the faster the CPU the
    // higher the value.  The default for a 16mhz AVR is a value of 6.  For an
    // Arduino Due that runs at 84mhz a value of 30 works.
    // Example to initialize DHT sensor for Arduino Due:
    //DHT dht(DHTPIN, DHTTYPE, 30);


    int heater = 3;

    //Define Variables we'll be connecting to
    double Setpoint, Input, Output,t;

    //Specify the links and initial tuning parameters
    PID myPID(&Input, &Output, &Setpoint,2,3,0, DIRECT);


    void setup() {
      Serial.begin(9600);
      Serial.println("DHTxx test!");

      dht.begin();
    // from here is heater control.
       pinMode (heater, OUTPUT);
      
        //initialize the variables we're linked to
      Input = t;
      Setpoint = 24.0;

      //turn the PID on
      myPID.SetMode(AUTOMATIC);

      
    }

    void loop() {
     
    // Wait a few seconds between measurements.
      delay(2000);

      // 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();
      // Read temperature as Celsius
      float t = dht.readTemperature();
      // Read temperature as Fahrenheit
      float f = dht.readTemperature(true);
     
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }

      // Compute heat index
      // Must send in temp in Fahrenheit!
      float hi = dht.computeHeatIndex(f, h);

      Serial.print("Humidity: ");
      Serial.print(h);
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.print(" *C ");
      Serial.print(f);
      Serial.print(" *F\t");
      Serial.print("Heat index: ");
      Serial.print(hi);
      Serial.println(" *F");
     
    //from here is heater control.
    //analogWrite(heater, 100);

    //if (t <= 31)
    //     {analogWrite(heater, 254);}
         
    //else if (t >= 33)
             // {analogWrite(heater, 20);}
             
    //else {analogWrite(heater, 100);}
         
       
      myPID.Compute();
      analogWrite(heater,Output); 
     
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • mk1manno
    0 mk1manno over 10 years ago

    Hey all

     

    trying to get pid working in this using dht22 but cant get it to work any input heres my code

     

    // Example testing sketch for various DHT humidity/temperature sensors
    // Written by ladyada, public domain

    #include "DHT.h"
    #include <PID_v1.h>

    #define DHTPIN 12     // what pin we're connected to

    // Uncomment whatever type you're using!
    //#define DHTTYPE DHT11   // DHT 11
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    //#define DHTTYPE DHT21   // DHT 21 (AM2301)

    // Connect pin 1 (on the left) of the sensor to +5V
    // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
    // to 3.3V instead of 5V!
    // Connect pin 2 of the sensor to whatever your DHTPIN is
    // Connect pin 4 (on the right) of the sensor to GROUND
    // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

    // Initialize DHT sensor for normal 16mhz Arduino
    DHT dht(DHTPIN, DHTTYPE);
    // NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
    // might need to increase the threshold for cycle counts considered a 1 or 0.
    // You can do this by passing a 3rd parameter for this threshold.  It's a bit
    // of fiddling to find the right value, but in general the faster the CPU the
    // higher the value.  The default for a 16mhz AVR is a value of 6.  For an
    // Arduino Due that runs at 84mhz a value of 30 works.
    // Example to initialize DHT sensor for Arduino Due:
    //DHT dht(DHTPIN, DHTTYPE, 30);


    int heater = 3;

    //Define Variables we'll be connecting to
    double Setpoint, Input, Output,t;

    //Specify the links and initial tuning parameters
    PID myPID(&Input, &Output, &Setpoint,2,3,0, DIRECT);


    void setup() {
      Serial.begin(9600);
      Serial.println("DHTxx test!");

      dht.begin();
    // from here is heater control.
       pinMode (heater, OUTPUT);
      
        //initialize the variables we're linked to
      Input = t;
      Setpoint = 24.0;

      //turn the PID on
      myPID.SetMode(AUTOMATIC);

      
    }

    void loop() {
     
    // Wait a few seconds between measurements.
      delay(2000);

      // 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();
      // Read temperature as Celsius
      float t = dht.readTemperature();
      // Read temperature as Fahrenheit
      float f = dht.readTemperature(true);
     
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }

      // Compute heat index
      // Must send in temp in Fahrenheit!
      float hi = dht.computeHeatIndex(f, h);

      Serial.print("Humidity: ");
      Serial.print(h);
      Serial.print(" %\t");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.print(" *C ");
      Serial.print(f);
      Serial.print(" *F\t");
      Serial.print("Heat index: ");
      Serial.print(hi);
      Serial.println(" *F");
     
    //from here is heater control.
    //analogWrite(heater, 100);

    //if (t <= 31)
    //     {analogWrite(heater, 254);}
         
    //else if (t >= 33)
             // {analogWrite(heater, 20);}
             
    //else {analogWrite(heater, 100);}
         
       
      myPID.Compute();
      analogWrite(heater,Output); 
     
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • clem57
    0 clem57 over 10 years ago in reply to mk1manno

    Any output? The serial command could be used liberally to show how the program is proceeding. Print out any variables that may have significance.

    Clem 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • bobcroft
    0 bobcroft over 10 years ago in reply to mk1manno

    Sean,

              not sure what you are using for a heater but with a system such as yours I doubt PID will work very well at all.  Firstly these sensors are very slow as typified by the 250 mS response time and the 2 seconds between readings.  Secondly there is the thermal lag of the heater and the thermal mass of the system.  All in all the system becomes very unresponsive.

    An alternative may be to use PWM to control the power to / from the heater and build in control of the on / off based on trial runs.  For example if the heater is required to turn off at 18 degrees C and the temperature over shot to 20 degrees then you could actually turn if off at 16 degrees in the program.  You could log the temperature over a period of time using Coolterm with a log file.

     

    I appreciate this is not the answer you asked for but it is an alternative approach.

     

    Bob

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to bobcroft

    PID will not work any less well because the system is slow - you just need to take that into account when calculating the PID loop constants.

     

    Almost all low cost commercial temperature controllers use modified PID control loops - they work equally well with time constants from a few tens of seconds to hours or days.

     

    @ Sean - is the any documentation for the PID library you are using ?

     

    When you say it doesn't work - what exactly is happening ?

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mk1manno
    0 mk1manno over 10 years ago in reply to michaelkellett

    This is Library I'm useing http://playground.arduino.cc/Code/PIDLibrary also have this http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

     

    What what is happening is with code I have input as t.so I want to read t as temp and I have set point at 24 and my output is analog write to gate pin of a MOSFET that controls a 55 watt 12 volt bulb for heater when I run setup temp just keeps climing up to max heat about 39 deg c also when running and I serial read it freezes a lot not every time but 4 out of 5 times.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to mk1manno

    I think you may have several problems:

     

    The PID code you are using is designed to be called much more often than its sample time which is set to 100mS by default. If your slow sensors mean that you are only calling it perhaps every 250mS you should set the sample time in the PID code to at least 2500 mS. But because your system is very slow I would be tempted to set the sample time longer to perhaps 10 or 20 seconds (10000 or 20000).

     

    To tune your system set the I and D terms to zero and the proportional term to 25  - this will mean that you get full power out when the error is 10C.

     

    Plot the temperature against the heater power and see if it does what you expect.

     

    Does your heater respond to the analogWrite correctly ?

     

    Are your serial prints working OK - what device do you send them to.

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • mk1manno
    0 mk1manno over 10 years ago in reply to michaelkellett

    Hey sorry so late getting back to you thanks for all the help have it up and running now and its working good with your info used.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to mk1manno

    Hey.. I am interested to yr project.. can i get de programming code from u? Your reply will be highly appreciated.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • khorshidalam
    0 khorshidalam over 8 years ago in reply to mk1manno

    But there is no egg tray turning option.......................electric motor rocks the eggs 4 times a day (24h) backwards and forwards..................any code?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube