Eco-Friendly Automated Mosquito Trap With Arduino Nano

by galofel in Circuits > Arduino

1304 Views, 9 Favorites, 0 Comments

Eco-Friendly Automated Mosquito Trap With Arduino Nano

20260313_130502 (1).jpg
20260313_123217.jpg

Mosquitoes lay their eggs in standing water. A farmer near me taught me a trick: if you let the eggs develop but flush the water before they hatch into adults, you skip the next generation. Repeat every 4 days for a few weeks and the local population drops to almost nothing.

I set up a small garden pool to attract them. The problem? You have to drain and refill every 4 days. Miss a cycle and you're breeding mosquitoes. So I automated it with an Arduino Nano.

No chemicals. No citronella. No bug zappers. Just water and timing. Total cost: ~$35-40.

Supplies

  1. Arduino Nano V3.0 (or Every)
  2. 5V Submersible Mini Water Pump
  3. 12V DC Normally Closed Solenoid Valve (1/2 inch)
  4. 2-Channel 5V Relay Module (SRD-05VDC-SL-C)
  5. 2-Wire Liquid Level Float Switch
  6. 12V 2A DC Power Supply
  7. DC Barrel Jack Adapter (Female)
  8. LM2596 Buck Converter Module
  9. Jumper wires
  10. Weatherproof enclosure

Tools:

  1. Soldering iron
  2. Wire strippers
  3. Multimeter
  4. Screwdriver

Prepare the Power Supply

Connect the 12V power supply to the DC barrel jack adapter. Wire the positive and negative outputs to two rails: one goes directly to the relay module's COM2 terminal (for the solenoid valve), the other goes to the LM2596 buck converter input.

Set Up the Buck Converter

Before connecting anything else, power on the 12V supply and adjust the LM2596 potentiometer with a small screwdriver until the output reads 5.0V on a multimeter. This powers everything except the solenoid valve.

Important: Do this BEFORE connecting the Arduino. Sending 12V to the Nano will fry it.

Connect the Arduino Nano

Wire the 5V output from the buck converter to the Nano's 5V pin (not VIN). Connect GND to GND.


Wire the Relay Module

Mosquito_Pool_Wiring.jpg
  1. Connect 5V and GND from the buck converter to the relay module's VCC and GND
  2. Arduino digital pin → Relay IN1 (pump control)
  3. Arduino digital pin → Relay IN2 (valve control)
  4. Relay 1 COM → 5V, Relay 1 NO → pump positive wire
  5. Relay 2 COM → 12V, Relay 2 NO → solenoid valve positive wire

Wire the Float Switch

Connect one wire to an Arduino digital pin (enable internal pull-up in code), the other wire to GND. When water is high, the switch closes the circuit.

Connect the Pump and Valve

20260313_123227 (1).jpg
  1. Pump negative wire → GND (5V rail)
  2. Solenoid valve negative wire → GND (12V rail)
  3. Position the pump at the bottom of the pool
  4. Connect the solenoid valve to your water supply line

Upload the Code and Test

Upload the code to the Arduino Nano, open Serial Monitor, and manually trigger a test cycle. Verify the pump drains fully and the valve refills to the correct level.

// Mosquito Trap Automation by Make-It
// This code uses a DS3231 Real-Time Clock (RTC) to trigger a water change every 4 days.

#include <Wire.h>
#include "RTClib.h"

// Create an RTC object
RTC_DS3231 rtc;

// --- Pin Definitions ---
#define EMPTY_PUMP_PIN 7 // Digital pin connected to IN1 on the relay module
#define REFILL_PUMP_PIN 8 // Digital pin connected to IN2 on the relay module

// --- Configuration ---
const long CYCLE_INTERVAL_SECONDS = 345600; // 4 days (4 * 24 * 60 * 60 seconds)
const int EMPTY_PUMP_DURATION_MS = 60000; // Run empty pump for 60 seconds
const int REFILL_PUMP_DURATION_MS = 60000; // Run refill pump for 60 seconds

