Skip to content

frankogenrwoth/irrigation-system-atmega328

Repository files navigation

Irrigation System (ATmega328P)

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.

Table of contents

Features

  • 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

Hardware

  • 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).

Pin mapping / wiring

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
  • DS18B20 (1-Wire)

    • DQ: PC0 (single-wire data line; software handles drive/read)
  • HC-SR04 (sonar)

    • TRIG: PD2
    • ECHO: PD3
  • Keypad (1x4)

    • KEY 1: PB2
    • KEY 2: PB3
    • KEY 3: PB4
    • KEY 4: PB5

Notes:

  • GPIO port/DDR usage and helper macros are in main.c (LCD_1602A_*, DS18B20_*, HCSR04_*, KEYPAD_*).

Files in this repository

  • 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.

Build (Atmel Studio / AVR-GCC)

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.

Flash examples (avrdude)

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:i

Arduino-as-ISP / bootloader example (set COM port and baud accordingly):

avrdude -c arduino -p m328p -P COM3 -b 115200 -U flash:w:workable.hex:i

Adjust -c (programmer), -P (port) and -b (baud) to match your hardware.

Usage / UI navigation

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).

Proteus image

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):

![Proteus schematic and PCB view showing the ATmega328P based irrigation system electronics; schematic window shows the microcontroller, ultrasonic sensor HC-SR04, DS18B20 temperature sensor, 16x2 LCD and a 1x4 keypad with interconnecting nets and pin labels; PCB layout shows component footprints, copper traces and board outline. Visible text labels include ATmega328P, LCD 1602A, HC-SR04, DS18B20 and example pin names PB0 PB1 PB2 PB3 PB4 PB5 PD2 PD3 PD4 PD5 PD6 PD7 PC0. Environment is an electronic design IDE with grid background, toolbars and rulers. Tone is technical and informational](/assets/proteus_setup.png)

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.

Contributing

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 LICENSE file (MIT or similar) if you want to grant reuse rights.
  • Add a README screenshot of the Proteus schematic (once hosted).
  • Add unit/integration tests for math/helper functions (offline tools) or simulation scripts.

License

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

About

c program for an irrigation system with lcd, sonar detector, temperature sensor and arduino uno with atmega 328p

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors