Sensors & Interfacing

Introduction to Sensors

Sensors convert physical phenomena (temperature, light, motion, pressure) into electrical signals that microcontrollers and circuits can process. Understanding sensor interfacing is crucial for building interactive systems and IoT devices.

Sensor Output Types

Analog Sensors

Output continuous voltage/current proportional to measured quantity. Require ADC for microcontroller interfacing.

  • Thermistor: Temperature → Resistance change
  • LDR: Light intensity → Resistance change
  • Potentiometer: Position → Resistance/voltage
  • Hall Sensor: Magnetic field → Voltage

Digital Sensors

Output discrete ON/OFF or binary signals. Can connect directly to microcontroller GPIO.

  • PIR: Motion detected (HIGH/LOW)
  • Reed Switch: Magnet present (OPEN/CLOSED)
  • Limit Switch: Physical contact (PRESSED/RELEASED)

Serial/Bus Sensors

Communicate via digital protocols (I2C, SPI, UART). Provide calibrated data with error checking.

  • BME280: Temperature, humidity, pressure (I2C)
  • MPU6050: Accelerometer, gyroscope (I2C)
  • DHT22: Temperature, humidity (1-wire)

Resistive Sensor Interfacing

Resistive sensors (thermistors, LDRs, FSRs) require a voltage divider to convert resistance to voltage.

Voltage Divider Circuit

Place sensor as R2 (bottom) for positive correlation, or R1 (top) for negative correlation.

Thermistor Example

Circuit: 5V → 10kΩ fixed resistor → Vout → NTC thermistor → GND

At 25°C, thermistor ≈ 10kΩ:

As temperature rises, resistance drops, Vout increases.

ADC Reading

For 10-bit ADC with 5V reference measuring 2.5V: ADC = 512

I2C Sensor Interfacing

I2C (Inter-Integrated Circuit) allows multiple sensors on a single 2-wire bus (SDA, SCL) using unique addresses.

I2C Connections

  • SDA: Serial Data line (bidirectional)
  • SCL: Serial Clock line (master generated)
  • Pull-up resistors: 4.7kΩ typical (SDA and SCL to Vcc)
  • Address: 7-bit or 10-bit unique identifier

Common I2C Sensors

  • BME280 (0x76/0x77): Temperature, humidity, barometric pressure
  • MPU6050 (0x68/0x69): 6-axis accelerometer & gyroscope
  • BH1750 (0x23): Ambient light sensor (lux)
  • DS3231 (0x68): Real-time clock (RTC)

Advantages

  • Multiple sensors on same bus
  • Only 2 wires (plus power/ground)
  • Built-in error checking
  • Calibrated digital output

Signal Conditioning

Raw sensor signals often need conditioning before ADC sampling.

Amplification

Use op-amp circuits to amplify weak signals (e.g., thermocouples, strain gauges).

Filtering

Low-pass RC filters remove high-frequency noise. Cutoff frequency:

Example: R=10kΩ, C=1µF → fc = 16Hz

Level Shifting

Convert 5V sensor signals to 3.3V microcontroller levels using voltage dividers or level shifters.

Practical Applications

  • Weather Station: BME280 for temp/humidity/pressure, BH1750 for light
  • Motion Detection: PIR sensor for security, MPU6050 for gesture control
  • Smart Lighting: LDR for ambient light, adjust LED brightness
  • Industrial Monitoring: Temperature, vibration, pressure sensors
Test Your Knowledge
Take this quiz to test your understanding. You need 80% or higher to pass and earn credit for this course.
5 questions80% required to pass