---
# System prepended metadata

title: Touchless Sensor report

---

# **Touchless Proximity Sensor with Wireless Dashboard Using Raspberry Pi Pico W**

Author: Santiago Peña Hallasi  
Student ID: sp223pv

## **Overview**

This project demonstrates how to build a wireless proximity detection system using the **Raspberry Pi Pico W** and the **APDS-9930 sensor**. When a hand or object approaches the sensor, the proximity value is read and visualized both on a physical LED bar and a live web dashboard hosted on a local server. This project explores real-time data acquisition, wireless data transmission over Wi-Fi, and web-based data visualization.

## **Estimated Time**

6–8 hours

## **Objective**

### **Why I chose this project**

I was inspired to build a gesture-based proximity system as a step toward more intuitive, touchless interfaces. It's especially relevant for applications in public spaces or home automation.

### **What purpose does it serve**

It allows monitoring of nearby activity or user interaction without physical contact. For example, it could serve as the base for a touchless light switch, interactive kiosk, or presence-aware system.

### **What insights it could give**

The system logs proximity levels over time, which can help analyze patterns of movement or usage. It could also be used to track engagement time near devices or detect motion trends.

## **Material**

| Item | Description | Source | Cost |
| :---- | :---- | :---- | :---- |
| **Raspberry Pi Pico W Kit** | Microcontroller with built-in Wi-Fi | amazon.com | 359 SEK |
| **APDS-9930 Sensor** | Proximity and ambient light sensor (I²C) | Local electronics store | 65 SEK |
| **LED bar (2510SR-1)** | 10-segment common anode LED bar | Included | \- |
| **Jumper wires** | For breadboard connections | Included | \- |
| **Breadboard** | For prototyping | Included | \- |
| **USB-C cable** | For programming and power | Already owned | \- |

