Data Acquisition, Sensors, Control, and AutomationIntroductionMechanical systems increasingly depend on software that measures physical variables, interprets data, and commands actuators. A modern production cell, mobile robot, engine test stand, or heating system is therefore both a mechanical system and an information system. The software pipeline is commonly expressed as: physical variable → sensor → signal conditioning → analog-to-digital conversion → computation → control decision → actuator → physical response This chapter develops the programming and engineering principles needed to construct such systems. It emphasizes sampling, filtering, signal processing, feedback, hardware interfaces, embedded timing, robotics, manufacturing automation, and safety. Examples use Python-like pseudocode and C-like embedded pseudocode; exact libraries vary by microcontroller and operating system. Learning ObjectivesAfter studying this chapter, a student should be able to: - Explain how sensors, interfaces, converters, processors, and actuators form a data-acquisition system.
- Select a sampling rate and identify aliasing risks.
- Implement basic calibration, filtering, and signal-processing operations.
- Distinguish open-loop from closed-loop control and program basic feedback logic.
- Design reliable embedded tasks with timing, communication, and fault handling.
- Describe interfaces used in industrial and robotic systems.
- Apply safety, cybersecurity, ethical, and regulatory principles to automation.
1. Data-Acquisition SystemsA data-acquisition (DAQ) system converts a physical phenomenon into a digital representation that software can process. Typical measured variables include temperature, pressure, displacement, speed, acceleration, force, torque, light intensity, and electrical current. A complete DAQ chain contains: - Sensing element: responds to a physical quantity.
- Transducer: converts that response into an electrical signal.
- Signal conditioning: amplifies, filters, linearizes, isolates, or protects the signal.
- ADC: converts voltage or current into a digital number.
- Processor and software: stores, analyzes, displays, and acts on measurements.
- Actuator and plant: changes the physical system when control is required.
A sensor reading is not identical to the physical quantity. It includes bias, gain error, noise, nonlinearity, hysteresis, drift, quantization, and delay. Engineering software must therefore record not only values but also units, timestamps, calibration status, and quality flags. Sensors and transducersCommon sensor classes include: | Sensor | Typical measured quantity | Common interface | Important limitation |
|---|
| Thermistor or RTD | Temperature | Analog resistance/voltage | Nonlinearity and self-heating | | Thermocouple | Temperature | Low-level voltage | Cold-junction compensation | | Strain gauge/load cell | Strain or force | Wheatstone bridge | Requires amplification | | Encoder | Position or speed | Digital pulses | Missed counts at excessive speed | | Accelerometer | Acceleration | Analog, I²C, or SPI | Vibration and bias sensitivity | | Pressure transducer | Pressure | 0–10 V, 4–20 mA, or digital | Installation and temperature effects | | Proximity sensor | Presence or distance | Discrete or fieldbus | Target material and alignment |
A static characteristic describes output versus input after transients have settled. Sensitivity is the change in output per change in input. A sensor with output voltage V = 0.01T volts, where T is temperature in °C, has sensitivity 0.01 V/°C within its specified range. A dynamic characteristic describes response to changing input, including time constant, bandwidth, delay, and resonance. CalibrationFor a linear sensor model, y = mx + b where x is the measured physical quantity, y is the sensor output, m is sensitivity, and b is offset. If the software receives voltage and must calculate the quantity, it should invert the model: x = (y - b)/m This relationship assumes linearity and constant calibration coefficients. A two-point calibration uses known pairs (x1,y1) and (x2,y2): m = (y2 - y1)/(x2 - x1), b = y1 - mx1 Units must be consistent. Calibration should be checked periodically because mechanical damage, aging, temperature, and installation can change the result. 2. Sampling, Quantization, and AliasingDigital systems observe a continuous signal at discrete times. If samples are taken at interval Ts, the sampling frequency is fs = 1/Ts where fs is in hertz and Ts is in seconds. The sampling theorem states that a band-limited signal with highest frequency fmax can be reconstructed only if fs > 2fmax The frequency fs/2 is the Nyquist frequency. The inequality is a theoretical minimum; practical systems normally sample substantially faster to allow filter roll-off, timing variation, and useful digital processing. Aliasing occurs when a component above the Nyquist frequency appears as a false lower frequency. An analog anti-aliasing low-pass filter must therefore be placed before the ADC. Software filtering after sampling cannot reliably remove information that has already aliased. QuantizationAn ideal unipolar ADC with N bits and reference voltage Vref has 2N possible codes. The ideal voltage step is approximately q = Vref/(2N - 1) where q is volts per code. Quantization error is commonly modeled as lying approximately between -q/2 and +q/2 for an ideal converter, although real ADCs have offset, gain, integral-nonlinearity, reference, and noise errors. Worked example. A 12-bit, 0–3.3 V ADC measures a sensor output of 1.65 V. The code is approximately code = (1.65/3.3)(4095) = 2047.5 Thus the recorded integer will be approximately 2048, depending on rounding and ADC implementation. The voltage step is 3.3/4095 ≈ 0.806 mV per code. This is resolution, not guaranteed accuracy. Timestamping and synchronizationEvery sample should have a timestamp generated from a stable clock. For multiple channels, the designer must determine whether simultaneous sampling is required. Sequential multiplexing introduces channel-to-channel time differences. In vibration, electrical power, and control applications, clock jitter can create measurable phase error. A real-time task should use a scheduled next-release time rather than repeatedly adding an uncertain software delay. 3. Signal Conditioning and Digital FilteringSignal conditioning may include voltage scaling, bridge excitation, isolation, impedance matching, anti-alias filtering, and protection against overvoltage. A sensor must be compatible with the ADC input range; applying a voltage beyond the permitted range can damage hardware. Moving-average filterFor samples x[k] and a window of M samples, the moving average is y[k] = (1/M) ∑i=0M-1 x[k-i] It reduces random noise but introduces delay and attenuates rapid changes. The equation assumes equally spaced samples and equal weighting. A larger M gives stronger smoothing but poorer responsiveness. Efficient code maintains a running sum: buffer = [0] * M
sum_value = 0
index = 0
for each new_sample:
sum_value = sum_value - buffer[index] + new_sample
buffer[index] = new_sample
index = (index + 1) mod M
filtered = sum_value / MThe buffer must be initialized deliberately; filling it with zeros can create an artificial startup transient. Exponential low-pass filterA first-order discrete filter is y[k] = αx[k] + (1-α)y[k-1] where 0 < α ≤ 1. A value near 1 follows the input rapidly; a small value produces more smoothing. For a continuous first-order time constant τ and sample interval Ts, a useful coefficient is α = 1 - e-Ts/τ This approximation assumes a constant sample interval and a first-order low-pass model. If task timing varies significantly, compute α from the actual interval or correct the timing architecture. Differentiation and integrationA backward-difference estimate of derivative is ẋ[k] ≈ (x[k] - x[k-1])/Ts and a simple rectangular integral is I[k] = I[k-1] + x[k]Ts Differentiation amplifies high-frequency noise, while integration accumulates bias and can drift. Both operations require filtering, saturation limits, and attention to units. 4. Interfaces and Embedded ProgrammingCommon hardware interfaces- GPIO: reads or drives binary states such as switches, lamps, and solenoid commands.
- UART/serial: asynchronous point-to-point communication; framing commonly includes start and stop bits.
- I²C: two-wire addressed bus suitable for nearby sensors; pull-up resistors and address management are required.
- SPI: synchronous bus with separate clock and chip-select signals; generally fast but uses more wires.
- CAN: robust differential multi-node bus widely used in vehicles and machines; message priority affects arbitration.
- Industrial Ethernet and fieldbuses: support distributed I/O, drives, diagnostics, and deterministic or near-deterministic communication.
A protocol is not merely a wiring choice. Software must handle framing, timeouts, retries, invalid values, bus contention, endianness, versioning, and loss of communication. Embedded task structureA reliable application separates acquisition, processing, control, communication, and diagnostics. A typical architecture is: initialize hardware
load calibration and configuration
verify sensors and actuators
periodically:
acquire inputs
validate ranges and timestamps
filter and convert units
update control law
apply output limits
command actuators
record diagnostics
on fault:
remove hazardous energy or enter defined safe state
report fault and require authorized resetA hard real-time task must meet every deadline; a missed deadline may be unsafe. A soft real-time task can tolerate occasional delay with degraded performance. The control period should be selected based on plant dynamics, sensor bandwidth, computation time, and communication delay. 5. Feedback ControlIn open-loop control, the command is generated without measuring the resulting output. Open-loop control is simple but cannot automatically correct disturbances or parameter variation. In closed-loop control, a sensor measures output and the controller uses the error: e(t) = r(t) - y(t) where r(t) is the reference, y(t) is measured output, and e(t) is error. The feedback loop consists of reference, controller, actuator, plant, sensor, and feedback path. PID controlThe continuous proportional–integral–derivative controller is u(t) = Kp e(t) + Ki ∫0t e(τ)dτ + Kd de(t)/dt where u(t) is command, Kp is proportional gain, Ki is integral gain, and Kd is derivative gain. The terms have different units unless the gains are selected consistently with the variables and actuator command. - Proportional action responds to present error.
- Integral action removes persistent steady-state error but may wind up when the actuator saturates.
- Derivative action anticipates error change but is sensitive to measurement noise.
A practical discrete implementation is I[k] = I[k-1] + e[k]Ts D[k] = (e[k] - e[k-1])/Ts u[k] = Kp e[k] + Ki I[k] + Kd D[k] The derivative is often applied to the measured signal rather than the error to reduce derivative kick during a set-point step. Anti-windup can stop integration while the actuator is saturated or back-calculate a correction. Output limits must be enforced after calculating the command. Illustrative calculation. Suppose Kp = 2, Ki = 0.5 s⁻¹, Kd = 0, Ts = 0.1 s, current error is 3 units, and the previous integral state is 4 units·s. Then I[k] = 4 + 3(0.1) = 4.3 and u[k] = 2(3) + 0.5(4.3) = 8.15 This command is valid only if the chosen gain units and actuator range are compatible. Stability and tuningA controller cannot be judged from one gain alone. Stability depends on plant dynamics, sampling, delay, actuator limits, sensor location, and all feedback signs. Excessive gain can cause oscillation; excessive integral action can produce slow oscillation or windup. Tuning methods include model-based design, step-response methods, frequency-response methods, and cautious experimental adjustment. Safety limits must be active during tuning. 6. Automation and RoboticsManufacturing automation combines sensors, programmable logic controllers (PLCs), drives, robots, machine tools, networks, and supervisory software. A PLC commonly executes a cyclic scan: - Read inputs.
- Execute logic.
- Update outputs.
- Perform diagnostics and communication.
A ladder-logic or state-machine implementation should make operating modes explicit: Idle, Ready, Running, Paused, Fault, and Maintenance. State transitions should be triggered by defined events and guarded by interlocks. Robotic systems add joint encoders, force or torque sensors, cameras, end-effectors, and motion planning. A robot program must consider coordinate frames, calibration, reachability, singularities, collision zones, payload, and speed. A vision system introduces illumination variation, lens distortion, latency, and classification uncertainty. A measurement used for safety should not be accepted merely because a machine-learning model reports high confidence; independent safeguards are required. A simple pick-and-place sequence may be represented as: if safety_ok and part_present:
move_to_pick_position()
close_gripper()
verify_grip()
move_to_place_position()
open_gripper()
verify_part_released()
else:
enter_safe_state()Each action needs a timeout and a failure response. “Verify grip,” for example, may use pressure, motor current, position, or a dedicated sensor. 7. Safety, Reliability, and CybersecurityAutomation safety is a systems responsibility, not a software afterthought. A risk assessment identifies hazards, initiating events, severity, likelihood, and safeguards. Relevant practices include guarding, emergency stops, protective interlocks, safe speed, safe torque off, lockout/tagout, and documented commissioning. A software stop command is not automatically an emergency stop. Emergency functions should use appropriately engineered safety circuits or safety-rated control systems, with independent fault detection where required. On sensor failure, the system should enter a defined state such as stopped, de-energized, or manually controlled. “Fail-safe” depends on the hazard: removing power may be safe for a drill but unsafe for a load that could fall. Good engineering practice includes: - range, rate-of-change, plausibility, and timeout checks;
- watchdog timers and brownout handling;
- redundant or diverse sensing for critical functions;
- bounded actuator commands;
- event logs with synchronized time;
- version-controlled software and configuration;
- authenticated updates and least-privilege access;
- network segmentation and protection of remote interfaces;
- validation using simulated, nominal, boundary, and fault cases.
Standards and legal requirements vary by jurisdiction and application. Engineers should consult applicable machinery, functional-safety, electrical, robotic, electromagnetic-compatibility, and occupational-safety standards rather than assuming that a general-purpose controller is safety-rated. 8. Applied Case: Temperature Control of a Heated Process VesselThis is an illustrative case, not a report of a particular plant. Background and problemA laboratory vessel must maintain liquid temperature at 80 °C. A resistance heater is controlled by a microcontroller through a power stage. A resistance temperature detector (RTD) provides measurement. Heat loss changes when the lid is opened, so open-loop duty control is inadequate. AnalysisThe RTD signal is amplified and filtered before entering a 12-bit ADC. The control task runs every 100 ms, so Ts = 0.1 s and fs = 10 Hz. The vessel responds much more slowly than 5 Hz, but the anti-alias filter and control design must still be considered. A second temperature switch provides an independent over-temperature cutoff. The software converts voltage using calibration coefficients, checks that temperature is physically plausible, and applies an exponential filter. A set-point ramp prevents an abrupt command. A PI controller is selected because derivative action would amplify measurement noise. Approach and solution```text every 0.1 s: raw = read_adc() if raw is outside electrical limits: fault( Multiple Choice Questions with AnswersQuestion 1Which component should normally be placed before an ADC to reduce aliasing? A. Digital display B. Analog anti-aliasing low-pass filter C. Actuator driver D. Database logger Correct Answer: B. Analog anti-aliasing low-pass filter Question 2A 12-bit ADC provides how many ideal digital codes? A. 12 B. 256 C. 1024 D. 4096 Correct Answer: D. 4096 Question 3For samples spaced by T_s seconds, the sampling frequency is: A. T_s B. 1/T_s C. 2T_s D. T_s/2 Correct Answer: B. 1/T_s Question 4In a PID controller, which action primarily removes persistent steady-state error? A. Proportional B. Integral C. Derivative D. Feed-forward only Correct Answer: B. Integral Question 5What is a major risk of integral action when an actuator is saturated? A. Aliasing B. Integral windup C. Reduced ADC resolution D. Bus arbitration Correct Answer: B. Integral windup Question 6A sensor model is y = mx + b. If x must be calculated from y, the correct expression is: A. x = my + b B. x = (y + b)/m C. x = (y − b)/m D. x = m/(y − b) Correct Answer: C. x = (y − b)/m Question 7Which interface is commonly designed as a robust differential multi-node bus in vehicles and machines? A. CAN B. GPIO C. A single analog wire D. Unidirectional LED output Correct Answer: A. CAN Question 8Why should a robot sequence verify that a part has been gripped? A. To increase screen brightness B. To detect failure before moving the part elsewhere C. To eliminate all calibration requirements D. To make sampling unnecessary Correct Answer: B. To detect failure before moving the part elsewhere Question 9A hard real-time task is one in which: A. Every deadline must be met for correct operation B. The program never uses sensors C. Only the user interface matters D. Delays are always harmless Correct Answer: A. Every deadline must be met for correct operation Question 10Why is a software stop command not automatically equivalent to an emergency stop? A. Software cannot calculate averages B. Emergency functions require appropriately engineered safety provisions C. Sensors cannot produce digital signals D. PLCs cannot control actuators Correct Answer: B. Emergency functions require appropriately engineered safety provisions
|