Input Devices


Group assignment

For the group assignment , the team worked with both analog and digital input devices to understand their signals.

Analog Signals:

Sensor:
The team selected an LDR (Light Dependent Resistor) sensor, which changes its resistance based on ambient light levels.

Observed Signals:
Using an oscilloscope, the team measured the output voltage of the LDR sensor in response to changes in ambient light. They connected the LDR sensor to a microcontroller board and observed the voltage changes when exposed to different light levels. This provided insights into how the sensor's resistance variation correlates with the amount of light it detects.

Digital Signals:

Sensor:
For digital signal measurement, the team utilized an ultrasonic distance sensor, which employs ultrasonic waves to measure distances.

Observed Signals:
Similarly, using an oscilloscope, the team measured the voltage output of the ultrasonic sensor to observe changes in voltage corresponding to different distances. This allowed them to understand how the sensor's digital output varies with proximity to objects.

Summary:
Through these experiments, the team gained practical insights into how both analog and digital sensors operate and how their signals behave in response to changing environmental conditions or distances to objects. This hands-on experience deepened their understanding of sensor technologies and their applications in various electronic projects.


Individual assignment

For my individual assignment, I'm diving into the world of sensors, aiming to understand how they work by connecting them to a development board. My focus is on learning how to link different sensors to the microcontroller and program it to gather data from them.

I've chosen multiple sensors for this project, each with its own unique functions. To make the integration process smoother, I'll be using a board I designed earlier. This board acts as a bridge between the sensors and the microcontroller, providing the necessary connections and interfaces.

The Seeed Xiao RP2040 microcontroller will be at the heart of this project, responsible for tasks like data collection and processing. Its compatibility with various sensors and user-friendly programming capabilities make it a perfect fit for what I aim to achieve.

Now, let's delve into the exciting journey of integrating each sensor with the development board and microcontroller to unlock their potential.

Sensor1: PIR sensor

Let's delve into the Passive Infrared (PIR) sensor, a fascinating device widely used for motion detection. Unlike many other sensors, PIR sensors don't emit any energy themselves; instead, they detect infrared radiation emitted by objects in their field of view.

The principle behind PIR sensors is based on the fact that all objects with a temperature above absolute zero emit infrared radiation. When an object moves within the detection range of a PIR sensor, it causes a change in the pattern of infrared radiation reaching the sensor.

Here's how it typically works:

  1. Detection: The PIR sensor has two slots that detect infrared radiation. These slots are divided by a filter, which blocks out any ambient radiation not emitted by moving objects.

  2. Sensing Motion: When an object moves within the sensor's field of view, it causes a change in the amount of infrared radiation reaching each slot. This change is detected by the sensor.

  3. Output: The PIR sensor then sends a signal to the connected microcontroller, indicating that motion has been detected. This signal can trigger various actions, such as turning on lights, activating an alarm, or capturing images.

  4. Adjustable Sensitivity and Range: PIR sensors often come with adjustable sensitivity and range settings, allowing users to customize their operation based on the specific requirements of the application.

  5. Low Power Consumption: One of the significant advantages of PIR sensors is their low power consumption. They remain in a low-power standby mode until motion is detected, making them ideal for battery-powered applications such as security systems and motion-activated lighting.

When integrating a PIR sensor with a microcontroller, the process typically involves connecting the sensor's output pin to one of the microcontroller's digital input pins. Then, the microcontroller can be programmed to react to the signal received from the sensor, performing tasks based on the detected motion.

Overall, PIR sensors are versatile and widely used in various applications, including security systems, automatic lighting systems, and even in smart home devices. Their ability to detect motion accurately and efficiently makes them an indispensable component in many projects.

Setting up a PIR sensor involves a few steps to ensure proper functionality and reliable detection of motion. Here's a basic guide to setting up a PIR sensor:

  1. Selecting a Location: Choose a location for the PIR sensor where it has a clear view of the area you want to monitor for motion. Ensure that the sensor is positioned at an appropriate height and angle to cover the desired area effectively.

  2. Power Connection: Connect the power supply to the PIR sensor. Most PIR sensors operate on low voltage and can be powered by batteries or a DC power supply.

  3. Output Connection: Connect the output pin of the PIR sensor to a digital input pin on your microcontroller or any other device you want to trigger when motion is detected. Use jumper wires or a breadboard for this connection.

  4. Adjustments: Many PIR sensors come with adjustable settings such as sensitivity and trigger delay. Adjust these settings according to your requirements. The sensitivity setting determines how sensitive the sensor is to motion, while the trigger delay setting controls how long the sensor remains triggered after detecting motion.

  5. Testing: Test the PIR sensor to ensure it is functioning correctly. Move within the sensor's detection range and observe whether it detects motion reliably. Adjust the sensor's position and settings as needed to optimize its performance.

  6. Integration: Once the PIR sensor is set up and tested, integrate it into your project or system. Program your microcontroller to react to the signal from the PIR sensor, triggering desired actions such as turning on lights, sounding an alarm, or sending notifications.

  7. Fine-Tuning: Periodically check and fine-tune the PIR sensor's position and settings to maintain optimal performance. Environmental factors such as changes in lighting conditions or the presence of obstructions may affect the sensor's detection capabilities over time.

