F15: Plant Control

From Embedded Systems Learning Academy
Jump to: navigation, search

Automated Plant Control System

CMPE146 F15 PlantControl system.png


The Plant Control project introduces a plant incubator which allows for resource and energy efficiency while producing healthy flowering and vegetation. The incubator will utilize an SJOne development board, its on-board sensors (light/temperature), a moisture sensor, and LEDs in order to autonomously provide the optimal moisture level for growth in any lighting. The owner of the plant control system can be confident that his or her plant is growing in perfect conditions and will be notified otherwise via an LCD screen.

Objectives & Introduction

This project is a self watering, self lighting, and temperature alerting plant grower.
The entire system is controlled via an SJOne Board which utilizes an LPC1758 Microprocessor.

In addition to the onboard sensors, the project will require interfacing to:

  • RGB LCD Screen
  • Moisture Sensor
  • Water Pump
  • PWM controlled LED

Team Members & Responsibilities

  • Moises Negrete
    • LED and Water Pump Driver Circuit Design
    • Temperature, Light Sensor, PWM software
    • Design and Build Planter
  • Eduardo Lemus
    • LCD Interface
    • Software Design and Implementation
    • Source Code Task and Timing Cleanup
  • David Chiu
    • Moisture Sensor Interface
    • Power Regulator Circuit
    • Design and Build Planter


Week# Date Task Actual
1 10/24 Research best lighting, temperature, moisture conditions Completed
2 10/30 Purchase necessary equipment, and begin testing equipment (sensors) Completed
3 11/06 Interface Sensors Completed
4 11/13 Interface LEDs and Water Pump Completed
5 11/20 Begin Building Planter Completed
6 11/27 Finish Building Planter & Begin RT Code Completed
7 12/2 Functionality Testing and Prototype Verification Completed
8 12/9 Plant Flower and Field Test Completed

Parts List & Cost

Part Name Cost
Fafada Water Pump $6.99 http://www.amazon.com/gp/product/B00MP4Q6K2?psc=1&redirect=true&ref_=ox_sc_act_title_1&smid=AAOUP5IQ82N49
Arrela Soil Hygrometer $6.11 http://www.amazon.com/gp/product/B00KKQYW76?psc=1&redirect=true&ref_=ox_sc_act_title_1&smid=AIOZ1JWV33B58
1/2 gallon Water Reservoir $7.00 Auto Zone
Faux-Ceramic Planting Pot $5.00 Home Depot
Baby Mums (Flowers) $2.00 Trader Joes
SJone Board $80.00 SJSU
Soil $10.00 Home Depot
12V Power Adapter $6.00 Anchor Electronics
Grove RGB LCD Screen $13.90 http://www.seeedstudio.com/depot/grove-lcd-rgb-backlight-p-1643.html
Fairchild Semiconductor LM7805 Voltage Regulator $0.50 Anchor Electronics
Total $136.6

Design & Implementation

Hardware Design

The hardware design for this projects will be split into the different sections of our project. The different hardware components include a power circuit and water pump/LED drivers. The
Hardware design will then be followed by the design of the Plant Pot and finally the Hardware interfacing components.

Power Circuit
Due to the low power outputs of the LPC1758. in order to drive the LED and the the water pump,
an external power source strong enough to do so is necessary.

                  CMPE146 F15 PlantControl PowerCircuit.png
Figure 1. Power Regulator Circuit (12V-5V)

In figure 1, the power circuit uses 2 capacitors (100uF and 220 uF) to maintain stability of the regulator. The LM7805 is used to convert 12V to 5V as needed to power the LCD screen, drive the LED, and the motor. A switch was added at the 5V node in order to be able to switch on and off the 5V.

Water Pump/LED Driver

                    CMPE146 F15 PlantControl PWM.png
FIgure 2. PWM Mosfet Driver for water pump

The figure above (Figure 2) displays the circuit design used in our plant control system for driving the water pump via PWM. The PWM input from the LPC1758 enters the gate of the 2n7000 mosfet which allows the Source-to-Drain circuit completion. When the Source-to-Drain circuit is complete, the current will flow though the water pump and thus pump water into the dry soil when needed. The LED in the circuit is used to polarize the current so that it only flows in one direction disallowing the pump to receive current in a reverse direction. The circuit for driving the plant lighting LED is similar to the water pump driving circuit other than that the leads to the water pump are connected to a 5V LED. The plant lighting LED is connected in parallel to the forward current directing diode. A 10K Resistor connected from the Gate to the Drain in order to ensure gate is grounded if drive is ever disconnected.

Plant Casing
The Plant casing was designed to look like a classic ceramic/adobe plant pot. A water reservoir was connected to the back of the plant pot and the water pump was placed inside of the water reservoir. A hose was connected to the water pump and connected to go around the plant pot to drip water around the pot whenever a signal is received from the soil moisture sensor. An LED was mounted to the top of the plant pot in order to provide light whenever the light is in a dark environment. A figure showing the mounting is shown below.

                    CMPE146 F15 PlantControl case.png
