Gang Xie
Description
Do you often forget to irrigate your plants? Do you have to ask your neighbors to take care of them when your whole families are out for a vacation? Don’t worry any more! Here is a solution. This embedded system, worry-free automatic timed plant feeder, can do all the services for you. It can: regularly feed water to your plants for a specified amount of water; and also be used as an alarm clock.
You can set your desired feed pattern, and change all options at any time. It is easy, low-cost, and safe. It makes your worry free while you still enjoy your plants.
Introduction
The following diagram shows the system schematic.
It contains the several major blocks:
- ATmega 323 is the CPU of the system.
- 5 VDC power supplier: an adaptor first transforms 110 VAC 60 Hz into 9 VDC; then a regulator keeps VCC stable at 5 VDC.
- A crystal of 32KHz is used to provide a real-time clock.
- A crystal of 8MHz is for the CPU frequency.
- A block of circuit is built for programming so that the executable code can be downloaded from a computer to the system via a serial RS-232 port.
- A LCD is used to display the time and system states.
- A speaker is used for alarming and making sounds.
- Push buttons allow a user to change the system states.
- A relay is used to control the AC of the water pump with a DC signal from the processor.
- A block of circuit is used to protect the processor since a high voltage introduced from the relay can damage the processor.
Some key blocks will be explained in detail later on.
Electronics
The AVR processor used in this project is an ATmega323. It has two 8-bit Timer/Counters and one 16-bit Timer/Counter. Meanwhile, it supports the real-time counter. These features satisfy the system's demands. More detailed information can be founded in data sheets at Atmel. The following picture shows the pin configurations of the ATmega323.
The programming control circuit is shown in AVR basic system schematic. With this circuit, the code can be easily read and written by software PonyProg.
The regulator circuit uses an LM7805. A heat sink helps it cool down. This block of circuits is also shown in AVR basic system schematic.
The system has lots of functions heavily depending on a real-time clock. Thus, a 32768 Hz crystal works here. With a prescale of 128 and Timer2's overflow interrupt service, the crystal finally offers a 32768/128/(2^8) = 1 Hz frequency. Circuits for both the RTC crystal and the 8MHz crystal are shown in AVR basic system schematic.
A 2*24 HD44780 LCD is used as a display.
A 0.2W speaker makes sound.
The following diagram shows how push buttons work. When the button is pressed, the output signal is connected to GND. When it is released, the output is connected to VCC. Thus, it simulates push buttons in AVR STK500 kit. Push buttons are nominally open.
A R40-11D2-5 relay plays an important role in this project, since it is the relay that changes a control signal from the AVR into turning on or off the water pump. Its contact arrangement is shown as following.
In the system schematic as shown previously, there is an additional circuit for the relay to protect the AVR’s pins from being damaged. As we know, U=LdI/dt. There could be as large as 100 volts introduced from coils in the relay when the current flow in the coils are suddenly stopped or allowed. This high voltage can easily break through the AVR ports. In order to protect the AVR, the following circuit is used to limit the voltage applied on the AVR pins.
With this circuit, about 5 volts will be applied if the input control signal at B is high, which is large enough to trigger the relay.
The water pump (CAL P60) is in serial with a fuse for safety.
The speak makes sound of a certain tone when it is fed with a rectangular wave of a certain frequency in the project.
User Interface
The system provides a variety of UI functions. It has a pump, a LCD, a speaker and five push buttons.
The pump irrigates plants, which is our goal. Constrained by the water pump, the system uses a semi-volume control method by pumping for a specified amount of time. Water flow can be manually off-line adjusted by rotating a plastic valve in the pump. So please do some check and make sure that the pump supplies a desired amount of water in the specified time duration, before you leave the system to work.
The speaker will make sound when alarming or pumping. It actually gives a segment of music at the following frequencies in circular order:
f [Hz] | Note |
---|---|
880 | A5 |
987 | B5 |
1046 | C6 |
1174 | D6 |
1318 | E6 |
1397 | F6 |
1568 | G6 |
1760 | A6 |
Timer1 compare interrupt is used to generate these frequencies.
The LCD tells us the system status. It implements features such as displaying normal characters, blinking the cursor, shifting strings, and displaying a progress bar. A total of 6 pages can be shown in the LCD.
- First page is the one shown in normal mode. It shows the real-time date and time information in the first line. Different strings are shown in sequence in the second line.
- Second page is to show whether the clock alarm is set off or on at your specified time.
- Third page is to show whether the pump system is active or not, and whether sound is on or off during pumping.
- Page 4 shows the pumping duration, i.e., how many minutes and seconds of water will be pumped. Its range is from 1 second up to nearly 100 minutes.
- Page 5 shows the pumping frequency, i.e., how often you want to pump. Its range is from 1 second (not recommended) up to nearly 100 days.
- Page 6 shows the next pumping time.
Page 4, 5, and 6 together specify the pattern of pumping water.
A user can click five push buttons to communicate with the system. Timer0 is used to filter out electrical and mechanical noises. One of five buttons is used to reset the system. The other four, from left to right, are:
- Button Next: turn to next page if in non-editing mode, or swithches the blinking cursor the next changeable field if in editing mode.
- Button Edit: switches between non-editing and editing modes.
- Button +: increases the value of the current blinking field when in the editing mode.
- Button -: decrease the value of the current blinking field when in the editing mode.
Because of safety, conventions, and other issues, the system will stop alarming and/or stop pumping when any one of the buttons is clicked.
Software
The project is written in C, and compiled by AVRGCC. Meanwhile, it is heavily based on AVRlib function libraries, courtesy of the instructor Prof. Pascal Stang. About 45 % of code deals with real-time clock and time-related stuffs. It considers practical issues, such as 29 days, instead of 28 days, in February every four years. It need calculate and update the next pump time when necessary, since the next pump time is always larger than the current RTC time. About another 45 percent of code deals with the LCD.
Please click the following files to view the source code:
- ee281proj.c, global.h, avrlibdefs.h, and avrlibtypes.h: main() function and functions for push-button clicks and sound.
- lcd.c and lcd.h: general LCD functions, and display functions particular for this project.
- timer.c and timer.h: the TRC and all timing issues in alarming and pumping.