By following these steps, you can set up a PIR sensor effectively and leverage its motion detection capabilities in your projects or applications.

For motion detection, I've utilized a PIR motion sensor, and I've programmed an Arduino board to interpret the sensor signals and control the lighting accordingly. It's a straightforward setup that can make a big difference in terms of convenience and energy efficiency.

Microcontroller Programming

To begin programming your microcontroller, set up the Arduino IDE by selecting the appropriate board (Seeed Xiao RP2040) and port.

Code Structure:

  1. Start by including the necessary libraries for analog input and serial communication.

  2. Initialize variables and pins for sensor connection.

  3. In the setup function, initialize serial communication and configure the sensor pin as an input.

  4. In the loop function, use the analogRead() function to read the analog value from the sensor.

  5. Print the sensor readings to the serial monitor for testing and debugging purposes.

Programming Logic:

  1. Read the analog value from the sensor using the analogRead() function.

  2. Convert the analog value to force or pressure units by applying appropriate calibration techniques.

  3. Optionally, you can implement threshold detection or filtering algorithms to obtain more precise readings.

By following this structure and logic, you can effectively program your microcontroller to interface with the sensor and perform the desired tasks.

The code

cpp
//the time we give the sensor to calibrate (10-60 secs according to the datasheet) int calibrationTime = 30; //the time when the sensor outputs a low impulse long unsigned int lowIn; //the amount of milliseconds the sensor has to be low //before we assume all motion has stopped long unsigned int pause = 5000; boolean lockLow = true; boolean takeLowTime; int pirPin = 3; //the digital pin connected to the PIR sensor's output int ledPin = 13; ///////////////////////////// //SETUP void setup(){ Serial.begin(9600); pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(pirPin, LOW); //give the sensor some time to calibrate Serial.print("calibrating sensor "); for(int i = 0; i < calibrationTime; i++){ Serial.print("."); delay(1000); } Serial.println(" done"); Serial.println("SENSOR ACTIVE"); delay(50); } //////////////////////////// //LOOP void loop(){ if(digitalRead(pirPin) == HIGH){ digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state if(lockLow){ //makes sure we wait for a transition to LOW before any further output is made: lockLow = false; Serial.println("---"); Serial.print("motion detected at "); Serial.print(millis()/1000); Serial.println(" sec"); delay(50); } takeLowTime = true; } if(digitalRead(pirPin) == LOW){ digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state if(takeLowTime){ lowIn = millis(); //save the time of the transition from high to LOW takeLowTime = false; //make sure this is only done at the start of a LOW phase } //if the sensor is low for more than the given pause, //we assume that no more motion is going to happen if(!lockLow && millis() - lowIn > pause){ //makes sure this block of code is only executed again after //a new motion sequence has been detected lockLow = true; Serial.print("motion ended at "); //output Serial.print((millis() - pause)/1000); Serial.println(" sec"); delay(50); } } }

Explanation:

  1. Variables Initialization: Variables are defined to store calibration time, time of low impulse, pause duration, and flags for lock and low time.

  2. Setup Function: Serial communication is initialized, pins are set as input and output, and the sensor is calibrated. Calibration involves waiting for the sensor to stabilize after power-on.

  3. Loop Function:

    • If motion is detected (PIR pin is high), the LED is turned on. If it's the first time detecting motion after a pause, the time is printed.
    • If no motion is detected (PIR pin is low), the LED is turned off. If it's the first time detecting no motion after a period of motion, the end time is printed.

This code essentially monitors the PIR sensor's output and toggles the LED accordingly while also providing output to the serial monitor for debugging purposes.

Testing and Results for PIR Sensor using Arduino IDE

Testing Procedure:

  1. Upload the Arduino sketch provided to the Seeed Xiao RP2040 microcontroller via the Arduino IDE.

  2. Open the serial monitor in the Arduino IDE to monitor the sensor readings.

  3. Trigger motion within the detection range of the PIR sensor by moving within its field of view.

  4. Observe the serial monitor for notifications of motion detection and motion cessation.