DIY Mushroom Smart Farm
Smart farming? IoT? That’s the trend. Garden easier, farm easier. Join us to cultivate some juicy mushrooms in your very own living room!!
Components and supplies
1
5 mm LED: Red
1
Arduino Due
1
ZS-042 RTC (Real Time Clock) Module
1
Graphic OLED, 128 x 64
1
Power MOSFET N-Channel
1
Humidity Sensor, 3.5 %
1
Temperature Sensor
1
Arduino MKR1000
1
High Brightness LED, White
3
Prolight RGB 3 Watt Star
Project description
Code
Download the CODE HERE!
arduino
1 2 #include <IRremote.h> //Lib for IT Blaster and TSOP 3 #include <SPI.h> // Inbuilt Lib 4 #include <Wire.h> //Inbuilt Lib 5 #include <Adafruit_GFX.h> //Lib for OLED 6 #include <Adafruit_SSD1306.h> //Lib for OLED 7 #include <dht.h> //Library for dht11 Temperature and Humidity sensor (Download from Link in article) 8#include "RTClib.h" 9#include "ChannelManager.h" 10 11 12 // Assign pins for OLED (Software config.) 13#define OLED_MOSI 3 14#define OLED_CLK 4 15#define OLED_DC 5 16#define OLED_CS 6 17#define OLED_RESET 7 18Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 19#define SSD1306_LCDHEIGHT 64 //Change if you are using a Different OLED 20#define DHT11_PIN 13 //Sensor output pin is connected to pin 13 21dht DHT; //Sensor object named as DHT 22#define Desired_temperature 23 //The desired temperature is 23*C at any time 23//Decoded Remote Signals For my AC ##CHANGE IT FOR YOUR REMOTE 24unsigned int ACoff[] = {2950,1750, 400,1100, 450,1050, 450,400, 400,400, 400,400, 450,1100, 400,400, 400,400, 450,1100, 400,1100, 450,350, 450,1100, 400,400, 400,400, 450,1100, 400,1100, 450,400, 400,1100, 400,1100, 450,400, 400,400, 400,1100, 450,350, 450,400, 400,1100, 450,400, 400,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,350, 450,350, 450,1100, 400,400, 450,400, 400,1100, 450,1050, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,1100, 450,350, 450,400, 400,400, 400,400, 450,400, 400,1100, 450,350, 450,400, 400,400, 400,400, 400,1100, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 400,1100, 450,350, 450,350, 450,400, 450,350, 450,350, 450,1100, 450}; 25unsigned int ACon[] = {2950,1700, 450,1100, 400,1100, 450,350, 450,350, 450,400, 450,1050, 450,350, 450,400, 450,1050, 450,1100, 400,400, 450,1050, 450,350, 450,400, 400,1100, 450,1100, 450,350, 450,1050, 450,1100, 450,350, 450,350, 450,1100, 450,350, 400,400, 450,1100, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,1100, 400,400, 450,350, 450,1100, 400,400, 450,350, 450,1100, 400,1100, 450,350, 450,400, 400,400, 450,350, 500,300, 450,400, 450,350, 400,400, 450,1100, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,1100, 450,350, 400,400, 450,350, 450,400, 450,350, 400,400, 450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 400,400, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 450,350, 400,400, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 450,350, 450,1100, 400,400, 400,400, 450,350, 450,350, 450,1100, 400,400, 450}; 26unsigned int Temp23[] = {3000,1650, 550,950, 550,1000, 500,300, 550,250, 550,250, 550,1000, 500,300, 550,300, 500,1000, 550,950, 550,300, 550,950, 550,250, 550,300, 500,1000, 500,1050, 500,300, 500,1000, 550,1000, 500,300, 500,300, 550,1000, 450,350, 500,300, 500,1050, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,1100, 400,400, 400,400, 450,1050, 450,400, 400,400, 450,1100, 400,1100, 400,400, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,350, 450,1100, 400,400, 400,400, 450,350, 450,400, 400,400, 450,1100, 400,400, 400,1100, 450,1100, 400,1100, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 450,350, 400,400, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,1100, 400,1100, 450,1100, 400,1100, 450,1100, 400,1100, 400,400, 450}; 27unsigned int Temp24[] = {3000,1650, 500,1050, 500,1000, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300, 500,1000, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,1000, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,1000, 500,1050, 500,1000, 500,300, 500,350, 450,350, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,1050, 500,1000, 500,1050, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,300, 500,350, 500,300, 450,350, 500,350, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 500,350, 450,1050, 500,300, 500,1050, 500,1000, 500,1050, 500,1000, 500,1000, 500,350, 550}; 28unsigned int Temp25[] = {3050,1650, 500,1000, 550,950, 550,300, 500,300, 500,300, 550,1000, 500,300, 500,300, 550,1000, 550,950, 550,250, 550,1000, 500,300, 550,250, 550,1000, 500,1000, 550,300, 550,950, 550,950, 550,300, 500,300, 500,1000, 550,250, 550,300, 550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 600,250, 500,300, 550,250, 550,250, 550,300, 550,250, 500,300, 550,300, 500,300, 500,1000, 550,250, 550,300, 500,1000, 550,250, 550,300, 500,1000, 550,1000, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,1000, 550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,950, 550,300, 500,1000, 550,1000, 500,1000, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 500,350, 500,1000, 500,1000, 500,1050, 500,1000, 500,1050, 500,300, 550}; 29unsigned int Temp26[] = {3000,1650, 500,1000, 500,1050, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 450,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300, 500,1000, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 450,350, 500,300, 500,1050, 500,1000, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,1050, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,1050, 450,1050, 500,1000, 500,350, 500,300, 500,300, 500,350, 450,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 450,350, 500,300, 500,350, 450,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 450,1050, 500,1000, 500,350, 500,1000, 500,1000, 500,1050, 500,1000, 500,350, 500}; 30unsigned int Temp27[] = {3050,1600, 550,1000, 500,1000, 550,300, 500,300, 550,250, 550,1000, 500,300, 550,300, 500,1000, 550,1000, 500,300, 550,1000, 550,250, 500,300, 550,1000, 500,1050, 500,300, 500,1000, 550,1000, 500,300, 550,250, 550,1000, 550,250, 550,300, 500,1000, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,1000, 550,300, 500,300, 550,1000, 500,300, 500,300, 550,1000, 550,1000, 500,300, 500,300, 550,250, 550,300, 500,300, 550,300, 500,300, 500,300, 550,1000, 500,300, 550,250, 550,300, 500,300, 500,300, 500,350, 500,300, 550,250, 550,1000, 500,1000, 550,1000, 500,300, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 500,300, 550,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 500,300, 500,350, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,1000, 500,1050, 500,1000, 500,350, 500}; // PANASONIC C4D3:64800024 31unsigned int Temp28[] = {3100,1600, 550,950, 550,1000, 550,250, 550,250, 550,250, 550,1000, 500,300, 500,300, 550,1000, 500,1000, 550,250, 550,1000, 500,300, 550,250, 550,1000, 550,950, 550,300, 500,1000, 550,950, 550,300, 550,250, 500,1000, 550,300, 500,300, 550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 550,250, 500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 600,250, 500,300, 500,300, 550,300, 500,300, 500,1000, 550,300, 500,300, 500,1000, 550,250, 550,300, 500,1000, 550,1000, 550,250, 550,250, 550,250, 550,300, 500,300, 550,250, 550,1000, 500,1000, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,1000, 500,300, 500,1000, 550,1000, 500,1000, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 550,250, 500,300, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,1000, 500,300, 500,300, 550,950, 550,1000, 500,1000, 550,1000, 500,300, 550}; 32unsigned int Temp29[] = {3100,1550, 600,950, 500,1000, 550,300, 500,300, 500,300, 550,950, 550,300, 550,250, 550,1000, 500,1000, 550,250, 550,1000, 500,300, 550,250, 550,950, 600,950, 550,250, 550,1000, 500,1000, 550,250, 600,250, 550,950, 550,250, 550,300, 550,950, 550,250, 550,300, 550,250, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,250, 600,250, 550,950, 550,250, 550,300, 500,1000, 550,250, 550,300, 550,950, 550,1000, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,1000, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,1000, 550,250, 550,1000, 500,1000, 550,1000, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,1000, 500,1000, 550,1000, 500,1000, 550,300, 500}; 33unsigned int Temp30[] = {3000,1650, 500,1000, 550,1000, 500,300, 500,300, 550,250, 550,1000, 500,300, 500,300, 550,1000, 550,950, 550,250, 550,1000, 550,250, 550,250, 550,1000, 550,950, 550,300, 500,1000, 550,950, 550,300, 500,300, 550,950, 550,300, 550,250, 550,1000, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,950, 550,300, 500,300, 500,1000, 550,250, 550,300, 550,950, 550,1000, 500,300, 550,250, 550,250, 600,250, 500,300, 550,250, 550,1000, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,950, 550,300, 500,1000, 550,950, 550,1000, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,950, 500,1050, 500,1000, 500,350, 500,1000, 500,1000, 500,1050, 500,300, 500}; 34//Change it for your remote 35IRsend irsend; 36int Measured_temp; 37int Measured_Humi; 38int AC_Temp; 39char temp_error = 2; 40int Pev_value; 41boolean AC = false; 42int khz = 38; // 38kHz carrier frequency for the NEC protocol 43const int MaxChannels = 1; // Max number of channels, change if more or less are required 44const int MaxPoints = 10; // Max number of light intensity points, change if more or less are required 45// RTC 46RTC_DS1307 RTC; 47// Time 48DateTime CurrentTime; 49 50Channel Channels[MaxChannels]; 51Point Points[MaxChannels][MaxPoints]; 52 53void InitializeChannels(int channels) { 54 // Channel 0: 55 int channelNo = 0; // Currently editing channel 0 56 int pin = 2; // Channel 0 uses pin 2 57 Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]); // Initialize channel and choose FadeMode 58 Channels[channelNo].AddPoint(8, 0, 0); // Add Point (can also use decimal values ranging from 0 to 1 if you prefer) 59 Channels[channelNo].AddPoint(8, 30, 255); 60 Channels[channelNo].AddPoint(9, 0, 255); 61 Channels[channelNo].AddPoint(9, 30, 0); 62} 63 64// ----------------------- Functions ----------------------- 65long lastUpdateTime = 0; 66 67// Update light intensity values 68void UpdateLights(DateTime currentTime) 69{ 70 long now = Seconds(currentTime.hour(), currentTime.minute(), currentTime.second()); // Convert current time to seconds since midnight 71 if(now != lastUpdateTime) // Perform update only if there is a perceivable change in time (no point wasting clock cycles otherwise) 72 { 73 for(int channel = 0; channel < MaxChannels; channel++) // For each Channel 74 { 75 analogWrite(Channels[channel].GetPin(), Channels[channel].GetLightIntensityInt(now)); // Get updated light intensity and write value to pin (update is performed when reading value) 76 } 77 } 78 lastUpdateTime = now; 79} 80 81 82// Convert HH:mm:ss -> Seconds since midnight 83long Seconds(int hours, int minutes, int seconds) { 84 return ((long)hours * 60 * 60) + (minutes * 60) + seconds ; 85} 86 87void setup() 88{ 89Serial.begin(9600); 90display.begin(SSD1306_SWITCHCAPVCC); 91display.clearDisplay(); 92 93// Initialize channel schedules 94InitializeChannels(MaxChannels); 95 96 // Clock 97 Wire.begin(); 98 RTC.begin(); 99 //RTC.adjust(DateTime(__DATE__, __TIME__)); // Set RTC time to sketch compilation time, only use for 1 (ONE) run. Will reset time at each device reset! 100} 101void loop() { 102 // Get current time 103 CurrentTime = RTC.now(); 104 105 // Update lights 106 UpdateLights(CurrentTime); 107 108 DHT.read11(DHT11_PIN); //Read the Temp and Humidity 109 Measured_temp = DHT.temperature + temp_error; 110 Measured_Humi = DHT.humidity; 111// text display tests 112 display.setTextSize(1); 113 display.setTextColor(WHITE); 114 display.setCursor(0,0); 115 display.print("Temperature: "); display.print(Measured_temp);display.println("C"); 116 display.setCursor(0,10); 117 display.print("Humidity: "); display.print(Measured_Humi);display.println("%"); 118 display.setCursor(0,20); 119 display.print("AC Temp: "); display.print(AC_Temp);display.println("C"); 120 display.display(); 121 delay(500); 122 display.clearDisplay(); 123 124 if ((Measured_temp <= (Desired_temperature-3)) && AC == true) //If AC is turned on and temperature is less than 3 degree of Desired value #24 turn off 125 { 126 irsend.sendRaw(ACoff, sizeof(ACoff) / sizeof(ACoff[0]), khz); delay(2000);//Send signal to Turn Off the AC 127 AC_Temp = 0; AC=false; 128 } 129 if ((Measured_temp >= Desired_temperature+4) && AC == false) //If AC is off and measured Temp is greater than Desired Temp 130 { 131 irsend.sendRaw(ACon, sizeof(ACon) / sizeof(ACon[0]), khz); delay(2000); //Send Signal to Turn On the AC 132 delay(2000); 133 irsend.sendRaw(Temp27, sizeof(Temp27) / sizeof(Temp27[0]), khz); //Send signal to set 27*C 134 AC_Temp = 27; AC=true; 135 } 136if ( Measured_temp != Pev_value) //Change the temperature only if the measured voltage value changes 137{ 138if (Measured_temp == Desired_temperature+3) //If AC is ON and measured temp is very very high than desired 139{ 140 irsend.sendRaw(Temp24, sizeof(Temp24) / sizeof(Temp24[0]), khz); delay(2000);//Send signal to set 24*C 141 AC_Temp = 24; 142} 143if (Measured_temp == Desired_temperature+2) //If AC is ON and measured temp is very high than desired 144{ 145 irsend.sendRaw(Temp25, sizeof(Temp25) / sizeof(Temp25[0]), khz); delay(2000);//Send signal to set 25*C 146 AC_Temp = 25; 147} 148if (Measured_temp == Desired_temperature+1) //If AC is ON and measured temp is very high than desired 149{ 150 irsend.sendRaw(Temp26, sizeof(Temp26) / sizeof(Temp26[0]), khz); delay(2000);//Send signal to set 26*C 151 AC_Temp = 26; 152} 153if (Measured_temp == 27 ) //If AC is ON and measured temp is desired value 154{ 155 irsend.sendRaw(Temp27, sizeof(Temp27) / sizeof(Temp27[0]), khz); //Send signal to set 27*C 156 AC_Temp = 27; 157} 158if (Measured_temp == Desired_temperature-1) //If AC is ON and measured temp is low than desired value 159{ 160 irsend.sendRaw(Temp28, sizeof(Temp28) / sizeof(Temp28[0]), khz); delay(2000);//Send signal to set 28*C 161 AC_Temp = 28; 162} 163if (Measured_temp == Desired_temperature-2 ) //If AC is ON and measured temp is very low than desired value 164{ 165 irsend.sendRaw(Temp29, sizeof(Temp29) / sizeof(Temp29[0]), khz); delay(2000);//Send signal to set 29*C 166 AC_Temp = 29; 167} 168if (Measured_temp == Desired_temperature-3 ) //If AC is ON and measured temp is very very low desired value 169{ 170 irsend.sendRaw(Temp30, sizeof(Temp30) / sizeof(Temp30[0]), khz); delay(2000);//Send signal to set 30*C 171 AC_Temp = 30; 172} 173} 174Pev_value = Measured_temp; 175} 176
Downloadable files
Assembling the Circuit
Assembling the Circuit

Assembling the Circuit
Assembling the Circuit

Comments
Only logged in users can leave comments