Difference between revisions of "S17: Smart Planter"

From Embedded Systems Learning Academy
Jump to: navigation, search
(7.DC Pump)
(8.Lamp)
Line 275: Line 275:
 
====DC Pump ====
 
====DC Pump ====
  
=== 8.Lamp ===
+
====Lamp ====
  
 
=== Software Design ===
 
=== Software Design ===

Revision as of 20:53, 25 May 2017

Smart Planter

Abstract

This project aims at developing an automatic irrigation and lighting system for plants. An Android app allows a user to remotely monitor and manually control the watering and lighting for the plant.

Objectives & Introduction

The SJOne board sends sensor readings to an Android app through a server. The Android app can also send commands to the SJOne board through the server (such as turning the water pump on or off).

An Android Things app runs on a Raspberry Pi 3 to provide Internet connectivity to the SJOne board and to get timestamps of when the plant was last watered (future enhancements can include more useful features with APIs from Google). The two boards communicate over UART.

Team Members & Responsibilities

  • Sona Bhasin
    • Temperature/Humidity sensor
    • Rain sensor
    • Code integration and testing
  • Johnny Nigh
    • Android app
    • Server application
    • Android Things app
    • Communication between the SJOne and Android Things app
  • Thrishna Palissery
    • Soil moisture sensor
    • Light sensor
    • LCD
    • Code Integration and testing
  • Hugo Quiroz

Schedule

Week # Start Date End Date Task Status Actual Completion Date
1 03/14/2017 03/21/2017
  • Finalize the components and interfacing protocols.
Completed 03/23/2017
2 03/24/2017 04/04/2017
  • Order Project Components.
Completed 04/06/2017
3 04/04/2017 04/14/2017
  • Prepare project schematic and design PCB.
  • Interface Raspberry Pi with SJ One for communicating with Android app.
Completed 04/15/2017
4 04/04/2017 04/11/2017
  • Finalize the wiki schedule.
Completed 04/10/2017
5 04/11/2017 04/28/2017
  • Interface temperature and humidity sensor with single bus protocol.
Completed 04/22/2017
6 04/11/2017 04/25/2017
  • Control and read actuators and sensors using GPIO.
Completed 04/25/2017
7 04/11/2017 04/28/2017
  • Interface LCD display to SJ-One using UART.
Completed 05/05/2017
8 04/18/2017 04/30/2017
  • Interface flow and rain sensor to SJ-One board.
Completed 04/30/2017
9 04/20/2017 05/05/2017
  • Interface soil moisture sensor to Sj-One board via its ADC.
Completed 04/28/2017
10 05/06/2017 05/10/2017
  • Integrate all components and test.
Completed 05/12/2017
11 05/10/2017 05/15/2017
  • Final testing and resolution of problems if any.
Completed 5/19/2017
12 05/11/2017 05/21/2017
  • Final wiki artifact and prepare for Demo.
Completed 5/25/2017

Parts List & Cost

Item # Description Distributor Qty Cost
1 SJOne Board 1 $80.00
2 Soil Moisture sensor Amazon 1 $5.99
3 Light sensor Amazon 1 $8.99
4 Rain sensor ebay 1 $1.99
5 Temperature and Humidity sensor Amazon 1 $7.99/4 pieces
6 DC water pump Amazon 1 $12.99
7 Flow meter Amazon 1 $10.99
8 Raspberry Pi 3 Amazon 1 $36.78
9 Voltage regulator (3.3V) Sparkfun Amazon 1 $1.95
10 Voltage regulator (5V) Amazon 1 $7.99/12 pieces
11 LCD display (20x4) Amazon 1 $32.10
12 Lamp 1
Total: $207.76

Design & Implementation

Hardware Design

Discuss your hardware design here. Show detailed schematics, and the interface here.


Hardware Interface

Rain Sensor

The rain sensor is used in the project to detect if it is raining. This helps the Smart Planter to decide if it needs to water the plants if the moisture level falls below desired value. The sensor requires 5 V power supply. The digital output of the pin is connected to P0.29 of SJOne board. When rain drops fall on the conductive plate connected to rain sensor, the conductive plate elements are bridged by the rain water and the digital pin output goes low. To read the rain sensor, we have implemented GPIO external interrupt to be triggered on detecting falling edge.


Figure 1: Hardware Interface of Rain sensor

Temperature/Humidity Sensor

The temperature/humidity sensor being used in the project is AOSONG DHT11 that uses single-wire protocol for communication. The sensor requires 5V power supply. The output signal of the sensor is connected to P2.7 of SJOne board and to 5V VCC with a pull-up resistor of 4.7kΩ. The sensor keeps track of the temperature and humidity for the Smart Planter system. The ideal temperature range for plants is between 50 °F and 80 °F while the humidity range is between 40% and 60%. If the temperature falls below 54°F, the user is intimated using the Android app. The pin diagram for interfacing the temperature/humidity sensor with SJOne board is shown below.

