📘 Automation Logic & Mode Control
🎯 Lesson Objective
By the end of this lesson, students will:
-
Understand what automation logic means
-
Learn how to design manual mode control
-
Learn how to design automatic mode control
-
Use flags and state variables
-
Combine sensors + conditions + outputs
-
Build real smart-system logic
1️⃣ What is Automation Logic?
Automation logic is:
A set of conditions that automatically control a system based on inputs.
Example:
If temperature > 30°C
→ Turn AC ON
If water level > 90%
→ Turn pump OFF
Automation logic removes human intervention.
2️⃣ Manual vs Automatic Systems
There are two main control approaches:
🔹 Manual Control
User directly controls device.
Example:
-
Press button → LED ON
-
Mobile app → AC ON
Decision comes from user.
🔹 Automatic Control
System decides based on sensor input.
Example:
-
Temperature > setpoint → AC ON
-
Gas detected → Buzzer ON
Decision comes from program logic.
3️⃣ Why Mode Control is Important
Real smart systems allow:
✔ Manual override
✔ Automatic operation
✔ Safe fallback
Example:
Smart AC:
Manual mode → User controls AC
Auto mode → Temperature controls AC
Mode switching makes system flexible.
4️⃣ Designing Mode Logic
We use a variable to store mode.
Example:
bool manualMode = false;
If:
manualMode = true → Manual control
manualMode = false → Automatic control
This variable acts as a control flag.
5️⃣ Basic Manual Control Example
bool manualMode = true;
bool acState = false;
void loop() {
if (manualMode == true) {
if (buttonPressed == true) {
acState = true;
} else {
acState = false;
}
}
}
Here:
User decides AC state.
6️⃣ Basic Automatic Control Example
bool manualMode = false;
float temperature = 32;
float setPoint = 30;
bool acState = false;
void loop() {
if (manualMode == false) {
if (temperature > setPoint) {
acState = true;
} else {
acState = false;
}
}
}
Here:
Sensor decides AC state.
7️⃣ Complete Mode Control Structure
Professional structure:
void loop() {
if (manualMode == true) {
manualControl();
} else {
automaticControl();
}
}
Then create functions:
void manualControl() {
if (buttonPressed == true) {
acState = true;
} else {
acState = false;
}
}
void automaticControl() {
if (temperature > setPoint) {
acState = true;
} else {
acState = false;
}
}
This is clean modular automation design.
8️⃣ Real IoT Example – Smart Water Tank
Variables:
bool manualMode = false;
int waterLevel = 40;
int minLevel = 30;
int maxLevel = 90;
bool pumpState = false;
Automation logic:
if (manualMode == false) {
if (waterLevel < minLevel) {
pumpState = true;
}
if (waterLevel > maxLevel) {
pumpState = false;
}
}
This creates automatic water management system.
9️⃣ Using Flags (State Variables)
A flag is a variable that stores state.
Examples:
-
manualMode
-
acState
-
pumpState
-
gasAlert
Flags help track system condition.
Example:
bool gasAlert = false;
if (gasValue > threshold) {
gasAlert = true;
}
This can later trigger buzzer or notification.
🔟 Combining Multiple Systems
Example – Smart Home:
if (manualMode == false) {
if (temperature > setPoint) {
acState = true;
}
if (gasValue > gasThreshold) {
buzzerState = true;
}
if (waterLevel < minLevel) {
pumpState = true;
}
}
Multiple automations can run together.
1️⃣1️⃣ Priority Handling
Sometimes safety must override manual mode.
Example:
Gas detection should override everything.
if (gasValue > gasThreshold) {
acState = false;
buzzerState = true;
}
This is called priority logic.
Safety always first.
1️⃣2️⃣ State Machine Thinking (Basic Concept)
Instead of thinking only in conditions, think in states.
Example:
AC states:
-
OFF
-
COOLING
-
ERROR
Advanced systems use state machines.
This lesson prepares students for that thinking.
1️⃣3️⃣ Common Beginner Mistakes
❌ Mixing manual and auto logic together
❌ Not using mode flag
❌ Overwriting state incorrectly
❌ Not separating logic into functions
❌ Forgetting safety override
Always design logic first on paper.
Then code.
1️⃣4️⃣ Designing Before Coding
Before writing code, ask:
-
What inputs exist?
-
What outputs exist?
-
What conditions control outputs?
-
Is there manual override?
-
What is safety behavior?
Automation is about logic clarity.
📌 Lesson Summary
In this lesson, we learned:
-
What automation logic is
-
Manual vs automatic systems
-
Mode control using flags
-
Designing smart AC logic
-
Designing water pump logic
-
Using state variables
-
Safety override logic
-
Structured automation programming
This lesson prepares students for:
All real IoT projects.