Figure 3.1 Plant Control Casing (Mounted LED and Water Reservoir)

                    CMPE146 F14 PlantControl Base.png
Figure 3.2 2D model of Plant Control Casing (Mounted LED and Water Reservoir)

Hardware Interface

For the hardware implementation we used the I2C and the PWM communications as well as GPIO. The I2C bus was used in order to communicate from the board to the LCD screen, which is used to display the temperature of the room that the plant is in. PWM was used to control the water pump and the lighting LED. GPIO pins were used to interface sensors that required AtoD conversion as well as for the switches on the board which are used for testing.

                CMPE146 F15 PlantControl LCD.png
Figure 4. LCD interface

The LCD screen is interfaced to the SDA and SCL lines of the LPC1758 to act as a slave under I2C communication.

                CMPE146 F15 PlantControl SoilSensor.png
Figure 5. Soil Moisture Sensor Interface

The soil moisture sensor was connected to the ADC pin of the LPC1758 in order to convert the analog signal of the sensor into a digital signal that the LPC1758 can process.
The interface for the PWM can be seen in the Hardware Design sections where the Driver Circuit is explained. In that scenario, the PWM output is connected to the gate of a mosfet that is used as a switch to control how fast the water pump pumps water and how dim or bright the lighting LED shines.

As for the other sensors used, they are part of the SJOne Board and also use I2C communication similar to the LCD and therefore are connected to the SDA and SCL in the same manner.

                CMPE146 F15 PlantControl BlockSys.png
                    Figure 6. System Block Diagram

Figure 6 shows the system block diagram and how the SJOne was interfaced to the rest of the components.

Software Design

Below are flow charts for the software algorithm combining the tasks that are performing the reading and the tasks that are enabling/disabling the IO devices. In order to share the values of the readings we are utilizing queues to pass values from one task to another.

                    CMPE146 F15 PlantControl Software1.png
Figure 7. Water Pump Flow Chart

In the figure above, we have two tasks that control the water pump. The first task (MoistureSensorTask) reads the sensors and the second task (WaterPumpTask) determines whether to turn on the water pump or not. Depending on the Moisture levels the water will be pumped at different rates using PWM and for different amounts of time. Each Moisture level check is timed for 30 minute intervals because we know that the rate of change in moisture levels in the soil will not change drastically over short periods of time. This allows the CPU to utilize it's resources to perform other tasks. It is important to point out that the Moisture sensors were placed in the middle of the pot,(right next to the root of the plant) this allowed for an accurate reading of moisture levels.

WaterPump Pseudo Code:

  • Get information from MoistureSensorTask;
  • Check timer.
  • Reset timer.
  • Analyze information(Check if the moisture level is ideal for the specific plant)
  • Pump the exact amount of water needed to the plant
  • Set timer for 30 min.
  • Exit Task
                    CMPE146 F15 PlantControl Software2.png
                                   Figure 8. LED Flow Chart 

In the figure above, we also have two tasks that control the LED. The first task (LightSensorTask) reads the sensors and the second task (LightPWMConsumerTask) determines whether to turn on the LED or not. In addition, the LightSensorTask controlled the intensity of the LED using on of the PWM of the micro-controller. For instance, if there is no light at all, the LED will turn on at a 100% intensity, however if the light is not sufficient, the LED will turn on at the intensity needed. The LightSensor Task runs at a high frequency(with a small TaskDelay),by doing this it was possible to check the lighting of the plant while giving other tasks sufficient time to perform. We will be monitoring the amount of light more frequently because a constant healthy level of lighting is necessary in order to maximize plant growth.

LED Pseudo Code:

  • Get information from LightSensorTask;
  • Analyze information(Check if the amount of light is ideal for the specific plant)
  • Turn on LED at the exact intensity needed for the plant
  • Exit Task
                     CMPE146 F15 PlantControl Temperature.png
                                   Figure 9. Temperature Display Flow Chart 

In the figure above, we also have two tasks that control the LCD display. The first task (TemperatureSensorTask) reads the temperature sensors and the second task (LCDDisplayTask) determines whether to display a warning message. We will be monitoring the temperature constantly because the temperature is an important factor in plant growth. Currently we are using an external LCD screen to display a warning message whenever the temperature exceeds the recommended temperature for growing a certain type of plant. In the future, we can also set it up to control a fan or AC system when the temperature is too high or too low.

LCD Pseudo Code:

  • Get information from TemperatureTask;
  • Analyze information(Check if the temperature is ideal for the specific plant)
  • Initialize LCD screen;
  • Display Temperature;
  • Change color of LCD depending on the temperature
  • Exit Task

