Completed
Debugging on the shop floor: serial monitor, logic analyzers and common wiring mistakes
Code that works on the bench sometimes fails once it is wired into a real panel. This lesson gives you a short decision path to follow before you start rewriting code, and closes the pump station project.
What you will learn
- Separate what the PLC reads from what it decides to do.
- Pick the right tool: Serial Monitor, multimeter or logic analyzer.
- Check the three wiring mistakes behind most first-install problems.
Step 1: the Serial Monitor, your cheapest tool
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("I0_0: ");
Serial.println(digitalRead(I0_0));
delay(200);
}
Printing the raw input and output states answers the most common question: is the problem in what the PLC reads, or in what it decides to do? Remove the prints afterwards, they add overhead if left running permanently.
Step 2: if the reading is wrong, go upstream of the code
If the printed value does not match the physical signal, the problem is likely wiring, sensor supply voltage or a signal that changes faster than loop() reads it. A multimeter confirms whether the expected voltage is present at the terminal. A logic analyzer or oscilloscope catches fast or intermittent signals that a print is too slow to show.
Step 3: the three wiring checks
- The terminal you used matches the pinout diagram for your exact board variant.
- The sensor supply voltage matches what your board provides or expects.
- There is a shared ground between the PLC and any externally powered sensor.
These three explain a large share of first-install problems that look like code bugs.
Step 4: if the reading is right, debug the logic
For the state machine from lesson 1, print the current state and the inputs only when something changes, not on every pass. Seeing exactly when and why a transition happened is usually faster than stepping through the switch in your head.
State lastState = IDLE;
if (currentState != lastState) {
Serial.print("State ");
Serial.print(lastState);
Serial.print(" -> ");
Serial.println(currentState);
lastState = currentState;
}
Where you are now
Your pump station has a state machine, non-blocking timing, a Modbus interface, retained data, a watchdog, a plan for expansion and a dashboard. That is the skeleton of a deployable machine.
Go deeper
- PLC wiring mistakes: the 10 that destroy your panel
- RS485 problems: step-by-step bus fault diagnosis
- From prototype to industrial production: 12 steps
- Explore Industrial Shields PLCs
You have finished the course. Take the quiz below to check what you have learned.
There are no comments for now.