Introduction: LumiTrap : 3D-Printed Solar UV Bug Trap for Eco-Friendly Pest Control

About: As I explore the exciting world of electronics, I can't help but feel a sense of wonder and amazement at the incredible things I discover!

Seeking a non-toxic and sustainable method to rіd your space of insects? This solar-powered bug trap presents an eco-conscious alternative, removing the necessity for chemicals or pesticides, thereby ensuring safety for individuals and the environment. Whether safeguarding a vegetable gаrden from destructive pests or aiming to relish еvenings on your balcony or at a campsite free frоm insect swarms, this device serves as an optіmal solution. It is especially effective at capturing mosquitoes as well.

This device uses a specialised 365nm spectrum UV LED to attract flying insects and a fan to capture them in a trap, all powered entirely by solar energy. It features a built-in light sensor (LDR) that automatically activates the system at night, following a smart cycle. Initially, the UV light turns on to silently lure bugs for 60 seconds and is then followed by a brief activation of the fan for 30 seconds to capture them. This cycle repeats throughout the night and stops at sunrise, The batteries are recharged by solar panels, making the system highly sustainable and low-maintenance. This project features a fully 3D-printed design. Users can place oil in the bottom tray to trap captured insects, which can then be easily removed and washed after use.

This intelligent, off-grid altеrnative proves ideal for gardens, balconies, рati‍os, greenhouses, and outdoor camping arrangеments. It is also good at capturing mosquitoes. Constructed around the compact, low-powеr XIAO SA‍MD21 board, this project is perfectlу suited for makers prioritizing clean design, lоw-power performance, and a cleaner environment. Whether cultivating vegetables or simply savoring the outdoors, this DIY trap merges functionality, sustainability, and simplicity into a clever design.

With 8 hours of solar charging, the device can run for 7 to 8 hours at night.

Supplies

Step 1: Designing in Fusion 360

I used Fusion 360 to plan and design my project with a focus on easy 3D printing. My goal was to reduce print time and material usage while eliminating the need for supports for overhangs, all while ensuring practicality. This included providing enough space for wiring and making assembly easy. First, I imported 3D models of all the components and experimented with different configurations by arranging the parts in various positions. Once I identified the optimal layout, I designed the enclosure around them.

Firstly, I used a perfboard to assemble the main control circuit. Since creating a 3D model of the circuit board was time-consuming. I took a top-angle photo of the circuit board and designed a model based on the exact dimensions of the perfboard. Then, I used the decal tool to place this image on the surface of the PCB model and resized it accordingly. This process helped me visualize where the screw holes would align and determine the placement of the screw terminals.

After completing the design process, I exported all the files in STL format and 3D printed them. Since it needs to be used outdoors, it is better to 3D print its body in ABS plastic. You can find all design files attached below


Step 2: Code & Flashing XIAO SAMD21

The code is pretty simple. We have 2 MOSFETs to control the FAN and LED also a LDR to find the light intensity

How code workers

