Skip to content

Activity 4.1.1 — Sensors & Motors


Learning Objectives

By the end of this lesson, students will be able to:

  1. Distinguish between digital and analog sensors
  2. Explain how to interface various sensors with digital circuits
  3. Describe different types of motors and their control methods
  4. Use motor driver ICs to interface motors with digital logic
  5. Design simple sensor-motor interface circuits

Vocabulary

Vocabulary (click to expand)
Term Definition
Sensor A device that converts a physical quantity into an electrical signal
Actuator A device that converts electrical energy into physical motion or other output
Digital Sensor A sensor with two output states: HIGH (1) or LOW (0)
Analog Sensor A sensor with a continuously variable output voltage
Voltage Divider A circuit that produces an output voltage proportional to input voltage
H-Bridge A circuit that allows control of motor direction by reversing polarity
PWM Pulse Width Modulation - rapidly switching to control average power

Part 1: Introduction to Sensors

Sensors are input devices that convert physical phenomena into electrical signals that digital circuits can process.

Two Categories of Sensors

Digital Sensors (On/Off) - Output is either HIGH (1) or LOW (0) - Like a switch that is either open or closed - Easy to connect directly to digital circuits

Analog Sensors (Continuous) - Output varies over a continuous range - Need additional circuitry to convert to digital - Provide more detailed information about the physical quantity


Part 2: Digital Sensors

Common Digital Sensors

Sensor Symbol Function
Pushbutton Pressed = HIGH, Released = LOW User input
Limit Switch Activated = HIGH Detect position/motion
IR Break Beam Beam broken = HIGH Detect object passage
Magnetic Reed Switch Magnet present = HIGH Detect magnetic field
Photointerrupter Light blocked = HIGH Object detection

Digital Sensor Interface

Connecting a pushbutton to a digital circuit:

+5V ──┬── Pull-down resistor (10kΩ) ───▶ Input pin
     ─┴─ Pushbutton
     GND

Pull Resistors: - Pull-down resistor: Connects to GND, keeps input LOW when button not pressed - Pull-up resistor: Connects to VCC, keeps input HIGH when button not pressed (more common)

+5V ──┬── Pushbutton
     ─┴─ Pull-up resistor (10kΩ) ───▶ Input pin
     GND

Key insight: Pull resistors ensure predictable input states. Without them, the input "floats" and can pick up interference, causing unpredictable behavior.


Part 3: Analog Sensors

Common Analog Sensors

Sensor Output Range Application
Photocell (LDR) Dark: high resistance, Light: low resistance Light detection
Thermistor Temperature-dependent resistance Temperature sensing
Potentiometer Position-dependent voltage Position/volume control
Flex Sensor Bending increases resistance Bend detection
Force Sensor Resistance varies with force Pressure/force sensing

Analog Sensor Circuit: Voltage Divider

Most analog sensors change resistance. To convert this to voltage, use a voltage divider:

VCC ──[Fixed R]───[Sensor R]─── GND

        Output Voltage

Formula:

Vout = VCC × (R_sensor / (R_fixed + R_sensor))

Example: Photocell Circuit

+5V ──[1kΩ]───[Photocell]─── GND
          Vout to ADC or comparator
  • In bright light: Photocell resistance is low (~100Ω), Vout is near 0V
  • In darkness: Photocell resistance is high (~1MΩ), Vout is near 5V

Op-Amp Amplification

For small sensor signals, use an operational amplifier:

         ┌─────────────┐
  V-  ───│             │──▶ Vout
        │    Op-Amp   │    (amplified)
  V+  ───│             │
        └─────────────┘

Non-inverting amplifier: Gain = 1 + (R_feedback / R_input)


Part 4: Motors as Actuators

Types of Motors

Motor Type Control Method Application
DC Motor Voltage/speed, polarity/direction General motion
Servo Motor PWM angle signal (0-180°) Precise positioning
Stepper Motor Step pulses, precise increments Precision control

DC Motors

Characteristics: - Speed proportional to applied voltage - Direction depends on polarity of applied voltage - No built-in position control

Speed Control: - Higher voltage = faster speed - PWM can simulate variable voltage

Direction Control: - Forward: Positive to terminal A, Negative to terminal B - Reverse: Negative to terminal A, Positive to terminal B

Servo Motors

Characteristics: - Precise angular position (typically 0° to 180°) - Internal feedback for position control - Controlled by PWM signal