// We need to store the time of the last cycle. We'll use a variable for this.
// For a real-world device, this should be stored in EEPROM to survive power loss.
long lastCycleTime = 0;

void setup() {
Serial.begin(9600);
Wire.begin();

pinMode(EMPTY_PUMP_PIN, OUTPUT);
pinMode(REFILL_PUMP_PIN, OUTPUT);

// Make sure pumps are off at startup
digitalWrite(EMPTY_PUMP_PIN, HIGH); // Relays are often LOW-triggered, so HIGH is OFF
digitalWrite(REFILL_PUMP_PIN, HIGH);

if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}

// UNCOMMENT THE FOLLOWING LINE THE *FIRST* TIME YOU UPLOAD
// This sets the RTC to the date and time this sketch was compiled.
// After setting the time, comment it out and re-upload to prevent resetting the time on every reboot.
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

Serial.println("Mosquito Trap Initialized.");
// Get the current time to start our cycle timer
DateTime now = rtc.now();
lastCycleTime = now.unixtime();
Serial.print("Current Unix time: ");
Serial.println(lastCycleTime);
}

void loop() {
// Get the current time from the RTC
DateTime now = rtc.now();
long currentTime = now.unixtime();

Serial.print("Current Time: ");
Serial.print(now.timestamp(DateTime::TIMESTAMP_FULL));
Serial.print(", Seconds since last cycle: ");
Serial.println(currentTime - lastCycleTime);

// Check if 4 days (CYCLE_INTERVAL_SECONDS) have passed since the last cycle
if (currentTime - lastCycleTime >= CYCLE_INTERVAL_SECONDS) {
Serial.println("--- Cycle time reached! Starting water change. ---");
runWaterChangeCycle();
// Update the last cycle time to the current time
lastCycleTime = currentTime;
Serial.println("--- Water change complete. Timer reset. ---");
} else {
Serial.println("Not time yet. Waiting...");
}

// Wait for a while before checking again to conserve power.
// For ultra-low power, you would use deep sleep modes here.
delay(3600000); // Check once per hour (3600 * 1000 ms)
}

void runWaterChangeCycle() {
// Step 1: Turn on the emptying pump
Serial.println("Starting empty pump...");
digitalWrite(EMPTY_PUMP_PIN, LOW); // LOW turns the relay ON
delay(EMPTY_PUMP_DURATION_MS);

// Step 2: Turn off the emptying pump
digitalWrite(EMPTY_PUMP_PIN, HIGH); // HIGH turns the relay OFF
Serial.println("Empty pump finished.");
delay(5000); // Wait 5 seconds before refilling

// Step 3: Turn on the refilling pump
Serial.println("Starting refill pump...");
digitalWrite(REFILL_PUMP_PIN, LOW); // LOW turns the relay ON
delay(REFILL_PUMP_DURATION_MS);

// Step 4: Turn off the refilling pump
digitalWrite(REFILL_PUMP_PIN, HIGH); // HIGH turns the relay OFF
Serial.println("Refill pump finished.");
}

Start with a shorter test cycle (every few hours) before setting it to the full 4-day interval.


Set Up the Pool

20260313_130502 (1).jpg
  1. Any small container works: a bucket, a plant pot saucer, an old basin
  2. Place it in a shaded area near where you spend time outdoors (mosquitoes prefer shade)
  3. Recycled house water works great - mosquitoes aren't picky
  4. Put the electronics in a weatherproof enclosure nearby

Tips and Results

Tips:

  1. Waterproof your electronics. The pump and float switch can get wet, everything else should stay dry.
  2. Secure the float switch. If it shifts, it reads the wrong level.
  3. If your water supply runs out or the valve fails, the pool stays empty and mosquitoes just go elsewhere.

After about 3 weeks of running, the mosquito situation in our yard went from unbearable to barely noticeable. We can sit outside in the evening again.

I used Make-it to plan this project. It generated the initial parts list, wiring, and code which I then tweaked for my setup.