Greenhouse Climate Observation Module

Dependencies:   BSP_DISCO_F746NG DHT

Committer:
chri721u
Date:
Tue Jan 21 12:28:42 2020 +0000
Revision:
0:a5831f680465
Child:
1:4363657c576d
Current version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chri721u 0:a5831f680465 1 /*
chri721u 0:a5831f680465 2 Developer: Christian Andresen
chri721u 0:a5831f680465 3
chri721u 0:a5831f680465 4 Project name: Project Greenhouse
chri721u 0:a5831f680465 5
chri721u 0:a5831f680465 6 Brief description:
chri721u 0:a5831f680465 7 Microcontroller observing the climate within a greenhouse, and displaying warnings/information as needed.
chri721u 0:a5831f680465 8 Sensors monitor light levels, as well as temperature and humidity.
chri721u 0:a5831f680465 9 To simulate an actual greenhouse, LEDs will be used in place of actual influences.
chri721u 0:a5831f680465 10
chri721u 0:a5831f680465 11 Objectives:
chri721u 0:a5831f680465 12 - Able to set controller location (Which section/greenhouse is it located in)
chri721u 0:a5831f680465 13 - Able to open window at certain temperature tresholds (For 5 minutes)
chri721u 0:a5831f680465 14 - Water plants at regular intervals (Twice a day)
chri721u 0:a5831f680465 15 - Plants must have light for at least 12 hours. If weather is cloudy, artificial lights.
chri721u 0:a5831f680465 16 - Testmode: Alternate time-tracking system, much faster than 24 hour system.
chri721u 0:a5831f680465 17 */
chri721u 0:a5831f680465 18
chri721u 0:a5831f680465 19 #include "mbed.h" // Mbed header from mbed-os version 5
chri721u 0:a5831f680465 20 #include "stm32746g_discovery_lcd.h" // Last updated 27/11/2019
chri721u 0:a5831f680465 21 #include "DHT.h" // Author: Wim De Roeve
chri721u 0:a5831f680465 22 #include "bootup.h" // Author: Christian Andresen
chri721u 0:a5831f680465 23
chri721u 0:a5831f680465 24 // Sensor Inputs
chri721u 0:a5831f680465 25 AnalogIn temp_sensor(A0);
chri721u 0:a5831f680465 26 DHT humid_sensor(A1, DHT22);
chri721u 0:a5831f680465 27 AnalogIn light_sensor(A2);
chri721u 0:a5831f680465 28
chri721u 0:a5831f680465 29 /* LED Outputs */
chri721u 0:a5831f680465 30 DigitalOut temp_led(D5); // Red LED
chri721u 0:a5831f680465 31 DigitalOut water_led(D6); // Blue LED
chri721u 0:a5831f680465 32 DigitalOut window_led(D7); // Green LED
chri721u 0:a5831f680465 33 DigitalOut light_led(D8); // Yellow LED
chri721u 0:a5831f680465 34
chri721u 0:a5831f680465 35 // Call Bootup class from bootup.h as LCD_Start
chri721u 0:a5831f680465 36 bootup LCD_Start;
chri721u 0:a5831f680465 37
chri721u 0:a5831f680465 38 // Multithreading threads
chri721u 0:a5831f680465 39 Thread tTemp;
chri721u 0:a5831f680465 40 Thread tHumid;
chri721u 0:a5831f680465 41 Thread tLight;
chri721u 0:a5831f680465 42 Thread tWater;
chri721u 0:a5831f680465 43
chri721u 0:a5831f680465 44 uint8_t text[30]; // Prepare text element for later print to LCD
chri721u 0:a5831f680465 45
chri721u 0:a5831f680465 46 void Window_Open()
chri721u 0:a5831f680465 47 {
chri721u 0:a5831f680465 48 for( int a = 1; a < 10; a = a + 1 ) {
chri721u 0:a5831f680465 49 window_led = 1;
chri721u 0:a5831f680465 50 wait(1);
chri721u 0:a5831f680465 51 printf("Window open for %d minutes", a);
chri721u 0:a5831f680465 52 }
chri721u 0:a5831f680465 53 window_led = 0;
chri721u 0:a5831f680465 54 }
chri721u 0:a5831f680465 55
chri721u 0:a5831f680465 56 void Temp_Display()
chri721u 0:a5831f680465 57 {
chri721u 0:a5831f680465 58 while(1) {
chri721u 0:a5831f680465 59 // Monitor temperatures and display results on LCD screen
chri721u 0:a5831f680465 60 float temp = temp_sensor.read();
chri721u 0:a5831f680465 61 wait(1);
chri721u 0:a5831f680465 62 sprintf((char*)text, "Temperature: %.1f C", temp*100/2);
chri721u 0:a5831f680465 63 BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)&text, CENTER_MODE);
chri721u 0:a5831f680465 64 }
chri721u 0:a5831f680465 65 }
chri721u 0:a5831f680465 66
chri721u 0:a5831f680465 67 void Humid_Display()
chri721u 0:a5831f680465 68 {
chri721u 0:a5831f680465 69 while(1) {
chri721u 0:a5831f680465 70 // Monitor humidity and display results on LCD screen
chri721u 0:a5831f680465 71 float humid = humid_sensor.ReadHumidity();
chri721u 0:a5831f680465 72 wait(1);
chri721u 0:a5831f680465 73 sprintf((char*)text, "Humidity: %.1f", humid);
chri721u 0:a5831f680465 74 BSP_LCD_DisplayStringAt(0, 175, (uint8_t *)&text, CENTER_MODE);
chri721u 0:a5831f680465 75 }
chri721u 0:a5831f680465 76 }
chri721u 0:a5831f680465 77
chri721u 0:a5831f680465 78 int main()
chri721u 0:a5831f680465 79 {
chri721u 0:a5831f680465 80 LCD_Start.LCD_Bootup();
chri721u 0:a5831f680465 81 // Start multithread
chri721u 0:a5831f680465 82 tTemp.start(&Temp_Display);
chri721u 0:a5831f680465 83 tHumid.start(&Humid_Display);
chri721u 0:a5831f680465 84 }