Hence, for each of the the necessary readings needed,(such as temperature, moisture levels, etc) a task was created. The tasks gathered the necessary information and sent them to another task (through a queue) that processed the information. The task that receives the information ("consumer task") analyses the information received and executes the necessary steps to resolve a problem if there is one. In addition the use of queues instead of xsemaphores made it easier to create a context switch between task. In addition, to allow the various task to run a task time delay was added to each task.

All of the important task followed the following format:


    • Initialize device that collects data
    • Collect data
    • Sent Data to Task_ReceiveData
    • Exit


    • Receive data
    • Analyze data
    • Take necessary steps according to data collected
    • Exit


Light Sensor
The light sensor task takes a raw value reading from the light sensor and places it in the light queue for the LED task to process. The light sensor uses I2C to connect to the LPC1758 meaning that it is a slave and the CPU will address it whenever it is ready to read a value.

Tempreature Sensor
The temperature sensor also uses I2C and the values are read whenever the master CPU addresses it. The temperature sensor reads a binary number that is converted into a Farenheight value and sent to a queue for the processing by the RGB LCD.

Moisture Sensor
The moisture Sensor was read using an ADC pin. The Digital values from the conversion of the sensor's analog values were then read every half hour. The moisture sensor values were then sent to a queue to which the water pumping task will respond to. The moisture sensing task is set to read the moisture every few minutes and sleep if there is a value waiting in the queue every so often.

The LCD screen outputs temperature value and flashes "too hot" or "too cold". The screen also changes color from yellow to red (when it is too hot) and to blue (when it is too cold).
Water Pump (PWM)
Once a value was placed into the watering queue from the moisture sensor, The water pump task reads the value and determines whether the plant needs watering or not. Depending on the dryness condition of the soil, the task will pump water for 5 seconds at a different rate of flow from 0-100% its full 2.2 liters/minute.

LED (PWM) The LED task is similar to the water pump in that the light will dim and brighten from 0-100% of its maximum 5 watts. The amount of light produced by the LED is strictly dependent on the light sensing task.

Testing & Technical Challenges

Throughout the project we have come across many challenges that we were able to overcome because we started early. We made many mistakes in both the software and the hardware implementations of our design and it slowed our progress greatly. Some advice would be to pick a project quick and start early so that you if you fail you can have time in the end to make up for it.

Issue #1

One of the main issues that slowed our progress is that none of our group have ever worked with an LCD screen and we did not know how to initialize or print to the screen. We spent many days researching for solutions but everything online pointed to arduino libraries, which we are not allowed to use. For one of the attempts we tried to take a look into previous projects that utilized the LCD however that also did not make any sense to us because we had no idea what was going on inside the LCD screen. After trying for so long, we decided to give up and ask for help. If given the opportunity to work on another project I will definitely ask for help earlier in the process, getting stuck and not knowing what to do was a big waste of time and if you can draw knowledge from someone it helps speed up the learning process.

Issue #2

One of the problems we faced during our implementation is that the light control task in our project was not functioning correctly. The light would flash on and off at times. We found that this was due to a task delay in the task that produced the value for the intensity of the light necessary. Changing the time delay in that task allowed the light to function properly and it is worth noting that an easier approach would have been to perform all of the functions in one task.

Issue #3

Another mistake we made was that we were reading the wrong datasheet for one of our parts. We were looking into the datasheet of a similar transistor which had different operating conditions and we for the longest time we couldn't find out what the problem was. We didn't know this was the problem until we decided to try another transistor and it caused a spark. This was a sign to us that we are not operating at the ideal conditions and we destroyed the transistor. We took a closer look at the parts number and it was differrent than the one we thought it was.


At the end of this project, we were able to successfully implement various types of communication protocols (such as I2C, and SPI). In addition, the project added to our understanding of circuit design, and implementation. The use of MOSFETS, in combination with resistors resistors and diodes, made it easy to troubleshoot problems during the hardware design phase. Furthermore, the project helped us understand how to interface different devices to the SJSU one microcontroller. The data sheet of the devices that were connected to the microcontroller had to be read and understood in order to successfully. On the other hand, the project made us understand how to use a real operating system in a real application.The project gave us an understanding of how semahpores and queues work, and when is best to use one over the other.In the end the project was a successful learning experience. Anybody who is looking to make a similar project should consider doing multiple things in a single task in order to avoid some of the mistakes that we encountered. Another recommendation for somebody who wants to create a plant growing system is to consider a an ebb and flow system as oppose to a drip irrigation system; this would avoid the moisture sensor and water would be pumped regularly based on a timer if not constantly. A great understanding of the RTOS is necessary in order to have a fully synced project.

Project Source Code



We would like to thank both Preetpal Kang and Dr. Haluk Ozemek, for their limitless support and encouragement throughout the semester.
The knowledge and skills gained in CMPE146 were paramount to the completion of this project.

References Used

Soil Hygrometer
LCD RGB Backlight
2N7000 Transistor
Voltage Regulator