Skip to content

8085 Program for an Automatic Lawn Irrigation System

Design an 8085 assembly program that simulates a basic automatic lawn irrigation system. The program should:

  • Turn ON irrigation only when:

    • Manual override is not active
    • Soil is dry
    • It’s not raining
    • It’s not daytime

If manual override is ON, irrigation must always turn on, regardless of other conditions.


Port (Hex)PurposeInput Value Meaning
00HSoil Moisture Sensor1 = Moist, 0 = Dry
01HRain Sensor1 = Raining, 0 = Dry
02HTime of Day1 = Daytime, 0 = Night
03HManual Override1 = Force ON, 0 = Auto Mode
10HOutput to Valve1 = Irrigation ON, 0 = OFF

START:
; Step 1: Check Manual Override
IN 03H
CPI 01H
JZ MANUAL_ON
; Step 2: Check Soil Moisture
IN 00H
CPI 01H
JZ IRRIGATION_OFF
; Step 3: Check Rain Sensor
IN 01H
CPI 01H
JZ IRRIGATION_OFF
; Step 4: Check Time of Day
IN 02H
CPI 01H
JZ IRRIGATION_OFF
; All conditions passed → Irrigation ON
MVI A, 01H
OUT 10H
JMP WAIT_AND_RESTART
MANUAL_ON:
MVI A, 01H
OUT 10H
JMP WAIT_AND_RESTART
IRRIGATION_OFF:
MVI A, 00H
OUT 10H
JMP WAIT_AND_RESTART
WAIT_AND_RESTART:
MVI C, FFH ; Simple delay
WAIT: DCR C
JNZ WAIT
JMP START

🧱 Step 1: Control the Irrigation Valve with a Simple Output

Section titled “🧱 Step 1: Control the Irrigation Valve with a Simple Output”

Before building decision logic, we first need to define how to turn irrigation ON or OFF from the 8085.

This step introduces the output port connected to the irrigation valve.


PortPurposeAccepted Values
10HIrrigation Control Valve0 = OFF, 1 = ON

We’ll directly send a value to this port to simulate the valve being turned ON or OFF.


  • It gives us a simple, verifiable action to test
  • It introduces the concept of output control using the OUT instruction
  • It lays the groundwork for plugging in more complex logic later

MVI A, 01H ; Load A with 1 to simulate "turn ON"
OUT 10H ; Send A to port 10H
HLT ; Stop execution

Try changing MVI A, 01H to MVI A, 00H to simulate turning OFF the irrigation.

Expected:

  • Port 10H reflects the ON/OFF signal
  • Easy to test using I/O monitor in Sim8085

Now that we can control the valve through an output port, let’s add manual override as an input condition.

When the override switch is ON (1), irrigation should always turn ON regardless of other sensor inputs.


PortPurposeValue 0Value 1
03HManual OverrideAutomatic modeForce irrigation ON
10HValve Control (OUT)OFFON

  • We read the override input from port 03H using IN
  • If the value is 01H, we skip all sensor checks and go straight to turning irrigation ON

This models user-first logic: a manual switch overrides all automation.


IN 03H ; Read from port 03H (Manual Override)
CPI 01H ; Compare with 1 (Override ON)
JZ MANUAL_ON ; If equal, jump to force ON
HLT ; Temporary end
MANUAL_ON:
MVI A, 01H ; Force irrigation ON
OUT 10H ; Send ON signal to valve
HLT

Try:

03H = 00H → Should not jump (automation continues)
03H = 01H → Should jump to MANUAL_ON and turn irrigation ON

If the manual override is OFF, we now begin evaluating environmental conditions — starting with the soil moisture sensor.

If the soil is already moist, irrigation is not needed.


PortPurposeValue 0Value 1
00HSoil Moisture InputDry (needs water)Moist (skip watering)

  • Read input from port 00H (soil moisture)
  • If it’s moist (01H), jump to IRRIGATION_OFF
  • If dry (00H), continue to the next condition (rain sensor)

IN 00H ; Read soil moisture from port 00H
CPI 01H ; Is soil moist?
JZ IRRIGATION_OFF ; Yes → skip irrigation

Try setting:

00H = 01H → moist → jumps to IRRIGATION_OFF
00H = 00H → dry → continues to next condition

If the soil is dry and manual override is not active, the next check is the rain sensor.

If it’s currently raining, irrigation should be turned OFF — watering during rain is wasteful.


PortPurposeValue 0Value 1
01HRain SensorNo rain (continue)Raining (skip watering)

  • Read input from port 01H
  • If rain is detected (01H), jump to IRRIGATION_OFF
  • If not raining (00H), proceed to the final check — time of day

This prevents unnecessary watering during active rainfall.


IN 01H ; Read rain sensor input from port 01H
CPI 01H ; Is it raining?
JZ IRRIGATION_OFF ; Yes → turn irrigation OFF

Try setting:

01H = 01H → raining → jump to IRRIGATION_OFF
01H = 00H → dry → continue to time-of-day check

🧱 Step 5: Check Time of Day Before Irrigation

Section titled “🧱 Step 5: Check Time of Day Before Irrigation”

If the soil is dry, it’s not raining, and manual override is off — the last condition to check is the time of day.

We assume that irrigation should only happen at night (for example, to reduce evaporation).


PortPurposeValue 0Value 1
02HTime of DayNight (continue)Daytime (skip)

  • Read port 02H to get time info
  • If it’s daytime (01H), skip irrigation
  • If it’s night (00H), proceed to turn it ON

This simulates energy-efficient watering schedules.


IN 02H ; Read time-of-day input
CPI 01H ; Is it daytime?
JZ IRRIGATION_OFF ; Yes → skip irrigation

If we pass all conditions:

; All checks passed → turn irrigation ON
MVI A, 01H
OUT 10H
HLT

Try these combinations of input:

OVRSMRAINTIMEExpected Output
1XXXON (override)
01XXOFF (moist soil)
001XOFF (raining)
0001OFF (daytime)
0000ON (all clear)

🧱 Step 6: Run Continuously in a Monitoring Loop

Section titled “🧱 Step 6: Run Continuously in a Monitoring Loop”

So far, our program halts after making a single decision. In a real-world irrigation controller, we want it to run forever and re-evaluate conditions regularly.


  • A single check isn’t enough — environment changes with time
  • Sensors may update inputs (e.g., rain starts after initial dry condition)
  • Automation means ongoing evaluation, not one-time logic

We add a loop at the end of the program to jump back to the start after each evaluation. To avoid tight-loop issues, we also add a delay to prevent too frequent checks.


WAIT_AND_RESTART:
MVI C, FFH ; Software delay (adjust as needed)
WAIT: DCR C
JNZ WAIT
JMP START ; Begin sensor checks again

Update all HLT instructions to:

JMP WAIT_AND_RESTART

This makes the program a live system — it continuously watches and reacts.


  • On power-up, the irrigation logic starts running
  • After each ON/OFF decision, the system waits a little and starts over
  • You can simulate changing conditions in Sim8085 by updating I/O ports mid-run

This 8085 assembly program simulates a smart irrigation controller using real-world inputs like moisture, rain, and time. The logic includes:

  • 🧠 Manual override that takes priority over automation
  • 💧 Soil and rain checks to avoid overwatering
  • ☀️ Daytime skipping to conserve water
  • 🔁 Continuous monitoring loop for real-time behavior
  • IN and OUT are essential for hardware interaction
  • Multi-condition decision-making can be modeled step-by-step
  • Infinite loops with delays create realistic control systems

This is a great example of using 8085 assembly for practical automation.