Control Signal: - PWM with 20ms period (50 Hz) - Pulse width determines angle: - 1ms = 0° - 1.5ms = 90° - 2ms = 180°

Stepper Motors

Characteristics: - Moves in precise step increments (e.g., 1.8° per step) - Can hold position without power - Requires controller to energize coils in sequence

Types: - Unipolar: coils have center tap - Bipolar: four wires, no center tap (requires H-bridge)


Part 5: Motor Driver ICs

The L293D Dual H-Bridge

The L293D can drive two DC motors or one stepper motor with direction control.

Pinout:

        ┌─────────────┐
  VCC2 -│             │- GND
  1Y   -│             │- 1A
  1A   -│    L293D   │- 1Y
  2A   -│             │- 2Y
  2Y   -│             │- 2A
  VCC1 -│_____________│- GND

Connections: - VCC1: Logic power (5V) - VCC2: Motor power (up to 36V) - 1A, 2A: Control inputs (from digital circuits) - 1Y, 2Y: Motor outputs

Truth Table:

1A 1Y Output
0 Disabled (Hi-Z)
1 Enabled (HIGH)

For bidirectional control with enable:

Enable Input A Motor Output
0 X Disabled
1 0 Forward
1 1 Reverse

The ULN2003 Darlington Array

The ULN2003 drives stepper motors or high-current loads.

Features: - 7 Darlington pairs - Can sink up to 500mA per channel - Built-in flyback diodes

Typical Stepper Connection:

Arduino ──▶[ULN2003]───▶Stepper Coil
Pin       Channel      Wire

Part 6: Interfacing Sensors with Motors

Example: Light-Activated Motor

Goal: Turn on a fan when it gets too bright

Components: - Photocell sensor - Comparator circuit - L293D motor driver - DC fan

Circuit:

+5V ──[Photocell]───[10kΩ]─── GND
         │              │
         ▼              ▼
      Comparator ──────[Input]
      L293D Enable ───[HIGH when dark]
      Fan Motor

Example: Object Counter with Motor

Goal: Count objects and rotate turntable after each one

Components: - IR break beam sensor - 74LS90 decade counter - L293D driver - Stepper motor

Operation: 1. Object breaks beam 2. Sensor output goes HIGH 3. Counter increments 4. After 10 counts, stepper advances one position


Part 7: Practice Problem

Problem Statement

Design a circuit that: 1. Uses a limit switch to detect when a door is closed 2. Turns on an LED when the door is open 3. Turns on a motor (to close a mechanism) when the door is closed

Components Available:

  • Limit switch (closed = LOW, open = HIGH)
  • LED
  • DC motor
  • L293D motor driver

Draw the circuit and explain the logic.

Show Solution

Circuit Diagram:

+5V ──[Limit Switch]──────▶ Input Pin (with pull-down)
                           ─┴─ Switch to GND (closed position)
                    ┌──────────────┐
                    │ Logic        │
                    │ Input        │
                    └──────┬───────┘
              ┌────────────┼────────────┐
              │            │            │
              ▼            ▼            ▼
          [Inverter]    [LED]      [Motor]
              │            │            │
              ▼            ▼            ▼
           Motor ON    LED ON      OFF when
           when closed  when open   door open
           (door closed           (door open
            signal)               signal inverted)

**Logic:**
- Door open: switch = HIGH → LED ON, Motor OFF
- Door closed: switch = LOW → LED OFF, Motor ON

**Using L293D:**
- Enable pin = switch signal
- Input A = HIGH (for direction)
- When door closes (switch = 0), motor turns

Summary

  • Sensors convert physical phenomena to electrical signals
  • Digital sensors output HIGH or LOW (switches, limit switches, IR beams)
  • Analog sensors output continuous voltage (photocells, thermistors)
  • Use voltage dividers to interface analog sensors with circuits
  • Motors convert electrical energy to motion (DC, servo, stepper)
  • Use motor driver ICs (L293D, ULN2003) to interface motors with digital logic
  • H-bridges enable bidirectional motor control

Key Reminders

  • Always use pull resistors with digital sensors
  • Analog sensors need signal conditioning (voltage dividers, op-amps)
  • Motor drivers protect digital circuits from motor current
  • Use flyback diodes to protect against motor voltage spikes
  • Servo motors use PWM for position control

Custom activity — adapted from PLTW Digital Electronics