Close

Firmware - pseudo Code

A project log for Automatic Self Cleaning Filter (Liquid)

Low Cost & Automated,using Atmega328P (Arduino) as it's brain. Controls Solenoid valve and DC Motor, by monitoring pressure inside.

amar-potdarAmar Potdar 02/03/2016 at 09:330 Comments

As stated earlier in Details, System will operate in Two Modes, Idle Mode and Clean Mode.

This system is a better example of Real-time parameter monitoring and control.

In Real-time monitoring, Continuously monitoring the sensor value, and comparing it with the specified value. Depending upon the current sensor value, System goes either into Idle or Clean Mode. Also, Manual button is provided to manually clean the system, On pressing the button system goes into Clean Mode.

In control, We are switching ON/OFF Solenoid Valves, DC Motor and couple of LEDs.

Pressure Indicator LEDs:

For Controlling, Operating modes and pressure indicator LEDs, I have decided to take state-machine based approach.

There are total 5 LEDs( 3mm - GREEN, YELLOW, RED) are used

GREEN = Low Pressure.

YELLOW = Medium Pressure.

RED = High Pressure.

pseudo code:

//----------Variable deceleration----------

Valves = INLET,OUTLET,DIRT;

Motor = DC_MOTR;

button = man_clean;

LEDs = LD1,LD2,LD3,LD4,LD5;

Sensor = LDR_val;

States = curr_state;

//----------Initialization----------

INIT Valves (As OUTPUT).

INIT DC_MOTR (As OUTPUT).

INIT LEDs (As OUTPUT).

INIT button (As INPUT).

INIT Sensor(As INPUT).

//----------Main Function-------- Run Forever---------

WHILE(1)

READ LDR_val;

IF man_clean == pressed

curr_state = press_state_5;

ELSE

IF LDR_val < 1000 and LDR_val > 800

curr_state = press_state_1;

ELSEIF LDR_val < 800 and LDR_val > 600

curr_state = press_state_2;

ELSEIF LDR_val < 600 and LDR_val > 400

curr_state = press_state_3;

ELSEIF LDR_val < 400 and LDR_val > 200

curr_state = press_state_4;

ELSE IF LDR_val < 200

curr_state = press_state_5;

ENDIF

CASE curr_state OF

press_state_1: HIGH = LD1; LOW = LD2,LD3,LD4,LD5; CALL idle_mode();

press_state_2: HIGH = LD1,LD2; LOW = LD3,LD4,LD5; CALL idle_mode();

press_state_3: HIGH = LD1,LD2,LD3; LOW = LD4,LD5; CALL idle_mode();

press_state_4: HIGH = LD1,LD2,LD3,LD4; LOW = LD5; CALL idle_mode();

press_state_5: HIGH = LD1,LD2,LD3,LD4,LD5; CALL clean_mode();

END CASE;

//----------Utility Function-----------

FUNCTION idle_mode()

Turn ON INLET;

Turn ON OUTLET;

Turn OFF DIRT;

Turn OFF DC_MOTR;

ENDFUNCTION;


FUNCTION clean_mode()

REPEAT

Turn ON INLET;

Turn OFF OUTLET;

Turn ON DIRT;

Turn ON DC_MOTR;

UNTIL TIMER != 30Secs.

ENDFUNCTION;

ENDWHILE


Discussions