/pic16f18446-cnano-greenhouse

A plant monitoring system with PIC16F18446 which provides automated control of soil moisture and air humidity in a greenhouse. It also displays the environment parameters: air humidity, soil moisture and temperature.

Primary LanguageCOtherNOASSERTION

MCHP

Plant Monitoring System using PIC16F18446

The designed application must read data from the sensors, display the status of the environment, and adjust the environment settings in a closed feedback loop. The feedback is represented by the measured soil moisture and bythe air humidity values. To measure these values, a soil moisture sensor and a temperature and humidity sensor are needed. To adjust these environment characteristics levels, devices such as fans and water pumps need to be used. Based on the acquired data, the fans and the pump are operated in order to keep the optimum conditions for the plant to develop. The firmware puts the PIC® MCU in Sleep mode after completing the mentioned tasks, and it wakes it up every second using a timer interrupt, being also power efficient. By putting the device in Sleep mode, some of the device’s features are turned off decreasing the power consumption, without impacting the application functionalities.

The prototype diagram is presented below.


The components are interconnected according to the diagram presented below.


Related Documentation

Software Used

Hardware Used

Setup

The PIC16F18446 Curiosity Nano Development Board is used as the test platform.


The AC164162 Curiosity Nano Adapter evaluation kit is a hardware extension that eases the connection between the Curiosity Nano board and extension boards like the mikroBUS™ click boards and Xplained Pro extension boards. The extension board supports three click boards.


The software setup is described below.

Schematic:


Peripherals used:

  • MSSP1 (SPI) to display data on OLED C click
  • MSSP2 (I2C) to read data from Temp&Hum click
  • ADCC to read analog sensors (soil moisture, water level sensor)
  • TMR0 to generate interrupt every second

MCC Settings:

This application uses Foundation Services Libraries and Micro-E Clicks software provided through MCC. The following screenshots illustrate the settings from MCC.

ADCC:


MSSP1:

MSSP1 is generated by oledC


MSSP2:


TMR0:


MIKROE Clicks - Display - oledC:


Pin Manager:



Operation

The system starts by initializing the temperature and humidity sensor interface, the OLED display interface and the timer. After the initialization, the following operations are executed in the main loop:

  1. Clear the WDT
  • If the WDT is not cleared in less than two seconds, the system is restarted.
  1. Read analog and digital sensors
  • Acquire data that describe the environment using the hardware components.
  1. Display data from the sensors
  • The acquired data from the sensors are displayed.
  1. Adjust the humidity
  • If the humidity value is over 75%, both the intake and the exhaust fans are activated. The greenhouse is ventilated until the humidity drops below 70%.
  1. Adjust the soil moisture
  • Every eight hours, data is read using the soil moisture sensor. If the moisture is under 70%, the water pump will be activated for five seconds, which is enough to rehydrate the soil.
  1. Reservoir water level indicator
  • If the water level sensor reads a value which is lower than 10%, then a message will display on the OLED C click board until the reservoir will be filled above 70%.
  1. Sleep mode
  • The system enters Sleep mode to reduce power consumption. The timer generates an interrupt every second, so the system will wake up and run the loop again.

The humidity, soil moisture and water level values are specific to this application according to the plant and the water reservoir dimensions. These values are configurable and can be changed in the main.c source file by modifying some macro definitions values.

To evaluate this application:

  1. Connect the board to the PC.

  2. Open the pic16f18446-cnano-greenhouse.X project in MPLAB® X IDE.

  3. Set pic16f18446-cnano-greenhouse.X project as main project. Right click on the project in the Projects tab and click Set as Main Project:

  4. Select the PIC16F18446 Curiosity Nano in the Hardware Tool section of the project settings:

  • Right click on the project and click Properties;
  • Select the PIC16F18446 Curiosity Nano (click on the SN) in the Hardware Tool tab and then click OK:
  1. Program the project to the board: right click on the project and click Make and Program Device:

Demo

Summary

The presented prototype has the purpose to prove the functionality of such a system. The implementation can befurther scaled to develop a larger monitoring system, to automate the control of a real size greenhouse. Significant applications that can start from this prototype belong to the agriculture domain.