Input Devices
What Are Input Devices?
In the world of electronics and physical computing, input devices are like the senses of a microcontroller. Just as humans rely on senses like sight, touch, and hearing to understand and react to the world, microcontrollers (like my XIAO RP2040) use input devices to gather real-world information and respond accordingly.
An input device is any electronic component or sensor that detects a physical phenomenon โ such as light, motion, temperature, or sound โ and sends that data to a microcontroller in the form of electrical signals.
Think of them as:
-
๐๏ธ Eyes (IR sensor, camera)
-
๐ Ears (microphone, sound sensor)
-
๐๏ธ Skin (touch sensor, pressure pad)
-
๐ก๏ธ Thermometer (temperature sensor)
-
๐ฎ Inner ear (accelerometer, gyroscope)
Types of Input Devices
Category | Sensor Type | How It Works | Common Applications |
---|---|---|---|
Environmental | Temperature, Humidity | Uses a thermistor for temperature and a capacitive sensor for humidity. | Weather stations, smart homes, HVAC systems |
Physical Contact | Capacitive Touch | Detects changes in capacitance when a finger touches or nears the pad. | Touchscreens, switches, interactive devices |
Proximity/Distance | Ultrasonic, Infrared | Ultrasonic: Measures echo time. IR: Detects reflected IR light. | Robot navigation, automatic doors, parking sensors |
Motion | Accelerometer, Gyroscope | Accelerometer senses linear motion; gyroscope senses rotation. | Phones (auto-rotate), gaming controllers, drones |
Sound | Analog Sound Sensor | Converts sound waves to voltage; analog signal represents intensity. | Voice detection, sound-activated devices, noise monitoring |
Light | Light Dependent Resistor | Resistance changes based on light intensity falling on sensor. | Street lights, automatic brightness systems, solar devices |
Group Assignment
You can check out the detailed Group Assignment for this week on Mihir's page. It includes our full process of characterizing the design rules for in-house PCB production using the Roland SRM-20 milling machine, along with tests for different trace widths, clearances, and toolpath settings.
The page also explains our workflow for sending PCBs to a boardhouse like PCBWay, including using KiCad for layout, running DRC checks with manufacturer rule files, exporting Gerbers, and placing the order online.
My Learnings
-
I understood how tool diameter, cutting depth, and plunge rate directly affect the quality and success of PCB traces.
-
Learned how to generate and validate Gerber files for professional manufacturing.
-
Experienced how Mods software helps convert PCB designs into milling toolpaths (G-code).
-
Saw the practical differences between in-house prototyping and outsourced production โ in terms of resolution, finish, and speed.
-
Got hands-on insight into checking trace clearances, spacing, and avoiding bit breakage during CNC milling.
This group task gave me a strong foundation in both rapid prototyping with PCB mills and preparing professional-grade designs for fabrication services.
Individual Assignment
Sensor Explorations
1) DHT11 Temperature and Humidity Sensor
What it does:
The DHT11 is a basic digital sensor that reads:
-
Temperature (in ยฐC)
-
Relative humidity (%)
It uses a thermistor to measure temperature and a capacitive humidity sensor to detect humidity levels. It sends data using a digital signal (single wire communication), which makes it easy to interface.
My Connections:
-
VCC โ 3.3V
-
GND โ GND
-
DATA โ D2
I used the DHT library and could read temperature and humidity every second. I breathed on the sensor and watched the humidity go up โ simple and fun!
CODE - DHT Code
2) TTP223 Capacitive Touch Sensor
What it does:
This sensor acts like a touch-sensitive button. It works on capacitive touch technology, detecting changes in capacitance when a finger comes close. It doesn't need pressure โ just a soft touch.
My Connections:
-
VCC โ 3.3V
-
GND โ GND
-
OUT โ D3
When I touched the sensor pad, the output pin went HIGH. I used it like a digital button in my code โ perfect for future gesture-control projects.
CODE - TTP223 Code
3) HC-SR04 Ultrasonic Distance Sensor
What it does:
This sensor measures distance by using ultrasonic sound waves (just like a bat!). It sends a sound wave via the Trig pin and listens for the echo with the Echo pin. The time delay helps calculate the distance.
Formula:
- Distance = (Time ร Speed of Sound) / 2
My Connections:
-
VCC โ 5V
-
GND โ GND
-
Trig โ D4
-
Echo โ D5
When I placed my hand in front, I could see the distance values change in the Serial Monitor โ it was like magic. I even tried waving my hand at different speeds to watch the numbers fluctuate.
CODE - HC-SR04 Code
4) IR Obstacle Detection Sensor
What it does:
This sensor uses infrared light to detect if an object is in front of it. It has:
-
An IR LED that emits infrared light
-
A photodiode that detects the reflected light
If something reflects the IR light, the sensor's output pin goes LOW or HIGH depending on the module's configuration.
My Connections:
-
VCC โ 3.3V
-
GND โ GND
-
DATA โ D2
I waved objects in front of it and watched the output pin respond. Itโs often used in robots for obstacle avoidance.
CODE - IR Code
5) MPU6050 (Accelerometer + Gyroscope)
What it does:
The MPU6050 is a 6-axis motion tracking device. It contains:
-
A 3-axis accelerometer (measures tilt, gravity, movement)
-
A 3-axis gyroscope (measures angular velocity, i.e., how fast it's rotating)
This combo makes it ideal for projects like drones, gesture control, and balance bots.
My Connections:
-
VCC โ 3.3V
-
GND โ GND
-
SDA โ D4
-
SCL โ D5
I used the MPU6050_light library. At first, it didnโt work โ but then I discovered that I had to set the I2C pins manually using:
CODE - MPU6050 Code
6) Analog Sound Sensor
What it does:
This sensor detects ambient sound levels. It contains:
-
A tiny electret microphone
-
An op-amp circuit that amplifies sound
-
Outputs an analog voltage proportional to sound intensity
It doesnโt record sound โ it just gives you a signal when the sound gets louder.
My Connections:
-
OUT โ A0
-
VCC โ 3.3V
-
GND โ GND
I clapped, snapped, shouted, and even played music โ and watched the analog values spike. Itโs great for sound-reactive LEDs or basic noise monitoring.
CODE - Sound Code
7) Tilt Sensor
For this experiment, I tested a tilt sensor with my custom-designed PCB. The goal was to detect movement and trigger an LED when the sensor was disturbed or tilted. This simple yet effective experiment helped me understand sensor-based interactions and how motion can be converted into a digital output.
Understanding the Tilt Sensor
A tilt sensor is a type of switch that detects changes in orientation. It consists of a small conductive ball or mercury inside a casing. When the sensor is tilted, the ball moves and either completes or breaks the circuit, sending a signal to the microcontroller.
How It Works:
-
Stable Position: The circuit remains open, and no signal is sent (LED remains OFF).
-
Tilted Position: The ball shifts, completing the circuit, sending a HIGH signal to the microcontroller (LED turns ON).
Components Used:
-
Custom-designed PCB (with a microcontroller)
-
Tilt Sensor (ball-switch type)
-
LED (for output indication)
-
Resistors (for pull-down configuration)
-
Jumper Wires (for connections)
Wiring the Circuit:
-
The tilt sensor was connected to a digital input pin of my board.
-
One end of the sensor was connected to VCC and the other to the input pin with a pull-down resistor (to prevent floating signals).
-
An LED was connected to an output pin with a resistor in series.
Programming the Microcontroller
I wrote a simple Arduino sketch to read the tilt sensorโs state and control the LED accordingly.
Testing & Observations
-
When the sensor was stable, the LED remained OFF.
-
When the sensor was tilted, the LED turned ON, confirming the sensor was detecting movement correctly.
-
The response time was almost instant, making it a reliable input device for motion-based triggers.
How I Logged the Data
I used the Serial Monitor in Arduino IDE to view real-time sensor outputs. Sometimes I used the Serial Plotter to visualize changes โ especially helpful for analog sensors like sound and accelerometer data.
I also kept a physical notebook to write down interesting behavior and sensor responses.
What I Learned
-
How to interface 6 different sensors with the XIAO RP2040
-
How to debug I2C problems (like with the MPU6050)
-
The difference between analog and digital sensors
-
Practical applications for each sensor type
-
That seeing physical phenomena turn into numbers is surprisingly satisfying
About the Code
While working with sensors this week โ like the ultrasonic, IR, touch sensor, and accelerometer โ I used ChatGPT to help me with the code. Iโd ask for example sketches or typical ways to set them up, then tweak the code to match my specific board and wiring.
It really saved me time. Instead of digging through tons of websites, I could just ask ChatGPT exactly what I needed, get a clear explanation or a quick sample, and jump right into testing.
I still made lots of changes and adjustments as I went along, but having that help felt like a coding shortcut that also taught me a thing or two.