Map a button’s logical state to relay driver polarity and motor state.
The focus of this experiment is to trace a push-button decision into relay or motor control. Students then distinguish logic signals from load current and safe driver requirements, and verify commanded states without powering unsupported loads from GPIO. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.
Learning objectives
Trace a push-button decision into relay or motor control.
Distinguish logic signals from load current and safe driver requirements.
Verify commanded states without powering unsupported loads from GPIO.
Identify the configured inputs (Button state; Relay input active low; Software compensates for polarity; Motor supply available) and record the corresponding observed outputs with units where applicable.
Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.
Expected learning outcomes
On completion, students can trace a push-button decision into relay or motor control, distinguish logic signals from load current and safe driver requirements, and verify commanded states without powering unsupported loads from GPIO.
Required deliverables
Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing verify commanded states without powering unsupported loads from GPIO. Separate predicted values from observations.
Prerequisite knowledge and related learning
Review the following catalogue prerequisites before starting. After completion, continue to Lab 4 · Digital input: button, IR & LDR.
Browser teaching model, the named WSL or Python environment, and the physical board/components only for the hardware activity described in the practical instructions.
Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.
X3 / PREPARE
Before starting
Follow the setup guide and use the named terminal or editor. A browser model is not a real GPIO measurement or a running service.
Do not connect a real motor to a GPIO pin. Stop the mock loop with Ctrl+C after the last release.
CONCEPTS / ACTIVE RECALL
Understand the experiment
Scientific architecture · Button, active-low relay and motor truth table
Scientific concept map: Pushbutton — Digital input; GPIO decision — Pressed / released; Active-low relay — LOW energizes; Motor supply — Isolated load path; Motor — ON / OFF.
Scientific foundations and analytical reasoning
Active-low relays energize when their control input is LOW. The motor requires an independent supply and suitable isolation/driver circuit.
Before operating the equipment or executing the program, derive the expected outcome using the required theoretical work in Experiment. Use the diagram to identify the variables and system boundaries.
Scientific theory · Relay switching and inductive load
A relay coil is controlled through a driver and its contacts switch a separate load circuit. An active-low module energizes on LOW; normally open and normally closed refer to the unenergized contact state. Motor startup and inductive transients require a suitable rated supply, driver and suppression.
Worked example and engineering interpretation
With active-low logic, input LOW energizes the relay and can close its normally open contact. HIGH de-energizes it. The GPIO does not directly supply the motor current. Verify contact type and logic polarity in the hardware documentation before energizing a load.
Engineering principles · additional worked teaching example
A relay module may be active-low: output logic 0 energizes its input circuit. A motor's supply and switched contacts are separate from GPIO. With a normally-open contact, de-energized means open; no motor current flows even if software intends ON and supply is absent.
From theory to experiment
Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.
How to investigate Lab 3 · Push-button relay & motor
A pull-up button reads LOW when pressed. An active-low relay energizes when its input is LOW; software polarity compensation ensures intended behavior. Motor supply availability is separate from relay state.
Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.
Experiment-specific guided practice
Objective: Verify button and relay control logic.
Press the button with active-low relay and compensated software. Compare GPIO LOW and energized relay.
Disable polarity compensation. Explain the inverted relay state.
Restore and release button; disable motor supply while pressed. Separate relay activation from motor operation.
Use the actual low-voltage relay and motor wiring instructions; never switch mains in this exercise.
Reference check:
Model boundary:
Independent task and submission evidence
Hold the button pressed and change compensation, then restore it and remove motor supply. Record pin level, relay state and motor state. Do not switch mains.
Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.
Trial
Changed setting
Fixed settings
Predicted result
Actual observation / units
Evidence / uncertainty
A: baseline
Reference
Record
Predict
Record
Record
B: one change
Record
Same as A
Predict
Record
Record
A: repeat
Restore
Same as A
Predict
Record
Record
Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.
Worked engineering reasoning and boundary conditions
Engineering reference configuration: Button state = pressed; Relay input active low = true; Software compensates for polarity = true; Motor supply available = true. In the classroom model, GPIO = 0; Relay = ON; Motor = ON. Use a suitable relay driver and independent safe low-voltage power. A closed, deterministic browser model. The existing practical instructions and source files provide independent execution; browser results are not hardware measurements.
Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.
Concept animation · topology and link dependencies
Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.
Step 1 of 3 · Connection 1
Connection 1
Link 1
b → g · logic
Connection 2
Link 1
b → g · logic
Link 2
g → r · driver
Connection 3
Link 1
b → g · logic
Link 2
g → r · driver
Link 3
r → m · power
Teaching example only; inspect live calculations or real practical evidence separately.
Recall the concept before revealing its explanation.
A scheduled press switches the modeled relay on, release off.
X3 · 03 / 08What initial relay/motor control conditions must be checked?Reveal explanation
Engineering explanation
Do not connect a real motor to a GPIO pin. Stop the mock loop with Ctrl+C after the last release.
X3 · 04 / 08Why use a driver or relay circuit for a motor?Reveal explanation
Engineering reasoning
The GPIO cannot safely supply motor current; use a suitable driver, power supply and protection for inductive loads.
X3 · 05 / 08Why define the relay's active polarity explicitly?Reveal explanation
Engineering reasoning
An active-low module energizes on LOW, so the same software level can mean opposite actuator states on different modules.
X3 · 06 / 08A button controls a relay and motor in a model. Select every technically valid statement.
A. Verify both pressed and released states.
B. A real motor needs a suitable driver and power arrangement.
C. A GPIO pin can safely drive any motor directly.
D. A model relay state proves the physical contacts switched.Reveal explanation
Applied scenario
Correct: A. Verify both pressed and released states.; B. A real motor needs a suitable driver and power arrangement.
X3 · 07 / 08In Push-button relay & motor, which command or code executes Two presses?Reveal explanation
Implementation recall
FAKEPI_PRESS=25@1,25@3 python -m labs.exp03.relay_motor # Ctrl+C after 4 s
X3 · 08 / 08For Push-button relay & motor, which actual output or state confirms the prescribed practical run succeeded, and what does it not establish?Reveal explanation
Evidence & acceptance
Use scheduled active-low button on BCM25 and relay BCM22. Relay is active-low: Motor ON means physical LOW at the driver, Motor OFF means HIGH. Expect transitions around 1 and 3 seconds with 0.3 s presses; stop after 4 s. Real motors require an appropriate driver and power isolation, not direct GPIO.
Execution boundary · Simulated (fake Pi). Browser simulation below is a teaching model, not execution of Python or firmware. The real commands run in VS Code/WSL; Wokwi is used for Arduino/ESP32 where indicated.
Relay-controlled motor. Control and load circuits.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery researchLoading experiment-specific apparatus…Previous model / additional reference tools
Simulation task
Verify button and relay control logic.
Explore the model using its own controls. Record a prediction before changing a condition. Compare the reference with a changed condition, then use the Experiment tab for the procedure, acceptance criteria and notebook. Model outputs and physical observations must remain separate.
Interactive engineering workbenchX3 · Existing model
01 / Explore
Interactive lab simulation
Browser model
Pin and connection reference
WSL uses simulated GPIO. These are source-derived signal mappings; physical connection notes are guidance, not a claim of physical testing.
Component
Signal / pin
Connection notes
Source
Button
BCM GPIO25 · physical 22
Button to GND, pull-up
exp03/relay_motor.py
Relay
BCM GPIO22 · physical 15
Active-low control; motor has separate supply and safe driver
Original virtual instrument; model signals and execution trace.
Loading instrument…
Awaiting model display.
Experimental instrumentation · A/B
Compare two model conditions
Capture a baseline, change one experimental condition, run the model if required and capture the comparison. Snapshots contain visible controls and display text, not physical sensor readings. Review before exporting.
Ask Dr. Mohammad locally, or prepare an experiment-aware prompt for ChatGPT, Gemini or Claude. The external providers open in their own tabs; nothing is automatically submitted.
Public course objective, displayed commands, source excerpts and procedure. Private assessment content is not collected.
Prepare a contextual AI prompt
0 characters
Common secret and email patterns are redacted on preparation; this is not a comprehensive privacy filter. Review the entire editable prompt, including student work and unpublished research, before sharing. The providers apply their own accounts, privacy settings and limits.
Prepare → review → copy & open your selected provider → paste and submit there.
Run & verify — acceptance checklist
Build verification: Source/model reviewed; GPIO Zero runtime pending.
Use scheduled active-low button on BCM25 and relay BCM22. Relay is active-low: Motor ON means physical LOW at the driver, Motor OFF means HIGH. Expect transitions around 1 and 3 seconds with 0.3 s presses; stop after 4 s. Real motors require an appropriate driver and power isolation, not direct GPIO.
Record the actual output, source (mock/model or physical), and any error. A missing tool, timeout or untested external service is not a pass.
Before the simulation or practical, solve both experiment-specific tasks. List the given inputs, show the intermediate calculation or state trace, identify the expected observation, and state a limitation. Show formulas and intermediate calculations where relevant, or draw the requested state/sequence diagram. These are independent classroom fixtures; where they differ from the reference configuration below, do not treat them as measured values. Compare your predictions with the corresponding experiment afterwards.
01 · Predict and derive using the given inputs
Construct the truth table for pressed/released, active-low versus active-high and polarity compensation. Identify energization for each.
Engineering method — A relay module may be active-low: output logic 0 energizes its input circuit. A motor's supply and switched contacts are separate from GPIO. With a normally-open contact, de-energized means open; no motor current flows even if software intends ON and supply is absent. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Compare or justify using evidence
Explain why an energized relay cannot prove motor rotation if supply is absent; draw the separate control and load circuits.
Engineering method — A relay module may be active-low: output logic 0 energizes its input circuit. A motor's supply and switched contacts are separate from GPIO. With a normally-open contact, de-energized means open; no motor current flows even if software intends ON and supply is absent. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Hardware reasoning
Hardware reasoning · Independent work
An active-low relay must energize only while button pressed. Write GPIO output states for pressed/released, then explain why a logic 1 at boot is useful under this policy.
Hardware reasoning — A relay module may be active-low: output logic 0 energizes its input circuit. A motor's supply and switched contacts are separate from GPIO. With a normally-open contact, de-energized means open; no motor current flows even if software intends ON and supply is absent. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
Work is saved locally when browser storage is available. Export it for submission; no remote upload or automatic grade is assigned.
Expanded independent theoretical exercise bank
Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.
Intermediate · Explain a changed-input result
Independent theoretical exercise · X3-01
Use the reference configuration (Button state = pressed; Relay input active low = true; Software compensates for polarity = true; Motor supply available = true), but change Relay input active low = false. The model reports GPIO = 1. Explain the governing rule and assumptions that make this output plausible; identify an independent verification method.
Intermediate · Quantitative comparison
Independent theoretical exercise · X3-02
Two model observations of GPIO are 0 (reference) and 1 (changed condition). Compute signed change and, when the reference is nonzero, percentage change. Explain why units matter.
Intermediate · Interpret a technical trace
Independent theoretical exercise · X3-03
For Motor supply available = false, the model supplies this excerpt from Execution observations:
Event / item · Observed result
Button · pressed
Driver polarity · Active low
Coil · Yes
Motor supply · No
Count rows whose Observed result value is exactly “pressed”, and identify the displayed row numbers. Explain what the count describes.
Advanced · Reverse reasoning
Independent theoretical exercise · X3-04
An observation is Motor = OFF. Candidate A uses Button state = pressed; Relay input active low = true; Software compensates for polarity = true; Motor supply available = true. Candidate B changes the listed settings (Motor supply available = false) and keeps the remaining settings fixed. Which is consistent with the observation? If both can explain it, say what additional evidence is required.
Advanced · Diagnose a reported mismatch
Independent theoretical exercise · X3-05
A student configures Software compensates for polarity = false while preserving all other reference settings, but copies the reference report of GPIO = 0. Evaluate whether the report is justified. Identify the first configuration/output check to perform.
Challenging · Design a controlled verification
Independent theoretical exercise · X3-06
Design a controlled comparison for Lab 3 · Push-button relay & motor using reference Button state = pressed; Relay input active low = true; Software compensates for polarity = true; Motor supply available = true and test Relay input active low = false. Specify the changed setting(s), measured metric GPIO, controls, repetitions, an acceptance check and what evidence can distinguish an actual implementation from the model.
Step-by-step experimental procedure
Map a button’s logical state to relay driver polarity and motor state.
1 · Reference workbench configuration
Use the named reference workbench and its reference inputs. Additional live instruments may have different controls; use the matching instrument. Record virtual and practical results separately.
Button statepressed
Relay input active lowYes
Software compensates for polarityYes
Motor supply availableYes
2 · Perform the investigation in order
Press the button with active-low relay and compensated software. Compare GPIO LOW and energized relay.
Disable polarity compensation. Explain the inverted relay state.
Restore and release button; disable motor supply while pressed. Separate relay activation from motor operation.
Use the actual low-voltage relay and motor wiring instructions; never switch mains in this exercise.
3 · Compare controlled trials
Trial
Independent change
Expected check
Observation
Active-low reference
Use reference inputs above
GPIO: 0; Motor: ON
Record actual result
Missing polarity compensation
Software compensates for polarity = No
Motor: OFF
Record actual result
Released
Button state = released
Motor: OFF
Record actual result
4 · Analyze and report
GPIO logical state, relay coil and separate motor power are different boundaries.
Required evidence: Record the named metrics and trace for the reference and changed cases, then attach the corresponding practical command output or device evidence if available.
Model boundary: A closed, deterministic browser model. The existing practical instructions and source files provide independent execution; browser results are not hardware measurements.
Controlled investigation · reproducible evidence
Method. Use the existing reference workbench configuration and the named controlled changes below. A controlled variable stays fixed while the independent variable is intentionally changed; the dependent variable is the resulting observed output. First predict each trial from the Concepts page. Run the baseline, then change only the specified setting and record the outcome. For deterministic traces one execution per case and a repeated verification are sufficient; for timing or stochastic measurements repeat at least five times, recording each run, median and range. Reset to the reference state between independent comparisons.
Trial
Independent change
Dependent observation
Active-low reference
Use reference inputs above
Record actual outcome and units
Missing polarity compensation
Software compensates for polarity = No
Record actual outcome and units
Released
Button state = released
Record actual outcome and units
Evidence: attach the completed comparison table, one trace or screenshot per condition, and actual practical terminal/hardware evidence where applicable. Explain any prediction mismatch and distinguish modeled behavior from measured results.
Loading laboratory-specific procedure…
Python / Google Colab notebook
Stateful virtual GPIO with explicit direction, input stimulation, PWM and verification; optional real MQTT telemetry exercise. Default profile executed in an isolated local Python kernel. Live services and physical hardware are separate acceptance tasks.
Do not connect a real motor to a GPIO pin. Stop the mock loop with Ctrl+C after the last release.
Complete one-time setup first. Copy one command block at a time into the indicated environment. Do not copy prompt characters. Open new terminals where named; variables are terminal-specific. Ctrl+C stops a running foreground command.
01
Open a terminal in the project root
WSL · Bash
source ~/psut-wsl/activate.sh
cd ~/psut-wsl/labs/pi-practical
✓ Expected: Normally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.Expected result for each action (2)
source ~/psut-wsl/activate.shThe toolkit virtual environment is selected in this terminal, usually with (.venv) in the prompt. Verify which python points into ~/psut-wsl/.venv.
cd ~/psut-wsl/labs/pi-practicalNormally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
Checkpoint you are in the folder that contains labs/ ; every command is python -m labs.expNN.… as on the page.
02
Two presses
WSL · Bash
FAKEPI_PRESS=25@1,25@3 python-m labs.exp03.relay_motor # Ctrl+C after 4 s
✓ Expected: Motor OFF with GPIO22 = HIGH ; each press: GPIO22 = LOW + Motor ON , release: Motor OFF .
Checkpoint Motor OFF with GPIO22 = HIGH ; each press: GPIO22 = LOW + Motor ON , release: Motor OFF .
03
Discuss active-low
Why is the motor ON when GPIO22 is LOW?
Checkpoint OutputDevice(22, active_high=False) : most relay modules switch on a LOW input.
Experimental notebook
Record your own results. Values are not prefilled or independently verified.
Save the actual terminal output from the checkpoints above. For simulated inputs explicitly record browser model, fakepi, mock or Wokwi. Never present those data as physical measurements. If a checkpoint fails, see the troubleshooting guide.
Download this notebook and open Google Colab. Select File → Upload notebook and choose the downloaded .ipynb.
Read the Markdown instructions before each executable cell. Use a Python runtime, run cells from top to bottom, and resolve imports if necessary.
Perform the baseline and controlled changes. Save the notebook with actual outputs and your written interpretation.
Execution scope: Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# X3 · Lab 3 · Push-button relay & motor
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## Theory and purpose
A pull-up button reads LOW when pressed. An active-low relay energizes when its input is LOW; software polarity compensation ensures intended behavior. Motor supply availability is separate from relay state.
**Execution boundary:** local computational model or loopback as explicitly described; not physical measurements or external service certification. Run cells in order.
02Instructions · Markdown
## 1. Define the experiment mechanism and inputs
03Python · executable cell
PYTHON · Code cell
# =====================================================================
# X3 | Code cell 01 | Lab 3 · Push-button relay & motor
# Purpose: 1. Define the experiment mechanism and inputs
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Define the reusable operation system; keep its logic separate from the trial.
def system(button_raw, active_low=True, compensate=True, supply=True):
pressed=button_raw==0
output=int(not pressed) if active_low and compensate else int(pressed)
relay=(output==0) if active_low else (output==1)
return output,relay,relay and supply
## 2. Execute the reference and inspect observations
05Python · executable cell
PYTHON · Code cell
# =====================================================================
# X3 | Code cell 02 | Lab 3 · Push-button relay & motor
# Purpose: 2. Execute the reference and inspect observations
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Repeat the same operation for each configured input so observations are comparable.
for raw in (1,0): print(raw,system(raw))
print('No compensation',system(0,compensate=False))
print('No supply',system(0,supply=False))
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert system(0,supply=False)==(0,True,False)
## Independent investigation and submission
Hold the button pressed and change compensation, then restore it and remove motor supply. Record pin level, relay state and motor state. Do not switch mains.
| Trial | Changed input | Fixed settings | Predicted output | Observed output | Explanation |
|---|---|---|---|---|---|
| A | baseline | | | | |
| B | one change | | | | |
| A repeat | baseline | | | | |
Save outputs and state one limitation.