| File | Date | Author | Commit |
|---|---|---|---|
| README.md | 2025-09-24 |
|
[91921e] README.md |
| code.c | 2025-09-24 |
|
[29df7f] code.c |
Switching States: A Simple C Program Simulation of 0/1
Understanding refrigerator light
Research
Concept of 0/1 Representation
1.1 Introduction:
The refrigerator light switch is a simple yet essential component in household appliances. It automatically turns the light ON when the door opens and OFF when the door closes. This project focuses on simulating this switch using C programming to understand both the real-world device behavior and its logical representation in software. Through this simulation, students can learn about state management, input/output handling, and basic programming constructs.
1.2 Key Points / Definitions:
Switch: A device used to open or close an electrical circuit.
Refrigerator Light Switch: Activates light when the door is open and turns it off when closed.
C Programming Simulation: Models ON/OFF states of a switch using conditional statements.
Applications: Fans, lights, refrigerator lights, microwave door switches, car interior lights.
State Representation: 0 = OFF, 1 = ON, to simplify logical modeling.
Learning Outcome: Understanding of state transitions, error handling, and practical appliance simulation.
1.3 Summary:
In summary, the study of the refrigerator light switch demonstrates how simple physical devices can be effectively modeled in programming. By using C language for simulation, students gain a clear understanding of how switches operate in real life, how their states can be represented digitally, and how practical programming can replicate everyday appliance behavior. This foundation prepares learners to design more advanced switch-based systems and understand the integration of hardware and software logic in real-world applications.
1.4 Sources:
https://www.electronics-tutorials.ws/switch/switch_1.html
https://www.programiz.com/c-programming
https://www.sciencedirect.com/topics/engineering/refrigerator
The refrigerator light must turn ON when the door is opened and turn OFF when the door is closed. The system must accurately detect door status and reflect it in the light state.
2.2 Key Requirements:
Accurate detection of door state (Open/Closed)
Correct representation of light status (ON/OFF)
Simple and understandable logic suitable for C programming
2.3 Input and Output:
Input: Door status (1 = Open, 0 = Closed)
Output: Light status (ON or OFF)
2.4 Pseudocode:
Start
Read door status
If door is Open → set light ON
Else if door is Closed → set light OFF
Display light status
Stop
2.6 Sources:
https://www.geeksforgeeks.org/flowchart
https://www.tutorialspoint.com/cprogramming/index.htm
https://www.electronicsforu.com/electronics-projects
3.1.1 Input Validation Loop:
A loop can be added to continuously prompt the user until they provide a valid input (0 or 1). This ensures that the program handles incorrect entries and only accepts proper input, improving robustness.
3.1.2 Multiple Switches:
Simulating multiple switches allows control of different refrigerator compartments. Each switch can be toggled individually, which introduces complexity and helps in understanding multi-input state management.
3.1.3 Visual Display of State:
The switch state can be displayed both as text (ON/OFF) and using simple ASCII art. This visual representation enhances user interaction and helps users quickly identify the current state of the switch.
3.1.4 State Persistence:
Maintaining the last state across multiple interactions allows the simulation to behave more like a real-world system. Users can see the switch status from previous sessions, providing continuity and a realistic touch.
3.1.5 Timed Switch:
A timed switch automatically turns off after a specified duration. This simulates energy-saving features and adds complexity to the program, teaching users about timing functions and delayed actions.
3.1.6 Sequence Control:
Allowing multiple switch inputs at once, like a sequence of values, introduces batch processing. This feature can simulate managing multiple compartments or devices efficiently, emphasizing sequence handling in programming.
3.2 New Innovations for Future Enhancement
3.2.1 Smart Refrigerator Integration:
Integrating switches into smart systems can monitor usage and energy consumption. It introduces IoT concepts and helps students understand modern appliance management.
3.2.2 IoT Alerts:
Sending notifications if the door stays open for too long makes the system interactive and practical. It teaches real-world application of alerts and sensor-based programming.
3.2.3 Energy Optimization Algorithms:
Adjusting light intensity based on ambient conditions or door activity can save energy. It introduces the concept of adaptive programming and algorithmic enhancements.
3.2.4 User Configurable Settings:
Allowing users to define auto-off timers or light behavior per compartment makes the system flexible. It teaches the importance of customizable parameters in software.
3.2.5 Interactive Simulation:
Console-based or GUI visualization of multiple switches provides a real-time interactive experience. It enhances understanding of user interface design and dynamic state changes.
3.3 Conclusion:
By adding these features and exploring new innovations, the refrigerator light simulation can be made more interactive, realistic, and educational. These enhancements provide students with opportunities to implement advanced programming concepts, handle multiple scenarios, and explore modern applications like IoT and smart appliances.
3.4 Sources:
https://www.iotforall.com/smart-appliances
https://www.sciencedirect.com/topics/computer-science/energy-optimization
https://www.tutorialspoint.com/cplusplus/cpp_oop.htm
Build Code of program
Test
Testing of program and test cases
Case 1:-
Input Output
1 Switch is ON - Light is ON
Case 2:-
Input Output
0 Switch is OFF- Light is OFF
Case 3:-
Input Output
Other than 0&1 Invalid input Please enter 1 or 0.