Automatic IoT Eggs Incubator
Observe automatic eggs incubation from any location.
Components and supplies
1
Servo Module (Generic)
1
Bulb 100 WATT (heating Filament type)
1
Humidifier
1
NodeMCU ESP8266 Breakout Board
1
Arduino UNO
1
DHT11 Temperature & Humidity Sensor (3 pins)
2
PC cpu cooling fan
Project description
Code
IoT Incubator
c_cpp
In Arduino IDE for ESP8266 (Node MCU)
1#include <Servo.h> 2#include <DHT.h> // library of DHT11 temperature and humidity sensor 3#include <CavyIoTdevelopmentBoard.h> 4//----------------------Servo Connection--------------------------------------------- 5#define SERVO 9 6Servo myservo; 7//----------------------DHT11 connection------------------------------------ 8DHT dht(8, DHT11); 9//-------------------------------------------------------------------------- 10 11//---------------For communication with DevBoard ---------------------------- 12#define rx 10 13#define tx 11 14#define rst 13 15//--------------------------------------------------------------------------- 16CavyIoT myIoTdevice; //Create instance of CavyIoT Object. 17//--------------------------------------------------------------------------- 18//----------------Timer and Scheme of Eggs Tray Router----------------------- 19int routerScheme=1; 20long int current_time; 21long int start_time=millis(); 22long int Interval=6*60*60*1000;//Timer Six hour 23//Interval=60000;//Uncomment for checking servo functions TimerOne minute. 24//--------------------------------------------------------------------------- 25//--------------------- Sensor Variables ------------------------------------ 26float temp; 27float hum; 28int angle; 29//-------------------------------------------------------------------------- 30void setup() 31 { 32 Serial.begin(9600); 33 myIoTdevice.SetPort(rx,tx,rst); 34 dht.begin(); 35 myservo.write(45); 36 myservo.attach(9); 37 myservo.detach(); 38 39//--------------------- Button Labels---------------------------------------- 40 Serial.println("Setting device buttons!."); 41 myIoTdevice.DefineButtonLables 42 ( "Heat", "on", "off", 43 "Humid", "on", "off", 44 "E-Fan", "on"," off", 45 "I-Fan", "on", "off" 46 ); 47 Serial.println("Wait for a while to connect!"); 48 /*------To start Device replace your own credentials here-----------------------------*/ 49 myIoTdevice.StartDevice 50 /*Your Wi-Fi router->*/("WiFi-SSID","WiFi-password", 51 /* CavyIoT------>*/"Username","password","Device");// 52 //-------------------------------------------------------------------------- 53 } 54 55void loop() 56 { 57 current_time=millis(); 58 myIoTdevice.loop(); //Updates the Status variable. 59 //--------------------------------------------------------------------- 60 /* Prints the current status of Buttons & working mode of device from control panel on Serial monitor.*/ 61 Serial.println("Device Status:-"+myIoTdevice.Status); 62 63 //---------Read values from sensor and angle of servo--------------------- 64 65 temp=dht.readTemperature(); 66 hum=dht.readHumidity(); 67 68 //----------------Sending data to server---------------------------------- 69 myIoTdevice.UpdateSensorData 70 ( "Temperature",String(temp), "C", 71 "humidity", String(hum), "Rh", 72 "Tray-Angle", String(angle), "deg" 73 ); 74 //-------------------Check timer for router scheme------------------------- 75 if(current_time-start_time>Interval) 76 { myservo.attach(9); 77 rotateTray(routerScheme); 78 start_time=current_time; 79 //Uncomment for debug 80 //Serial.print("Servo is working ,router scheme :"); 81 //Serial.println(routerScheme); 82 83 } 84 //------------------------------------------------------------------------- 85 86 87}//End of loop 88 //----------------------------------------------------------------------- 89 90///////////////////////////////////////////////////////////////////////////// 91 92///////////////////////////////////////////////////////////////////////////// 93void rotateTray(int scheme) 94{ int current_position=myservo.read(); 95 96 if (scheme==0) 97 { 98 for(current_position;current_position <=45;current_position+= 1) 99 { angle= current_position; 100 myservo.write(current_position); // tell servo to go to position // variable 'current_position' 101 delay(50); // for smoother movement of Servo. 102 103 } 104 105 } 106if (scheme==1) 107 { 108 for(current_position;current_position <=90;current_position+= 1) 109 {angle= current_position; 110 myservo.write(current_position); // tell servo to go to position // variable 'current_position' 111 delay(50); // for smoother movement of Servo. 112 113 } 114 } 115if (scheme==2) 116 { 117 for(current_position;current_position >=45;current_position-= 1) 118 { angle= current_position; 119 myservo.write(current_position); // tell servo to go to position // variable 'current_position' 120 delay(50); // for smoother movement of Servo. 121 122 } 123 } 124 if (scheme==3) 125 { 126 127 for(current_position;current_position >=0;current_position-= 1) 128 { 129 angle= current_position; 130 myservo.write(current_position); // tell servo to go to position // variable 'current_position' 131 delay(50); // for smoother movement of Servo. 132 133 } 134 } 135 136 routerScheme=routerScheme+1; 137 myservo.detach(); 138 if(routerScheme>3)routerScheme=0; 139}
Comments
Only logged in users can leave comments