The sensor waits for the microcontroller to pull the line low for a period of 18 ms on its signal pin. The sensor then briefly pulls the line high as “wait time” and then sends an acknowledgment signal which comprises of 80 µs of low time and 80 µs of high time. Subsequently, the sensor sends 40 bits of humidity, temperature and checksum data respectively. The bits are differentiated as 0 or 1 based on the duration for which the signal remain high. The bit 0 is represented by a signal which goes low for 50 µs followed by high time of 28-30 µs while the bit 1 is represented by a signal which goes low for 50 µs and then high for 60-70 µs. The sensor needs 1 s between reads to provide correct data. The data provided by sensor is of the form: 8-bit integer humidity data + 8-bit decimal humidity data + 8-bit integer temperature data + 8-bit decimal temperature data + 8-bit checksum.

Figure 2: Hardware Interface of Temperature/Humidity sensor

Soil Moisture Sensor

This soil moisture sensor can read the amount of moisture present in the soil surrounding it. It uses the two probes to pass current through the soil, and then it reads that resistance to get the moisture level. More water makes the soil conduct electricity more easily (less resistance), while dry soil conducts electricity poorly (more resistance). It outputs an Analog signal. It is a simple, 5-volt dc collector, emitter follower output monitoring the soil resistance as a base drive of the emitter follower. The more moisture the lower the base resistance and the more base current. Therefore, the more moisture the greater the emitter follower output voltage 0 to approx. 3.3 volts max. This output pin is connected to P0.26 pin of SJ-One board. The pin is configured as an ADC pin. The analog output from the soil moisture sensor is converted to digital signal via ADC of SJ-One board. If the moisture content is below a threshold a DC pump is turned on which waters the plant.


Figure3: Hardware Interface of Soil Moisture Sensor
Light Sensor

The light sensor is used to detect the current ambient light. The light sensor which is used in this project uses a photo resistor. It changes its resistance based on the amount of light that falls upon it. The light sensor produces an analog output voltage in the range of 0-4v max. This analog output is connected to the pin P1.31 of SJ-One board which is configured as ADC. Since the SJ-One pins can tolerate only a max of 3.3v, the output from the light sensor is stepped down to 3.3 v using a voltage divider. The stepped down voltage is then given as the input to the ADC pin. The light sensor requires 5V supply voltage. If the amount of light falls below a threshold a lamp is turned on.

Figure 4: Hardware Interface of Light Sensor

5.LCD

The Liquid Crystal Display used for this project was NHD-0420D3Z-NSW-BBW-V3. This display uses a built-in PIC16F690 for serial communication. It can work in different modes (I2C, SPI, RS232/UART). RS232/UART was used for this project as communication. To enter the RS-232 mode, both R1 and R2 on LCD should be open. A 5v voltage supply is provided. The pin P0.0 of SJ-One board is used as the TX 3 (UART3) pin. This pin is connected to the RX pin of LCD display. The baud rate used for communication was 9600. The communication format is 1 Start bit, 8-bit data, 1 Stop bit, no parity, no hand-shaking.


Figure5: Hardware Interface of lcd

Flow Meter

DC Pump

Lamp

Software Design

Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it.

Soil Moisture Sensor

Soil moisture sensor works on ADC. The following tasks are used by the soil moisture sensor.

scheduler_add_task(new moisture_sensor_task(PRIORITY_LOW));
xTaskCreate(test_task, (const char* )"test", STACK_BYTES(2048), 0,PRIORITY_MEDIUM, 0);

The 'moisture_sensor_task' reads the analog value from pin P0.26 and converts it into a digital value. This value is passed to the 'test_task' using a queue. The 'test_task' compares the value obtained from the moisture sensor with a threshold and takes appropriate action.

 class moisture_sensor_task: public scheduler_task
 {
   uint16_t moisture_value = adc0_get_reading(moisture_sensor_channel);
   xQueueSend(moisture_sensor_handle, &moisture_value, 0);
 }
 void test_task(void* p)
 {
   //Receives value from queue
   if(moisture_value<threshold)
   {
       turn_on_pump();
   }
   else
   {
       turn_off_pump()
   }

 }

2. Light Sensor

Light sensor works on ADC. The following tasks were used for light sensor.

scheduler_add_task(new light_sensor_task(PRIORITY_LOW));
xTaskCreate(test_task, (const char* )"test", STACK_BYTES(2048), 0,
			PRIORITY_MEDIUM, 0);

