Week 9 - Input Devices

Published on: March 25, 2025
In this week's assignment, we were asked to explore input devices by connecting a sensor to a microcontroller and reading data from it. The goal was to understand how different types of sensors can interact with a board we designed or used earlier in the course. For this assignment, I decided to connect an HC-SR04 ultrasonic distance sensor to my ESP32S3 Plus board. I successfully wired the sensor, programmed it, and was able to receive and interpret distance measurements. In the following sections, I will explain how I redesigned my board, how I connected the sensor, and how I read and displayed the data.
Redesign of the DevBoard
Since I will need a board in my final assignment that can read values from two ultrasonic sensors and transmit them via I2C to another board, I decided to design a new board for this week's task. This board should fulfill that purpose and serve as a prototype for the final project board.
I used my KiCad project from week 8 as a basis to create an optimized version of the board for the ultrasonic sensors with two pinheaders for VCC, ECHO, TRIG and GND each. Additionally, I added a dedicated pin header for the I2C interface to make communication with other devices easier.

Since I reorganized the connections on the PCB, I also had to adjust the routing in the PCB editor accordingly.


This time, we included a rubout underneath the microcontroller area on the PCB. This was done to avoid potential issues during the soldering process, such as accidental short circuits or poor adhesion caused by uneven copper underneath the chip. Removing the copper beneath the microcontroller helps ensure a smoother and more reliable assembly.

During the fabrication of the PCB, I encountered some issues: several milling bits were worn out and had to be replaced. Additionally, I learned from other students that some boards were misaligned in the LPKF milling machine. To resolve this, the sacrificial layer had to be replaced, and the affected milling bits were swapped out.
After maintaining the machine — which also included another spindle maintenance — I was able to mill my board without major issues. Since I wanted to protect the board from oxidation, I applied solder lacquer before assembling the components.


All components used in this week's assignment: my custom ESP32S3-based development board, two HC-SR04 ultrasonic sensors, pin headers, jumper wires and SMD components.
Soldering the board went without major issues along the way. The only thing that slightly annoyed me was a drop of solder that fell right onto the GND side of the LED, leaving behind a visible stain. Luckily, it landed on the ground plane, so the damage was purely aesthetic.

Ultrasonic Sensor
The HC-SR04 is a popular low-cost ultrasonic sensor that uses sound waves to measure distance. It's widely used in robotics, automation, and DIY electronics for obstacle avoidance and range detection.
Working Principle
The HC-SR04 works using the time-of-flight method. It sends an ultrasonic pulse and waits for the echo to return. The time taken for the round trip is used to calculate distance.
- Send a 10μs HIGH pulse to the Trig pin.
- The sensor emits 8 ultrasonic pulses at 40kHz.
- The Echo pin goes HIGH until the echo returns.
- Measure the duration of the HIGH state to calculate the distance.


Pinout
- VCC: 5V power supply
- Trig: Trigger input signal
- Echo: Output signal (pulse width indicates distance)
- GND: Ground
Technical Specifications
- Operating Voltage: 3.3V – 5V DC
- Current: 15mA typical
- Frequency: 40kHz
- Measuring Range: 2cm – 400cm
- Accuracy: ±3mm
- Measuring Angle: ~15°
Distance Calculation
Use the following formula to convert the echo pulse duration into distance:
distance = (duration > 0) ? (duration * SOUND_SPEED / 2) : -1;
If the duration is greater than zero, I multiply the duration (time of flight of the signal) with the speed of the sound and divide it by 2 (as the signal needs to return to the receiver once it is reflected from the obstacle).
Applications
- Robotic obstacle avoidance
- Liquid level detection
- Object proximity sensing
- Parking assistance systems
Programming and Measuring

For this week, I reused the Arduino code I had written during Week 4, where I already worked with an ultrasonic sensor. I simply adapted the code to match the GPIO pin assignments of the Seeed Studio XIAO ESP32S3 on my newly designed development board. Once the correct pins were set, I was able to successfully measure distances with the HC-SR04 sensor.

While measuring with the ultrasonic sensor, I noticed that it requires a 5V power supply to operate correctly. Unfortunately, my board was originally designed for 3.3V, which caused some issues. Luckily, I had also added a pin header with 5V supply to the board, so I was still able to connect the sensor and get valid measurements without having to redesign the entire board for now.

I did verify the sensor's accuracy with a ruler – but unfortunately, I wasn't born with three hands, so I couldn't hold the object, the ruler, and the camera all at once for a picture.
Lessons Learned This week I learned how important it is to design and test a prototype with sufficient time in advance. While working with the ultrasonic sensor, I realized that it requires a 5V power supply — something I hadn't fully considered in my board design, which was optimized for 3.3V.
Luckily, I had included a 5V pin header on the board just in case, which allowed me to still perform measurements successfully. This situation clearly showed me the importance of carefully checking datasheets and electrical requirements again before finalizing any hardware.
Outlook & Improvements for the Next Version
Since I'll need two ultrasonic sensors for collision avoidance in my robot, I plan to route the 5V connection directly to the pin headers for the sensors in the next version of the board. Additionally, I'm currently researching which connector and cable types would work best to ensure secure and reliable connections between the various sensors and boards inside the robot.
Workaround for Testing Both Sensors
Since I only had one dedicated 5V output on my board and needed to power two ultrasonic sensors, I had to find a workaround. Unfortunately, I didn't have a Y-splitter cable at hand. As an alternative, I used a multimeter probe with a banana-to-pin connector to temporarily connect both sensors to the 5V pin. This allowed me to provide sufficient power to both sensors at the same time.

This improvised solution worked well for testing purposes, and I was able to successfully read and display the distance measurements from both ultrasonic sensors in the Serial Monitor. However, for the final version of my board, I will add a second dedicated 5V connection to ensure stable and permanent wiring for both sensors.

Group Assignment
As always you will find our group assignment on our group documentation page.