Skip to content

9. Input Devices

Group assignment:

  • Probe an input device(s)’s analog levels and digital signals
  • Document your work on the group work page and reflect on your individual page what you learned

This is the link to the group site.

Helpful Documenting of Past Students

Files

Individual assignment:

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

What Sensor?

I decided to use the passive infrared sensor sensor. A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. PIR sensors are commonly used in security alarms and automatic lighting applications.

Later in the project I have decided to change this to a Doppler Radar. The Doppler Radar Sensor Module is a doppler radar microwave sensor module for detecting moving objects. This can act as an alternative to Passive Infrared (PIR) motion sensing. The doppler sensor detects “any movement” from “any object” and does not rely on heat, making it more reliable in hot environments.

Unlike the PIR sensor, this is an active sensor. Active sensors send out a pulse of energy and detect the changes in the return signal, while passive sensors detect energy emitted or reflected from an object.

PIR Sensor

Wokwi

Wokwi is a simulater like tinkerCAD. In our lab we are required to first test with a simulator because we don’t want to accidentally to burn out a boards.

This is the code for the PIR sensor in wokwi.

This is the PIR sensor not detecting motion. To simulate the motion I needed to click the button.

This is the PIR sensor detecting motion as you can see. Once the motion was detected the LED turned on.

Code
// Define pins
#define PIR_SENSOR_PIN  D3 // GPIO pin connected to PIR sensor output
#define LED_PIN  D2        // GPIO pin connected to LED

void setup() {
    pinMode(PIR_SENSOR_PIN, INPUT); // Set PIR sensor pin as input
    pinMode(LED_PIN, OUTPUT);        // Set LED pin as output
    digitalWrite(LED_PIN, LOW);      // Ensure LED is off initially
    Serial.begin(115200);            // Start serial communication
}

void loop() {
    int motionDetected = digitalRead(PIR_SENSOR_PIN);

    if (motionDetected == HIGH) {
        digitalWrite(LED_PIN, HIGH); // Turn LED on
        Serial.println("Motion detected! LED ON");
    } else {
        digitalWrite(LED_PIN, LOW);  // Turn LED off
        Serial.println("No motion. LED OFF");
    }

    delay(500); // Small delay to avoid excessive readings
}

This is the code for the PIR Sensor

Testing the Sensor

This is a video of the sensor working. It’s hard to tell but there is a big delay from when my hand goes under the sensor to the LED turning one. The rest of the videos are there to show that the sensor wasn’t that good.

I decided to not solder the PIR sensor because I decided to switch sensors. If I were to solder the PIR, it would have used the same board as the dopple because they both only use three pins. The only thing different is the code that I used.

Why Not PIR Sensor

As you can see in the video, the PIR sensor was working but not as well as I wanted. The sensor only worked part of the time and if you fully covered the sensor. For this reason I decided to switch to a doppler radar. I found the idea of the doppler in Neil’s video for this week. It was one of the reconended ones. Once I researched it more I decided to give it a try and I found one in the lab.

Doppler Radar

To find the documenting for creating the doppler board and for milling, you can find more about it here.

This is an image of the wiring for a doppler sensor. My circut was very simple and one included 3 wires connecting to the doppler. The most important part was the code. The following is the code that I used.

// Fab Academy 2023 - Fab Lab León
// PIR sensor or Doppler radar
// Fab-Xiao

const int RadarPin = D0; // Digital input pin (RP2040 pin 26 or ESP32-C3 pin D0)
const int LED_PIN = D2;  // LED output pin

void setup() {
    Serial.begin(115200);  // Initialize serial communication
    pinMode(RadarPin, INPUT); // Set radar/PIR pin as input
    pinMode(LED_PIN, OUTPUT); // Set LED pin as output
    digitalWrite(LED_PIN, LOW); // Ensure LED is off initially
}

void loop() {
    int value = digitalRead(RadarPin); // Read the value from the sensor (0 or 1)

    if (value == HIGH) {
        digitalWrite(LED_PIN, HIGH); // Turn LED ON when motion detected
        Serial.println("Motion detected! LED ON");
    } else {
        digitalWrite(LED_PIN, LOW); // Turn LED OFF when no motion
        Serial.println("No motion. LED OFF");
    }

    delay(50); // Small delay to avoid excessive readings
}

This is a video of me testing out the dopller radar and as you can see it reacts very well to motion. The good news is that I can adjust the motion but it can get very high in sensitivity.

In week 8, I created the PCB board for the doppler radar. Below is the video of me testing it out. As you can see in the video it shows when the the motion is deteacted.

Reflection

Group

The group assignment was very easy once we figured it out. At first we didn’t know what we were doing and was just pressing buttons. Eventually we figured out the device that we used and once we did it was very cool to see the different pulses on the anolog reader.

Individual

The work that I did on my own was very easy. I treated this week as the next step from last week which was also one more step closer to my final project. I have been trying todo my weekly assignments based on my final project so I dont get behind on that. This week helped a lot with that. Getting the LED to turn on with motion is one step closer to my Magic Mirror turning on when motion detected. Overall this week was easy todo and exciting to compleate.


Last update: April 28, 2025