Fab Academy 2026  ·  Week 09

Input
Devices

This week I explored how microcontrollers read the physical world through input sensors. I tested both analog and digital signals using an oscilloscope and multimeter, then connected an HC-SR04 ultrasonic sensor and a PIR motion sensor to my custom PCB from Week 8.

HC-SR04 PIR Sensor LDR Oscilloscope XIAO nRF52840 Arduino IDE Digital Signal Analog Signal
Sensors on custom PCB PIR Sensor HC-SR04 Ultrasonic Sensor

Group Assignment

  1. Probe an input device's analog levels and digital signals using a multimeter and oscilloscope
  2. Document work on the group page and reflect individually

Individual Assignment

  1. Measure something: add a sensor to a microcontroller board that you have designed and read it

Tools Used

  • Oscilloscope & Multimeter
  • Arduino IDE 2.3.8
  • Seeed XIAO nRF52840
  • HC-SR04 · PIR HC-SR501 · LDR
01
Group Assignment

Probing Analog & Digital Signals

For the group assignment, we used an oscilloscope and a multimeter to measure and compare how different sensors behave electrically — specifically looking at the difference between a digital signal (PIR sensor) and an analog signal (LDR sensor).

⚡ Digital Signal — PIR Sensor

PIR Sensor (Passive Infrared Sensor)

A PIR (Passive Infrared) sensor detects motion by measuring changes in infrared radiation from objects such as the human body. Unlike an LDR, a PIR sensor provides a digital output:

✅ Motion Detected

Output goes HIGH (1) — a clear 3.3V or 5V signal.

❌ No Motion

Output stays LOW (0) — a constant 0V signal.

This means the signal is not continuous — it switches abruptly between two states.

Explanation

A PIR sensor detects sudden changes in infrared radiation in its environment. When movement occurs, the sensor output changes abruptly from LOW to HIGH. Because of this behavior, the output signal is digital, meaning it only has two possible values (0 or 1), rather than a continuous range.

Oscilloscope Observations

When no motion is detected, the oscilloscope shows a constant low signal. When motion is detected, the signal suddenly changes to a high value, creating a sharp transition. These abrupt changes appear as sudden jumps in the signal rather than smooth variations — resulting in noticeable pulses as the signal switches quickly between LOW and HIGH states.

📊 Analog Signal — LDR Sensor

LDR (Light Dependent Resistor)

An LDR changes its resistance continuously depending on the amount of light it receives:

☀️ More Light

Lower resistance → higher voltage in the circuit.

🌑 Less Light

Higher resistance → lower voltage in the circuit.

Because of this, when used in a voltage divider circuit, the output signal is analog — a variable value, not just 0 or 1.

Previous Exploration: We previously explored this sensor using an oscilloscope and a multimeter in Week 6.

→ Go to Week 6: Electronics Design

Explanation

An LDR changes its resistance continuously depending on the amount of light. When used in a circuit such as a voltage divider, the output signal is analog — a variable value rather than a binary one. This allows us to detect not just presence/absence of light, but precise intensity levels.

Oscilloscope Observations

In the first observation, the LDR is connected in the circuit. The oscilloscope shows a signal with approximately one division of voltage — a constant line indicating stable ambient light conditions. The sensor is receiving room light and producing a steady output signal.

LDR analog signal — ambient light

When the sensor is covered, the signal changes. The frequency (Hz) decreases, and if partially covered with a finger, fluctuating waves become visible on the oscilloscope. These waves vary within a certain range depending on how much light is blocked.

LDR analog signal — sensor covered
02
Individual Assignment

Testing Sensors on My Custom PCB

For this week I wanted to put my custom PCB — designed in Week 8: Electronics Production — to the test. I intentionally designed my board with male header extensions for 5V, 3.3V, digital pins, and analog pins so that external sensors could be connected easily.

My plan was to test two sensors that will help with my final project: the HC-SR04 ultrasonic sensor and the PIR sensor. Both will be used to manage the part of my dispenser that detects hand motion to trigger the dispensing mechanism.

At university we had used these sensors with an Arduino Uno and a breadboard — but this time it would be different. Everything would run exclusively through my custom PCB.

Sensors connected to custom PCB
03
Input Sensor 1

Ultrasonic HC-SR04

I reviewed my notes from the Physics course I took at Universidad del Pacífico to explain the theory and operation of this sensor.

→ View Physics Notes — sensordistancia.pdf

📡 Sensor Overview

The HC-SR04 detects objects and measures their distance using ultrasound — essentially a sound too high-pitched for humans to hear.

HC-SR04 Ultrasonic Sensor front HC-SR04 Ultrasonic Sensor detail

🔌 TRIG vs ECHO — What Each Pin Does

TRIG — The "Shoot" Command

Pull it HIGH for 10 µs and the sensor fires 8 ultrasonic pulses at 40 kHz. That specific 8-pulse pattern lets the receiver distinguish its own signal from random background noise.

