Greenhouse Climate Observation Module
Dependencies: BSP_DISCO_F746NG DHT
main.cpp@1:4363657c576d, 2020-01-22 (annotated)
- Committer:
- chri721u
- Date:
- Wed Jan 22 07:27:47 2020 +0000
- Revision:
- 1:4363657c576d
- Parent:
- 0:a5831f680465
- Child:
- 2:739ba85b7a90
V0.1; Enabled accurate temperature measurement(celsius); Enabled accurate humidity measurement
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:4363657c576d | 17 | |
chri721u | 1:4363657c576d | 18 | REMEMBER TO RETURN BORROWED LED SOCKETS |
chri721u | 0:a5831f680465 | 19 | */ |
chri721u | 0:a5831f680465 | 20 | |
chri721u | 0:a5831f680465 | 21 | #include "mbed.h" // Mbed header from mbed-os version 5 |
chri721u | 0:a5831f680465 | 22 | #include "stm32746g_discovery_lcd.h" // Last updated 27/11/2019 |
chri721u | 0:a5831f680465 | 23 | #include "DHT.h" // Author: Wim De Roeve |
chri721u | 0:a5831f680465 | 24 | #include "bootup.h" // Author: Christian Andresen |
chri721u | 0:a5831f680465 | 25 | |
chri721u | 0:a5831f680465 | 26 | // Sensor Inputs |
chri721u | 0:a5831f680465 | 27 | AnalogIn temp_sensor(A0); |
chri721u | 0:a5831f680465 | 28 | DHT humid_sensor(A1, DHT22); |
chri721u | 0:a5831f680465 | 29 | AnalogIn light_sensor(A2); |
chri721u | 0:a5831f680465 | 30 | |
chri721u | 0:a5831f680465 | 31 | /* LED Outputs */ |
chri721u | 1:4363657c576d | 32 | DigitalOut humid_led(D2); // Blue LED |
chri721u | 0:a5831f680465 | 33 | DigitalOut temp_led(D5); // Red LED |
chri721u | 0:a5831f680465 | 34 | DigitalOut water_led(D6); // Blue LED |
chri721u | 0:a5831f680465 | 35 | DigitalOut window_led(D7); // Green LED |
chri721u | 0:a5831f680465 | 36 | DigitalOut light_led(D8); // Yellow LED |
chri721u | 0:a5831f680465 | 37 | |
chri721u | 0:a5831f680465 | 38 | // Call Bootup class from bootup.h as LCD_Start |
chri721u | 0:a5831f680465 | 39 | bootup LCD_Start; |
chri721u | 0:a5831f680465 | 40 | |
chri721u | 0:a5831f680465 | 41 | // Multithreading threads |
chri721u | 0:a5831f680465 | 42 | Thread tTemp; |
chri721u | 0:a5831f680465 | 43 | Thread tHumid; |
chri721u | 0:a5831f680465 | 44 | Thread tLight; |
chri721u | 0:a5831f680465 | 45 | Thread tWater; |
chri721u | 0:a5831f680465 | 46 | |
chri721u | 0:a5831f680465 | 47 | uint8_t text[30]; // Prepare text element for later print to LCD |
chri721u | 0:a5831f680465 | 48 | |
chri721u | 0:a5831f680465 | 49 | void Window_Open() |
chri721u | 0:a5831f680465 | 50 | { |
chri721u | 0:a5831f680465 | 51 | for( int a = 1; a < 10; a = a + 1 ) { |
chri721u | 0:a5831f680465 | 52 | window_led = 1; |
chri721u | 0:a5831f680465 | 53 | wait(1); |
chri721u | 0:a5831f680465 | 54 | printf("Window open for %d minutes", a); |
chri721u | 0:a5831f680465 | 55 | } |
chri721u | 0:a5831f680465 | 56 | window_led = 0; |
chri721u | 0:a5831f680465 | 57 | } |
chri721u | 0:a5831f680465 | 58 | |
chri721u | 1:4363657c576d | 59 | void Water_Spray() |
chri721u | 1:4363657c576d | 60 | { |
chri721u | 1:4363657c576d | 61 | // While humidity is under acceptable levels, this function would spray water. Since it cannot be acurately simultaed, this function will largely remain empty. |
chri721u | 1:4363657c576d | 62 | humid_led = 1; |
chri721u | 1:4363657c576d | 63 | wait(0.5); |
chri721u | 1:4363657c576d | 64 | humid_led = 0; |
chri721u | 1:4363657c576d | 65 | |
chri721u | 1:4363657c576d | 66 | } |
chri721u | 1:4363657c576d | 67 | |
chri721u | 0:a5831f680465 | 68 | void Temp_Display() |
chri721u | 0:a5831f680465 | 69 | { |
chri721u | 0:a5831f680465 | 70 | while(1) { |
chri721u | 0:a5831f680465 | 71 | // Monitor temperatures and display results on LCD screen |
chri721u | 0:a5831f680465 | 72 | float temp = temp_sensor.read(); |
chri721u | 0:a5831f680465 | 73 | wait(1); |
chri721u | 0:a5831f680465 | 74 | sprintf((char*)text, "Temperature: %.1f C", temp*100/2); |
chri721u | 0:a5831f680465 | 75 | BSP_LCD_DisplayStringAt(0, 125, (uint8_t *)&text, CENTER_MODE); |
chri721u | 0:a5831f680465 | 76 | } |
chri721u | 0:a5831f680465 | 77 | } |
chri721u | 0:a5831f680465 | 78 | |
chri721u | 0:a5831f680465 | 79 | void Humid_Display() |
chri721u | 0:a5831f680465 | 80 | { |
chri721u | 0:a5831f680465 | 81 | while(1) { |
chri721u | 1:4363657c576d | 82 | humid_led = 1; |
chri721u | 0:a5831f680465 | 83 | // Monitor humidity and display results on LCD screen |
chri721u | 0:a5831f680465 | 84 | float humid = humid_sensor.ReadHumidity(); |
chri721u | 1:4363657c576d | 85 | int dataread = humid_sensor.readData(); |
chri721u | 0:a5831f680465 | 86 | wait(1); |
chri721u | 0:a5831f680465 | 87 | sprintf((char*)text, "Humidity: %.1f", humid); |
chri721u | 0:a5831f680465 | 88 | BSP_LCD_DisplayStringAt(0, 175, (uint8_t *)&text, CENTER_MODE); |
chri721u | 1:4363657c576d | 89 | |
chri721u | 1:4363657c576d | 90 | if(humid > 70) { |
chri721u | 1:4363657c576d | 91 | Window_Open(); |
chri721u | 1:4363657c576d | 92 | } else if(humid < 50) { |
chri721u | 1:4363657c576d | 93 | Water_Spray(); |
chri721u | 1:4363657c576d | 94 | } |
chri721u | 0:a5831f680465 | 95 | } |
chri721u | 0:a5831f680465 | 96 | } |
chri721u | 0:a5831f680465 | 97 | |
chri721u | 0:a5831f680465 | 98 | int main() |
chri721u | 0:a5831f680465 | 99 | { |
chri721u | 0:a5831f680465 | 100 | LCD_Start.LCD_Bootup(); |
chri721u | 0:a5831f680465 | 101 | // Start multithread |
chri721u | 1:4363657c576d | 102 | tHumid.start(&Humid_Display); |
chri721u | 0:a5831f680465 | 103 | tTemp.start(&Temp_Display); |
chri721u | 1:4363657c576d | 104 | while(1) {} |
chri721u | 0:a5831f680465 | 105 | } |