The analog value from pin P1.31 is converted to digital value using the task 'light_sensor_task'. The value is send to 'test_task' for comparing it with a threshold. If the value is below particular threshold a lamp is turned on.

class light_sensor_task: public scheduler_task 
{
  uint16_t light_value = adc0_get_reading(light_sensor_channel5);
  xQueueSend(light_sensor_handle, &light_value, 0);
}

void test_task(void* p)
{
   //Receive item from a queue
   if(light_value<threshold)
   {
      turnOnLight()
   }
   else
   {
      turnOffLight()
   }
}


3. Rain sensor

Rain sensor uses GPIO external interrupt functionality to convey if it is raining to the SJOne board.

isRaining = false;
eint3_enable_port0(29, eint_falling_edge, rainsensor_isr);

The pin P0.29 is set as input and on external interrupt being triggered at falling edge, the callback function 'rainsensor_isr' will be called to set the flag isRaining as true. This flag is made use of by 'test_task'.

4.LCD

The following task was used for LCD. LCD is interfaced to SJ-One board using UART3. LCD displays soil moisture sensor value, temperature sensor value, humidity sensor value and Flow meter reading in Liters if here is no rain. When it rains, it displays 'Its Raining!'.

 
class display_LCD_task: public scheduler_task 
 { 
    init_UART3();
    if(!Raining)
    display_LCD(mois_perc, temp_val, humid_val, FlowMeterliters);
    else
    display("Raining!");
 }

5.Temperature

Implementation

This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.

1.Rain Sensor

Rain sensor value is read using the GPIO interrupt functionality.

To read the rain sensor output, the steps followed are:

  • The GPIO pin P0.29 is set as input pin.
  • The external interrupt at falling edge is enabled on P0.29.
  • On detecting a falling edge, a flag is set within the callback function for external interrupt on pin 0.29. This flag is checked by the master task in decision-making process for watering the plant.

2.Temperature/Humidity Sensor

To implement the single-wire protocol for temperature/humidity sensor, we have made use of a timer interrupt and GPIO external interrupt. The timer interrupt has been configured to be triggered every 30 µs and the GPIO external interrupt has been configured to be triggered when a rising edge is detected on the pin. We have also made use of semaphore and tasks to effectively achieve the purpose.

The sequence of steps to read the temperature/humidity sensor is as follows:

  • The GPIO pin P2.7 is set as an output pin.
  • The microcontroller sets the pin low for 18 ms.
  • The pin P2.7 is set as input pin.
  • The external interrupt at rising edge is enabled on P2.7.
  • The sensor then pulls the signal high briefly as wait time followed by an acknowledgment signal and 40 bits of data.
  • On detecting rising edge, the timer interrupt is enabled in the callback function for external interrupt on pin P2.7.
  • Within the timer interrupt ISR, if the signal is still high after the 30 µs, it in interpreted as bit 1 and if the signal falls low after 30 µs, then it is interpreted as bit 0. The values are stored in an array. Once all 40 bits of data has been received, a function to convert the values stored in array to decimal equivalent is called, which provides the humidity data in % and temperature data in °C, converted to °F.
Figure 6: Temperature/Humidity sensor Timing diagram

3.Soil Moisture Sensor

Testing & Technical Challenges

Temperature/Humidity Sensor reading

While trying to integrate the task for reading the temperature/humidity sensor along with other sensor tasks, it was seen that the system crashes. Also, since reading the temperature/humidity sensor is time-sensitive, the temperature and humidity values received were found to be erroneous after a few consecutive reads.

On debugging, it was found that the function that performed the conversion of binary values of temperature and humidity to decimal equivalents was taking too long which led to system crash. This issue was resolved by rewriting the binary-to-decimal conversion logic to use fewer for loops. Also, semaphore was made use of inside the interrupt handler for deferred processing and synchronization. This reduced the CPU utilization to a great extent.

The delay between consecutive reads performed on temperature/humidity sensor was adjusted in way to provide better synchronization in the event of multiple reads.

Conclusion

Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?

Project Video

Project Source Code

References

Acknowledgement

Johnny Nigh would like to thank Michael Nigh for his help with setting up the server and help with the basics on the Socket.IO JavaScript library.

References Used

Appendix

Future enhancements:

  • Automatically get the timezone based on the location of the board that is running the Android Things app (using the Google Maps Timezone API).
  • Add push notifications.
    • I.e. a soft watchdog in the SJOne application can tell the Android Things app to alert the user (if a possible failure has been detected).
  • Add support to turn watering and lighting on or off through voice commands (using the Google Assistant SDK).