# GreenLab, an IoT-Based Small-Scale Smart Greenhouse
## 3 GreenLab Project
### System Design
#### 3.2.2 Software Design  
Following the same IoT layered architecture approach for the software design, we have chosen three layers, containing the perception layer, the network layer, and the application layer [21]. A schematic of the proposed architecture is presented in Figure 7.  
The perception layer which is responsible for the system-environment interaction provides functionalities such as data acquisition from the sensors and control modules for the actuators as it can be seen in Figure 8. The main environment parameters to be controlled are the temperature, the ambient light, and the soil moisture, which are monitored through sensors, and their level is adjusted through actuators like fans, LEDs, and water pumps.  
Figure 8: Perception layer workflow.  
Figure 6: Ventilation and heating block diagram.  
Figure 7: Software layered architecture.  
Next, we will present the flowchart for each main control system module based on the sensors' readings. For the irrigation module, the flowchart is depicted in Figure 9. When the soil moisture sensor detects that the soil has reached the dryness threshold, the board closes the relay that controls the submersible pump. It draws water from the container and through a pipe and moistens the soil. This operation is interrupted by opening the assigned relay in the relay block in one of the following situations:  
* The soil moisture detection sensor tells the development board that the soil is sufficiently moist;
* A preset number (5) of seconds has elapsed since the relay closed;
* The ultrasonic distance sensor tells the plate that there is no more water in the container (the distance from the sensor to the float in the vessel is more than 10 cm and the water level is below the suction mouth of the pump).  
For the lighting module, the flowchart is depicted in Figure 10. The light sensor detects the difference between day and night (the absence of light) and communicates the status to the microcontroller which turns on or off the LED matrices according to the day/night functioning mode.  
For the ventilation and heating module, the flowchart is depicted in Figures 11 and 12. The control of the fans is carried out by turning on or off the relays in the following situations:  
* The gas sensor detects an amount of gas above a defined threshold;
* The temperature sensor detects a temperature above/below a defined threshold.  
The network layer provides the communication between the perception and the application layers.  
Figure 9: Irrigation flow chart.  
The application layer offers the possibility to visualize and monitor the data acquired by the perception layer. A mobile application is responsible for visualizing the evolution of each parameter, by using 24 h or 7-day data records and for direct control of the actuators, by providing a manual command mode of operation for the system. As basic security measures, authentication and authorization roles were defined and implemented. In Figure 13, there is a caption of the graphical user interface for the manual commands for an authenticated user with control rights.  
Figure 11: Ventilation flow chart.  
Figure 10: Lighting flow chart.