A compact embedded irrigation system for an ATmega328P microcontroller. The firmware reads a distance sensor (HC-SR04) to estimate tank capacity, a DS18B20 temperature sensor for soil temperature, drives a 16x2 LCD (1602A) for the user interface, and provides a simple 1x4 keypad UI to view and tweak configuration and trigger thresholds.
Note: A Proteus schematic / board image will be added here when hosted. See the "Proteus image" section for how to include or link your image.
- Features
- Hardware
- Pin mapping / wiring
- Files in this repository
- Build (Atmel Studio / AVR-GCC)
- Flash examples (avrdude)
- Usage / UI navigation
- Proteus image
- Contributing
- License
- Tank capacity estimation using HC-SR04 ultrasonic sensor and cylinder volume math
- Refill and leakage rate estimation
- Soil temperature via DS18B20 (1-wire)
- 16x2 LCD user interface (4-bit mode)
- 1x4 keypad for menu navigation and configuration
- Configurable triggers and alerts via the UI
- Microcontroller: ATmega328P (16 MHz)
- Display: LCD 1602A (4-bit)
- Distance sensor: HC-SR04 (Ultrasonic)
- Temperature sensor: DS18B20 (1-Wire)
- Keypad: 1x4 matrix (4 momentary buttons)
Suggested power: 5 V regulated for sensors and LCD. Make sure DS18B20 has the correct pull-up (or use parasite mode with care).
The pin defines are taken from main.c. Match these to your board or Proteus schematic.
-
LCD 1602A
- RS:
PB1 - EN:
PB0 - D4:
PD4 - D5:
PD5 - D6:
PD6 - D7:
PD7
- RS:
-
DS18B20 (1-Wire)
- DQ:
PC0(single-wire data line; software handles drive/read)
- DQ:
-
HC-SR04 (sonar)
- TRIG:
PD2 - ECHO:
PD3
- TRIG:
-
Keypad (1x4)
- KEY 1:
PB2 - KEY 2:
PB3 - KEY 3:
PB4 - KEY 4:
PB5
- KEY 1:
Notes:
- GPIO port/DDR usage and helper macros are in
main.c(LCD_1602A_*,DS18B20_*,HCSR04_*,KEYPAD_*).
main.c— main firmware. Contains LCD driver, DS18B20 driver, HC-SR04 logic, UI and app logic.deprecated.c— older/unused code (review before using).workable.cproj,workable.componentinfo.xml— Atmel Studio project files.Debug/Makefile— auto-generated Makefile from Atmel Studio (uses Atmel GCC toolchain paths).Debug/workable.hex(generated by build) — Intel HEX program image for flashing.
Open main.c to see implementation details and the menu/trigger/config buffers.
Recommended: Open the workable.cproj in Atmel Studio and build from the IDE. The project was generated by Atmel Studio and the Debug/Makefile references the Atmel toolchain paths.
Command-line (if you have avr-gcc toolchain in PATH and GNU make):
PowerShell example (adjust paths and toolchain if needed):
# from repository folder
cd 'e:/int uni/PROTEUS/workable/workable'
# build using the Debug Makefile if you have make installed
make -f Debug/Makefile all
# Resulting outputs will include workable.elf, workable.hex and workable.eep in the same directory.If you don't have make available on Windows, use Atmel Studio to build or install GNU make (mingw/msys) and ensure avr-gcc/avr-objcopy paths match your toolchain.
After building you should have workable.hex (or workable.elf/workable.srec) in the project folder. Example avrdude commands:
USBasp programmer example:
avrdude -c usbasp -p m328p -U flash:w:workable.hex:iArduino-as-ISP / bootloader example (set COM port and baud accordingly):
avrdude -c arduino -p m328p -P COM3 -b 115200 -U flash:w:workable.hex:iAdjust -c (programmer), -P (port) and -b (baud) to match your hardware.
The firmware exposes a simple menu through the 16x2 LCD and a 1x4 keypad. Key mapping (as used in ui_process_key_command):
- Key 1 (PB2): Back / Exit — when inside a menu, returns to previous level
- Key 2 (PB3): Down / Decrease — navigates down in menus or reduces a parameter
- Key 3 (PB4): Up / Increase — navigates up in menus or increases a parameter
- Key 4 (PB5): Select / Enter — enter a menu or toggle/select an option
Top-level menu entries (from main.c):
- Tank capacity
- Refilling rate
- Leakage rate
- Soil temperature
- Triggers
- Messages
- Config
The display updates automatically; some menu items perform sensor reads and take a short time (e.g., DS18B20 conversion). The HC-SR04 measurement is used to compute tank volume assuming a cylindrical tank — see the constants in main.c (tank height, radius, PI).
When you host the Proteus schematic or an exported image, place it in assets/ and update the README image path. Example Markdown to embed a local file (recommended path):
I included a placeholder path assets/proteus_setup.png. Create an assets/ folder and add your image there, or replace the path with the hosted image URL.
If you want to improve the project:
- Please open issues for bugs or feature requests.
- Fork the repo and make changes in a feature branch.
- Keep changes small and focused. Document any hardware changes or pin remaps.
Small, low-risk improvements that would be useful:
- Add a
LICENSEfile (MIT or similar) if you want to grant reuse rights. - Add a
READMEscreenshot of the Proteus schematic (once hosted). - Add unit/integration tests for math/helper functions (offline tools) or simulation scripts.
This project currently has no license file. If you want to make this open-source, add a LICENSE (for example, MIT) to the repository. If you want, I can add an MIT license file for you.
made with ❤️ by frank ogenrwoth