SIMULINK Stateflows for Washing machine & Gear shifting logic.
SIMULINK WEEK 4 CHALLENGE
Aim:-
1) Implement control logic of a “washing machine” using Stateflow as per given sequence
2) Make a Simulink chart for the “Gear shift” logic as per given conditions.
Software used:-
Matlab R2022a
Task 1:-
- Implement control logic of a “washing machine” using Stateflow as per given sequence:
- If the power supply is available, the system gets activated
- If the Water supply is not available, stop the process & indicate through LED
- Soaking time should be 200s followed by Washing time of 100s.
- Then rinsing happens for next 20s & dryer runs for 50s
After all the processes have completed turn on the finished LED
Simulink model creation:-
Step 1:- Open the simulink model , and get the 'Chart' block.
Step 2:- Provide the Input states and output states for the chart. For our given conditions, the Power supply and Water supply will be takes as inputs & Water,soaking,washing,rinsing,drying & finish are taken as the output states.
It can be done by two ways. Either you can directly click the input and output state arrows, which will appear in the 'Chart' block itself. Or double click the chart block>Choose 'symbol pane' option and you can define the input ad output states.

Step 3:- After describing the input and output states, connect two constant as input values ie., 1 for ON & 0 for OFF. Then connect 6 displays to the output states defined.After giving these conditions, our chart will look as follows:-

Step 4:- Double click the Chart block icon, to create the Chart flow for the given washing mahine conditions.
To create the Flow chart:-
Step 1:- Seven state blocks are chosen to define the given conditions.
Step 2:- Give seperate block names for all the chosen block for different states. Here our states start from filling water, then soaking followed by rinsing and drying and finally the process is finished.
Step 3:- When the ,Power supply & water supply is 1 ie., ON , the state flow will continue and proceeds to the next state.
Step 4:- Then for each of the states, the given time conditions is defined.

And hence as we notice, all the state conditions are in a one way state flow. If the power supply and water supply is on the flow chart will work and will give us the correct output. The outputs can be visualised with the help of the Led indicators.
Step 5:- To attach the indicators, Go to Library browser > Dashboard > Choose Lamp for indicating the working and also Choose Toggle switch for providing inputs.
Step 6:- Connect all the Led's with respective displays and choose Green color for 1 (ON) and Red color for 0 (OFF)
Condition 1:- Both the power supply & water supply are ON :-

Condition 2:- When the power supply & water supply are OFF:-

Condition 3:- When the water supply is stopped:-

Task 2 :-
To Make a Simulink chart for the “Gear shift” logic as per below conditions:
Speed Range(kmph) Gear
0 to 15 1
16 to 25 2
26 to 40 3
41 to 60 4
Above 61 5
Give speed input while the simulation is running & display the gear number.
Simulink model creation:-
Step 1:- Choose the 'Chart' block. Define the Input condition as Speed and Output as Gear. A constant block is connected to indicate the Speed in kmph and display block is connected to display the gear number.
Step 2:- Now, Double click the Chart block and the flow chart for the gear shifting logic is created.
Step 3:- For the gear states, the respective speed range is defined. Since it is a two way flow, for greater than conditions one set of flow is defined and for the next set of lesser speeds the corresponding condition is defined as follows:-

Step 4:- Now connect an Led indicator, for the respective gears and the colors are defined as follows:-

Now the final block diagram will looks as follows:-



And hence for the different speeds, we can display the respective LED and the gear number is displayed.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Note: The .slx files for both the scripts are attached with thw answer box