ECHO — The "Listen" Pin

Goes HIGH the moment those pulses are fired and drops LOW the instant the reflection returns. The time it stays HIGH is exactly how long the sound took to make the round trip. No reflection? Times out after 38 ms and resets.

⚠️ Both VCC and ECHO operate at 5V only. The XIAO nRF52840 tolerates 3.3V max on its pins — use a voltage divider on the ECHO pin.

📐 How It Works

Everything comes down to one simple idea: sound travels at a known speed, so measuring time gives you distance.

Distance = Velocity × Time   |   Speed of sound = 343 m/s = 0.0343 cm/µs

Since the pulse travels to the object and back, divide by 2:

Distance (cm) = 0.017 × Time (µs)   ≡   Distance (cm) = Time (µs) / 58

Operation Sequence

  1. Send a 10 µs HIGH pulse to TRIG.
  2. Sensor fires 8 ultrasonic bursts at 40 kHz.
  3. ECHO goes HIGH — the clock starts.
  4. Reflection arrives → ECHO goes LOW — the clock stops.
  5. Apply: Distance (cm) = Time (µs) / 58.

📋 Technical Specifications

ParameterValue
Operating Voltage5V DC
Standby Current< 2 mA
Working Current15 mA
Ultrasonic Frequency40 kHz
Measurement Range2 cm — 400 cm
Resolution0.3 cm (~3 mm)
Effective Angle< 15°
Recommended Cycle Period≥ 50 ms

Pinout

PinNameFunction
1VCCPower supply — 5V
2TRIGTrigger input — 10 µs pulse
3ECHOEcho output — HIGH duration proportional to distance
4GNDGround

💻 First Program: LED Reacts to Distance

The code defines three pins: TRIG (D9), ECHO (D10), and an LED (D8). In setup, all pins are configured and the LED starts off. In the loop, the TRIG pin sends a 10µs ultrasonic pulse, and the ECHO pin measures how long it takes to bounce back. That time is converted to centimeters using the formula (duration × 0.034) / 2. If the distance is under 10 cm, the LED turns on — otherwise it stays off.

Arduino / C++
const int TRIG = D9;
const int ECHO = D10;
const int MY_LED = 8;

void setup() {
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(MY_LED, OUTPUT);
  digitalWrite(MY_LED, LOW); // LED off at start
}

void loop() {
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  long duration = pulseIn(ECHO, HIGH);
  float distanceCM = (duration * 0.034) / 2;

  if (distanceCM < 10) {
    digitalWrite(MY_LED, HIGH); // Hand close — LED ON
  } else {
    digitalWrite(MY_LED, LOW);  // No hand — LED OFF
  }
  delay(100);
}
04
Input Sensor 2

PIR Motion Sensor

For this sensor, I also reviewed my lab notes from the Physics course at Universidad del Pacífico to explain its theory and operation.

→ View Physics Lab Notes — sensorpir.pdf

👁️ Sensor Overview

The PIR sensor detects motion by reading the infrared radiation naturally emitted by living beings. When a person enters its field of view, their body heat causes a change in the detected radiation — and that's what triggers the sensor. Field of view: 100°. It only needs 1 digital pin.

PIR Sensor front view PIR Sensor back — potentiometers

🔧 The Two Potentiometers

The sensor has two small knobs that let you tune its behavior without touching a single line of code.

Sensitivity

Controls how far the sensor can detect motion — from ~3 m (fully counter-clockwise) up to 7 m (fully clockwise). Too much sensitivity causes false triggers from heat vents, pets, or sunlight. Set it to the lowest range that reliably covers your target area.

Time Delay

Controls how long the OUT pin stays HIGH after motion is detected — from ~3–5 seconds up to 5 minutes. For microcontroller projects, turn this fully counter-clockwise and handle all timing in code — it gives much more precise control.

PotentiometerCounter-clockwiseClockwise
Sensitivity~3 m range~7 m range
Time Delay~3–5 seconds~5 minutes

📋 Pinout

PinNameFunction
1VCCPower supply — 5V
2OUTDigital output — HIGH when motion detected
3GNDGround

💻 First Program: LED Reacts to Motion

First I connected the PIR sensor output to D9 and the LED to D8. The code reads the PIR signal — if motion is detected the pin goes HIGH and the LED turns on, otherwise it stays off.

Arduino / C++
const int PIR = D9;
const int MY_LED = 8;

void setup() {
  pinMode(PIR, INPUT);
  pinMode(MY_LED, OUTPUT);
  digitalWrite(MY_LED, LOW); // LED off at start
}

void loop() {
  int motion = digitalRead(PIR);

  if (motion == HIGH) {
    digitalWrite(MY_LED, HIGH); // Motion detected — LED ON
  } else {
    digitalWrite(MY_LED, LOW);  // No motion — LED OFF
  }
  delay(100);
}
05

Get in Touch