Sensor and Actuator Notes
Introduction to Sensors and Actuators
- Sensors and actuators are crucial for implementing process control in embedded systems.
- The system collects data from the production process using sensors and transmits signals via actuators.
- Key components include:
- Sensors: Measure continuous and discrete process variables.
- Actuators: Drive continuous and discrete process parameters.
- Devices for Analog-to-Digital Conversion (ADC) and Digital-to-Analog Conversion (DAC).
- I/O devices for discrete data.
Definitions
- Transducer: A device that converts one form of energy into another.
- Sensor: A device that converts a physical parameter to an electrical output.
- Actuator: A device that converts an electrical signal to a physical output.
Sensors
- A sensor responds to an input quantity by generating a functionally related output, usually an electrical or optical signal.
- Examples include ultrasonic range sensors, precision temperature sensors (-40 to 100 degrees Celsius), and flex sensors.
Sensor Components
- Physical Medium
- Sensing Element
- Conditioning
- Target Handling
- Example: Temperature (physical medium) -> Resistance (sensing element) -> Voltage (conditioning) -> Information (target handling)
- Transducers and micro-sensors (10^-6 m) are also key elements.
- Stimulus (s) leads to Signal (S).
Types of Sensors
- Acoustic, sound, vibration
- Automotive, transportation applications
- Chemical sensors
- Electric current, electric potential, magnetic, radio sensors
- Environment, weather, moisture, humidity sensors
- Flow, fluid velocity sensors
- Ionizing radiation, subatomic particles sensors
- Navigation instruments
- Position, angle, displacement, distance, speed, acceleration sensors
- Optical, light, imaging, photon sensors
- Pressure sensors
- Force, density, level sensors
- Thermal, heat, temperature sensors
- Proximity, presence sensors
Analog Sensors
- Output a voltage or current (e.g., 0-5V, 4-20mA).
- Pros:
- Usually cheaper.
- Easy to use with Microcontroller Unit (MCU) ADCs.
- Cons:
- Vulnerable to noise.
- Careful signal routing is required.
- Example: IR proximity sensor (voltage output is non-linearly proportional to reflected infrared light).
Digital Sensors
- Output:
- PWM (Pulse Width Modulation) - Duty cycle, Pulse Width
- Quadrature
- Pros:
- Less vulnerable to noise.
- Easy to use with MCU Input Capture Pin.
- No complicated protocol.
- Cons:
- Strong noise can still malform the signal.
- Example: Ambient Light Sensor (frequency output with fixed 50% duty cycle; frequency changes).
Active vs. Passive Sensor Classification
- Active Sensors
- Require external power (excitation signal).
- Emit energy into the environment and measure the reaction.
- Examples: Tactile sensors (optical barriers, non-contact proximity sensor), Wheel/Motor sensors (optical, magnetic, inductive, and capacitive encoders), Active Ranging (reflectivity sensors, ultrasonic sensors, laser rangefinder, optical triangulation), Motion/Speed Sensors (Doppler radar/sound).
- Generally require more power.
- Passive Sensors
- Do not need an additional energy source.
- Generate an electrical signal in response to an external stimulus.
- Measure ambient environmental energy entering the sensor.
- Examples: Tactile sensors (bumpers, contact switches), Wheel/Motor sensors (brush encoders, potentiometers), Heading Sensors (compass, gyroscopes, accelerometers), Vision based sensors (CCD/CMOS cameras, visual ranging packages), Temperature, microphones, pyroelectric IR (PIR).
- Generally require very little power.
Analog to Digital Converter (ADC)
- An electronic integrated circuit that transforms a signal from analog (continuous) to digital (discrete) form.
- Analog signals are directly measurable quantities.
- Digital signals have two states: “0” and “1”.
Why Use ADC?
- Microprocessors can only perform complex processing on digitized signals.
- Digital signals are less susceptible to additive noise.
- ADC provides a link between the analog world of transducers and the digital world of signal processing and data handling.
ADC Overview
- Microcontrollers commonly use 8, 10, 12, or 16 bit ADCs.
ADC Process
- Sampling and Holding (S/H)
- Quantizing and Encoding (Q/E)
Sampling and Holding (S/H)
- Holding the signal benefits A/D conversion accuracy.
- The minimum sampling rate should be at least twice the highest data frequency of the analog signal.
Quantizing and Encoding (Q/E)
- Resolution: The smallest change in analog signal that results in a change in the digital output.
- Equation for Resolution: AV=2NV, where V = Reference voltage range, N = Number of bits in digital output, and 2^N = Number of states.
- Resolution represents the quantization error in converting the signal to digital form.
- Quantizing: Partitioning the reference signal range into discrete quanta and matching the input signal to the correct quantum.
- Encoding: Assigning a unique digital code to each quantum and allocating the digital code to the input signal.
ADC on Arduino
- ATmega 328 microcontroller has a 10-bit ADC microprocessor.
- Arduino divides the range of 0 to 5 volts into 1024 different voltage levels or intervals.
- 0 volts is in the interval 0, and 5 volts is in the interval 1023.
- 2.5 volts would be in the interval 511 (as well as 2.52 volts or 2.5103 volts).
ADC Characteristics
- Not every pin on a microcontroller can perform analog to digital conversions; on Arduino, these pins are labeled with an ‘A’ (A0 through A5).
- ADCs vary greatly between microcontrollers.
- Arduino has a 10-bit ADC, detecting 1,024 (2^10) discrete analog levels.
- Some microcontrollers have 8-bit ADCs (2^8 = 256 discrete levels) and some have 16-bit ADCs (2^16 = 65,535 discrete levels).
10-bit ADC Transfer Function
- TF=(V<em>ref+−V</em>ref−)/1023
- Example: 5115/1023 = 5 mV wide steps
10-bit ADC Resolution Range
- Transfer Function: 1023 steps5115 mV=5.0stepmV
- Resolution = 1 step = 5.0 mV
- Resolution % = 1023 steps1 step≈0.00098=0.10%
- General n-bit A/D Resolution %: 2n−11
- Given an n-bit ADC with a digital output D, the analog input range is:
- Analog Input Range = (D+21±21)2n−1(V<em>ref+−V</em>ref−)
- Example: 10-bit ADC, V<em>ref+=5115 mV, V</em>ref−=0, D = 1021
- Analog Input Range = (1021+21±21)210−15115−0=5107.5±2.5 mV
Voltage Reference (Vref)
- Example: (V<em>ref+−V</em>ref−)=5115±1% mV
- Digital output: D = 210
- =5115±51.15 mV
- Analog Input = (D+21±21)2n−1(V<em>ref+−V</em>ref−)
- =(210.5±21)(5.000±0.0500)=1052.5±2.500+10.53 mV
- Conclusion: Vref stability is more important than the number of ADC bits.
Improving ADC Accuracy
- Increase the resolution: Improves accuracy in measuring the amplitude of the analog signal.
- Increase the sampling rate: Increases the maximum frequency that can be measured.
Actuators
- Actuators: Convert electrical signals to physical outputs.
Types of Actuators
- Servo Motor
- H-Bridge Motor
- Pulse-Width-Modulation (PWM)
Actuator Construction
- Electrical motors
- Pneumatics and valves
- Solenoids, valves, cylinders
- Hydraulics, pneumatics
- Motors
- Heaters
- Lights
- Sirens/Horns (audio)
Servo Motors
- Components: servo input (electronic control signal) -> electronic control -> servo motor -> gear train system -> output position sensor -> servo output (physical shaft movement).
- Motor speed determined by supplied voltage.
- Motor direction determined by polarity of supplied voltage.
- It is difficult to generate analog power directly from a microcontroller, requiring an external amplifier (pulse-width modulation).
Brushed Motor: H-Bridge
- Allows a motor to be driven in both directions.
- Drive forward: Close 1 and 4.
- Drive backward: Close 2 and 3.
Controlling Brushed Motor: H-Bridge
- States: right, left, free, brake
- Configurations: S1 S2 S3 S4
- right: 1 0 0 1
- left: 0 1 1 0
- free: 0 0 0 0
- brake: 0 1 0 1 or 1 0 1 0
Stepper Motor
- Converts electrical pulses into discrete mechanical movement.
- Shaft rotates in discrete step increments.
- Full torque at standstill.
- Precise positioning and repeatability.
- No brushes.
- Low-speed possible.
- Cons:
* Resonance can occur.
* Not easy to control at high speed.
Motor and Encoder
- Motor speed determined by supplied Voltage.
- Motor direction determined by Polarity of supplied voltage.
- Difficult to generate analog power signal (1A…10A) directly from microcontroller.
- External amplifier (Pulse Width Modulation).
Pulse Width Modulation (PWM)
- A/D converters are used for reading analog sensor signals.
- Instead of using D/A converters for motor control (too expensive and needs power circuitry), PWM is done by software by, e.g., switching power on/off in intervals.
How PWM Works
- The supplied voltage did not change.
- Power is switched on/off at a certain pulse ratio matching the desired output power.
- Signal has very high frequency (e.g., 20kHz).
- Motors are relatively slow to respond.
- The only thing that counts is the supplied power (integral/summation).
- Pulse-width ratio = t<em>on/t</em>period
PWM Terminology
- Period = t<em>on+t</em>off
- Frequency = Period1
- Duty Cycle = t</em>on+tofft<em>on∗100
PWM Details
- A pulse with finite length in time is called ‘time on’ – how long the electrical signal was present.
- Once the electrical signal is removed and until the signal is applied again, it is called ‘time off’.
- If the electrical signal changes to ‘on’ and ‘off’ with continuous and equal intervals of ‘time on’ and ‘time off’, the pulse is periodic.
- Its period is equal to ‘time on’ + ‘time off’.
- The pulse period must remain constant in any change of time.
PWM with Arduino
- With Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each (period).
- A call to
analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.
Arduino Code Example
const int motorPin =
9; // PWM pin connected to the transistor base
void setup() {
pinMode(motorPin, OUTPUT); // Set motorPin as an output
}
void loop() {
analogWrite(motorPin, 204); // Set duty cycle to 80% (204 out of 255)
}
- motorPin is the PWM output pin connected to the base of the NPN transistor.
- Setup Function: Sets the motorPin as an output.
- Loop Function: Uses
analogWrite(motorPin, 204) to control the PWM signal. 204 is 80% of 255 (255 * 0.8 = 204), which means the pin will be on for 80% of the time and off for 20% of the time.
RC Pulse Width Modulation
- Remote control/ RC PWM is different to PWM signal used to control DC motor speed.
RC Servo Motors
- RC Servos has designed to accept the RC PWM signal which is periodic pulse with 1.0 ms to 2.0 ms width (standard).
- The idea behind this position protocol is that 1.5 ms commands the servo to go to the center position.
- A 1.0 ms pulse commands the motor to attempt to reach its leftmost position and 2.0 ms to its rightmost position.
- Any pulse measuring in between 1.0 ms and 2.0 ms is decoded as a position in between leftmost and rightmost.
- RC PWM signal can be generate using microcontroller. The positions available are dependent on timer resolution.
DC Motor Speed Control PWM
- In DC motor it is important to decode the position information (RC Pulse Width) and generate a speed magnitude signal.
- This is done by achieving maximum reverse speed when input is 1 ms.
- While, the motor will stop at 1.5 ms.
- At 2.0 ms, DC motor will move forward at maximum speed.
- Any other pulse width is then decoded to partial speed on the corresponding direction.
Controlling DC Motor : H-Bridge
- H-Bridge motor utilize PWM to control DC motor speed.
- In H-Bridge motor, the duty cycle is proportional to voltage applied into the load –means that voltage applied is directly proportional to motor speed.
- The H-Bridge is chopping the amount of time the motor is receiving energy.
- By varying duty cycle, an infinite amount of voltages can be applied to the motor. This will result, an infinite DC motor speed ranging from stopped running at full speed.