**Raspberry Pi Pico W**
![image_2025-07-04_053148327](https://hackmd.io/_uploads/SJC7iaNSgl.png)

**APDS-9930 Sensor** 
![image_2025-07-04_053246518](https://hackmd.io/_uploads/B1dwo64Bge.png)


## **Sensor Notes**

* **APDS-9930**: Offers proximity detection up to \~10 cm, communicates over I²C.  
* **LED bar**: Each segment lights up as proximity increases. Wired to GPIO pins 6–15.  
* **Pico W**: Controls sensor and LEDs, and handles Wi-Fi communication.

## **Computer Setup**

* **IDE Used**: **Thonny**  
  * Supports MicroPython and Raspberry Pi Pico W directly.  
  * **Flashing MicroPython**: via "Tools \-\> Options \-\> Interpreter" \-\> Select Pico W.  
  * **Uploading**: Simply save .py files directly to the device.  
* **Additional Setup**:  
  * Install uasyncio, urequests libraries (bundled in MicroPython v1.20+).  
  * No additional drivers were needed beyond Thonny’s built-in tools.

## **Putting Everything Together**

### **Wiring Diagram (simplified):**

* **APDS-9930**:  
  * VCC \-\> 3.3V  
  * GND \-\> GND  
  * SDA \-\> GP0  
  * SCL \-\> GP1  
* **LED Bar (Common Anode)**:  
  * Pins 1–10 \-\> GP6–GP15  
  * Common anode \-\> 3.3V  
  * Use \~220 Ohm resistors for each cathode

### **Notes:**

* The LED segments are **active-low**, so a GPIO LOW (0) turns them ON.  
* Ensure all grounds are connected (Pico, sensor, LEDs).

## **Platform Choice**

**Local Flask \+ SQLite server on PC**

* Data sent via **Wi-Fi socket** (faster and less blocking than HTTP)  
* **SQLite** chosen for simplicity and easy querying  
* **HTML dashboard** shows recent proximity history (auto-refresh every 2 seconds)

### **Why local?**

* Simpler, offline use.  
* Avoids cloud cost and complexity during development.  
* Scalable later via Firebase or MQTT if needed.

## **Core Code Highlights**

### **1\. Read and show proximity:**

```
def read\_proximity():  
    return i2c.readfrom\_mem(APDS9930\_ADDR, PROXIMITY\_REG, 1)\[0\]

def show\_bar(n):  
    for i, pin in enumerate(bar\_leds):  
        pin.value(0 if i \< n else 1\)  \# Common anode logic
```

### **2\. Async loop for sensing and sending:**

```
async def main():  
    addr \= socket.getaddrinfo(SERVER\_IP, PORT)\[0\]\[-1\]  
    s \= socket.socket()  
    s.connect(addr)  
    while True:  
        prox \= read\_proximity()  
        s.send(bytes(f"{prox}\\n", "utf-8"))  
        show\_bar(min(int(prox / 25.6), 10))  
        await asyncio.sleep(0.1)
```

* **Non-blocking loop** ensures real-time LED updates and fast Wi-Fi communication.  
* **Socket is faster** than urequests/HTTP and avoids async lag issues.

## **Transmitting the Data**

* **Protocol**: Wi-Fi TCP socket  
* **Transport**: Raw socket string data ("82\\n", etc.)  
* **Update frequency**: \~10Hz (every 0.1s)  
* **Design choice**: Avoid HTTP latency by using persistent sockets  
* **Battery use**: Moderate, Wi-Fi stays on; could be optimized using sleep cycles

## **Presenting the Data**

### **Backend Server (Flask \+ socket \+ SQLite)**

```
@app.route("/")  
def dashboard():  
    data \= get\_all\_proximity()  
    return render\_template("index.html", data=data)
```

### **Frontend (index.html)**

```
\<table\>  
  \<tr\>\<th\>ID\</th\>\<th\>Proximity\</th\>\<th\>Timestamp\</th\>\</tr\>  
  {% for row in data %}  
  \<tr\>\<td\>{{ row\[0\] }}\</td\>\<td\>{{ row\[1\] }}\</td\>\<td\>{{ row\[2\] }}\</td\>\</tr\>  
  {% endfor %}  
\</table\>
```

* Data is stored in a table with timestamps.  
* Auto-refreshes every 2 seconds for real-time display.  
* Database holds latest 20 entries (easy to scale).

## **Tutorial**

### 1. **Flash MicroPython to Pico W**
- Open Thonny → Tools → Options → Interpreter
- Choose “MicroPython (Raspberry Pi Pico)” and select your USB port

### 2. **Connect components** (as described in Wiring section)

### 3. **Upload code**
- Save `main.py` to your Pico W (this contains Wi-Fi + proximity logic)
- Use another Python script on your PC to run the Flask server

### 4. **Run the server**
- Install Flask and SQLite (`pip install flask`) if needed
- Start the backend script (`python server.py`)

### 5. **View the dashboard**
- Open browser at `http://localhost:5000`
- You’ll see proximity data updated every 2s

---

## **Finalizing the Design**

### **Results:**

* Fully working touchless proximity sensor  
* Real-time LED feedback \+ visual dashboard  
* Fast, responsive, and smooth thanks to async socket usage

### **Possible Improvements:**

* Add gesture classification (e.g., swipe left/right)  
* Replace LED bar with RGB LED strip (for more expressive UI)  
* Send data to Firebase or integrate with Home Assistant

## **Final Images:**

* Photo of circuit on breadboard  
![WhatsApp Image 2025-07-04 at 01.27.49_2ae73510](https://hackmd.io/_uploads/rk-9I64Bee.jpg)

* Photo of circuit on breadboard working  
![WhatsApp Image 2025-07-04 at 05.10.11_534fb153](https://hackmd.io/_uploads/rJQuOaESxg.jpg)

* Screenshot of the web dashboard  
![image](https://hackmd.io/_uploads/By3XhYErgg.png)

* Final result video  
@[youtube](https://youtube.com/shorts/mWcW8BndAbw)


## **Conclusion**

This proximity sensor project helped me understand embedded Wi-Fi communication, I²C sensor integration, and asynchronous programming. The system worked reliably and gave me insight into building interactive, touchless systems for smart environments.