If (it's dark):

Turn on the UV LED

Wait 1 minute

Turn on Fan (keep UV LED on)

Wait 30 seconds

Turn off Fan

Repeat

If (it's bright):

Turn off the UV LED and the Fan

The user can change the fan ON/OFF time in the code

const unsigned long uvOnlyDuration = 60000; // 1 minute
const unsigned long fanOnDuration = 30000; // 30 sec

Also, set the Light Threshold voltage here

const float dayThreshold = 2.9; // ≤ 2V = Bright (Day)

After setting all parameters, I flashed the code to XIAO using Arduino IDE

Complete code

// Pin definitions
const int ldrPin = D0; // D0 (LDR input)
const int uvLedPin = D1; // D1 (UV LED)
const int fanPin = D2; // D2 (Fan)

// LDR setup
const float vRef = 3.3;
const int adcMax = 1023;
const float dayThreshold = 2.9; // ≤ 2V = Bright (Day)

// Timing
const unsigned long uvOnlyDuration = 60000; // 1 minute
const unsigned long fanOnDuration = 30000; // 30 sec

void setup() {
pinMode(uvLedPin, OUTPUT);
pinMode(fanPin, OUTPUT);
digitalWrite(uvLedPin, LOW);
digitalWrite(fanPin, LOW);

analogReadResolution(10); // 10-bit ADC
Serial.begin(9600);
}

void loop() {
float voltage = readLdrVoltage();
Serial.print("LDR Voltage: ");
Serial.print(voltage, 2);
Serial.print(" V - ");

if (voltage > dayThreshold) {
Serial.println("Dark - Start cycle");

// Turn on UV LED only
digitalWrite(uvLedPin, HIGH);
digitalWrite(fanPin, LOW);

if (!waitWhileDark(uvOnlyDuration)) return;

// Now turn on fan
digitalWrite(fanPin, HIGH);
if (!waitWhileDark(fanOnDuration)) return;

// Turn off fan (UV LED stays ON)
digitalWrite(fanPin, LOW);
} else {
Serial.println("Bright - Powering off");
digitalWrite(uvLedPin, LOW);
digitalWrite(fanPin, LOW);
delay(500);
}
}

// Helper: read voltage from LDR
float readLdrVoltage() {
int raw = analogRead(ldrPin);
return (raw / (float)adcMax) * vRef;
}

// Helper: wait during dark period, exit early if it gets bright
bool waitWhileDark(unsigned long duration) {
unsigned long start = millis();
while (millis() - start < duration) {
float voltage = readLdrVoltage();
if (voltage <= dayThreshold) {
Serial.println("Daylight detected - exiting early");
digitalWrite(uvLedPin, LOW);
digitalWrite(fanPin, LOW);
return false;
}
delay(100);
}
return true;
}

Step 3: PCB Up Date for This Project

I initially hand-soldered the PCB according to the diagram, but the process was quite time-consuming. To simplify the build, I designed a new PCB with a similar layout. If you're interested in creating this PCB, I recommend ordering it, as it will make the process much easier. You can find the PCB file at this link. Thanks to Seeed Studio Fusion for providing the PCB and supporting this project.

Step 4: DC to DC Module Calibration

Before starting assembly, we need to calibrate both DC-to-DC models. For MT3608, we should provide 4.2V at the input and adjust the potentiometer until we receive 12V at the output. For the Mini 360, provide 12V at the input and turn the potentiometer until we get 5V at the output.

Step 5: Control Circuit Assembly

Here is the wiring diagram for the project. To make the build much easier, I also designed a PCB, which I will mention in upcoming steps.

1. We begin with UV LEDs. Cut the terminals of the LEDs and place them in the holes of the 3D print.

2. Use the cut LED terminal we prepared earlier to connect and solder the LEDs. Using tweezers will be helpful

3. Solder a 500R resistor on the cathode of the LED circuit

4. I created a 2p 1s battery pack and added two wires to both terminals.

But I suggest buying pre-made battery packs. You can find the link in the parts list.

5. Glued the battery using a B-7000 multipurpose glue and placed the battery in the 3d printed compartment

6. Screw in the solar charger wisng four M2 screws

7. Connect the battery terminals to the battery input of the solar charger

8. Screw in the power switch to the side wall using M2 screws

9. Connected solar charger Vout + to one terminal of the switch

10. Secure the PCB to the main body using two M3 screws.

11. Then place the programmed XIAO to the main board

12. Place the LDR onto the holes in the side wall and glue it

13. Solder two wires from the LDR and connect them to the terminal. Then, I connected all the wires according to the circuit diagram. I also left some wires to connect to the fan.


Step 6: Solar Roof Assembly

1. Apply glue to the back of the solar panel and attach it to the top cap, ensuring the solar pins are visible through the back of the top cap.

2. Apply some glue to the sides of the solar pins to ensure waterproofing.

3. Connect all solar cells in parallel. Use Kapton tape to secure the wiring, and solder a long wire to connect it to the solar charger.

4. Connect the solar power output to the solar power input of the charger controller

5. If you need to mount this to a pole or something .you can attach the pipe holder to the side holes using M3 screw and nuts

6 . We are done with all the wiring, and now close the top cap to the main body

Step 7: Final Assembly

1. Cut and spray paint an aluminium tube into four 60 mm pieces. We are using this as a spacer between the fan and the UV LED.

2.Place the aluminium tube onto the main body, aligning with the hole. Then, place the fan holder on top of it. Use an M6 bolt to secure them all together.

3. Do the same thing to all four spacers

4. Attach the fan securely to the fan holder.

5. Run the wires through the hole and solder the power wires to the fan

6. Now, slide the capture tray back into place.

7..I used a 22mm PVC pipe, measuring 1 meter in length, to mount the LumiTrap. For added stability, print a second pipe holder and place it on the fan holder. There's no need to screw the pipe holder into the fan holder's body.


Step 8: Operation and Teasing

First, stick it in the ground, and remove the tray

You can add some oil, like coconut oil, to it. Make sure it is spread evenly.

Please place the capture tray back in its original position. Place the device somewhere it is dark and not close to any light source

Currently, I don't have a vegetable garden for this, but I have a small goat farm. The goats have a problem with mosquito issues and other kinds of small bugs, so I leave them there all night.

So here is the result

Most of the bugs I captured were mosquitoes. Other than that, I also counted some other bugs I don't even know the names of.