▲ For more exciting content, please click on the blue text above and follow us!
Summer is here, and it’s the season of mosquitoes buzzing around. There is no difference between domestic and overseas in this regard.
The project we are introducing today is to modify and upgrade our weapon — the electric mosquito swatter, making our fight against mosquitoes a little more fun!
The upgraded electric mosquito swatter features include:
-
Add electronic devices to detect lethality -
Add a 4-digit counter to tally the “kills” -
Support USB charging -
Add a “kill sound” for a better experience
▼ Click to see the effect
Creative Ideas
The author’s idea is that the sound function can be easily added to the ATtiny using the DFPlayer module.
The score will be displayed using a 4-digit 7-segment display, and its onboard TM1637 can drive this display using only two wires (two IO pins of the ATtiny).
Since these electronic modules run at 5V, while the electric mosquito swatter typically uses two 1.5V batteries, we can conveniently upgrade the power part of the mosquito swatter to USB charging.
In other words, this “weapon upgrade” is made using relatively easy-to-find off-the-shelf electronic modules, with the only complex part being in signal computation, which is handled by the ATtiny through programming.
In the tutorial below, it is assumed that everyone has some understanding of Arduino and how to program; if not, you can first learn the basics of Arduino.
Before we start, a safety issue needs to be addressed:
The electric mosquito swatter uses high voltage (there are hundreds of volts on the mesh when the button is pressed), and even though the current is very low, be careful not to touch it or its internal circuits when connecting the battery.
Note: Do not let children play with this!
Materials
For this “ultimate” electric mosquito swatter, we need to prepare the following materials:
-
An electric mosquito swatter -
Digispark pro (with ATtiny, easily found online) -
DFPlayer (purchased from DFRobot) -
Resistors: 1Ω, 1kΩ -
8Ω speaker -
SD card (a small capacity card to store some sound files) -
Lithium-ion rechargeable battery: used battery -
Battery charger -
Potentiometer (I used a 1MΩ one; this is not very important, but a high value will limit the current consumption through the potentiometer) -
4-digit LED display with TM1637 (make sure it is a 4-digit display + TM1637, not just a 4-digit display) -
Capacitor: 470μF -
On/Off toggle switch -
Button -
Wires (reuse old telephone wires or network cables)
For tools, we need a soldering iron, a hot glue gun, and a 3D printer (some creativity to modify the handle of the swatter…)
Step 1: How to Upgrade Our Electric Mosquito Swatter?
If you don’t care how it works and just want to make the “ultimate” electric mosquito swatter, you can skip this step.
Resources explaining how the electric mosquito swatter works can be found online.
https://www.homemade-circuits.com/mosquito-swatter-bat-circuit/
It consists of an oscillating circuit and a circuit that boosts the voltage to hundreds of volts, plus the metal mesh connected to the swatter.
The first problem encountered is that there is nothing to hang the ATtiny on here (due to the 5V limitation of the ATtiny, the high voltage side cannot be used directly).
To solve this problem, the second idea is to measure the current consumption.
When an arc occurs on the metal mesh, and the mosquito is electrocuted, there must be some energy consumption, which should be readable by the ATtiny.
The best way to measure this consumption is to measure the voltage across a resistor, which the ATtiny can do.
Therefore, the method to count mosquitoes is to insert a small resistor between the battery and the electric mosquito swatter circuit and monitor the voltage across this resistor.
In addition, we use off-the-shelf electronic modules that have been made (each function has one: sound, display, charger, etc.), so overall, this is a relatively simple electronic project.
Step 2: Prepare the Circuit
The main components are:
-
ATtiny (Digispark pro) -
DFPlayer -
USB charger and battery -
Display -
Reset button -
On/Off switch -
Potentiometer for volume adjustment -
Two resistors and a capacitor
We should first lay them out to ensure they fit in the handle, and place the Digispark and DFPlayer closer together, leaving appropriate wire lengths for the other components based on their positions in the final module (i.e., the USB charger has a USB port that needs to be accessible for charging).
Step 3: Disassemble the Electric Mosquito Swatter
You can first check how much space is available for us to place the additional components.
You can also see if your swatter is the same as the one used in this tutorial.
The main difference to note is the “position” of the button on the swatter. In the picture, it is located between the battery’s+
and the circuit of the swatter. If that is the case, you are good to go (see photo).
In some swatters, this button is located between the ground-
and the circuit. In that case, the modifications and code below will not work. You will need to make some adjustments on both the hardware and software sides.
Step 4: Modify the Electric Mosquito Swatter
-
Make some space for the battery in the compartment designed for two AAA batteries (and reuse the battery connectors from the rechargeable battery).
Step 5: Build the Circuit and Solder the Components
In the previous step, the ground and VCC (5V) lines were not drawn for clarity, but all grounds need to be interconnected, and all VCCs need to be interconnected.
For VCC, the Digispark has three pins marked 5V, which are connected together and can be redistributed to other components. Do not use the VIN of the Digispark (VIN is a voltage input that needs to be above 6V; we do not use it, instead, we use the 5V output from the battery charger).
It is recommended to start with the Digispark:
-
Solder the Digispark to the DFPlayer -
Solder the Digispark to the display, button, and potentiometer -
Use heat shrink tubing to avoid contact and short circuits (e.g., on the resistor between the Digispark and DFPlayer)
Then, continue connecting the electric mosquito swatter circuit, battery charger, and switch:
-
Battery -
to charger Battery-
Input -
Battery +
to charger Battery+
Input -
1Ω resistor on the electric mosquito swatter circuit +
-
Capacitor on the electric mosquito swatter circuit’s +
and-
, pay attention to the polarity of the capacitor! -
Connect Digispark’s A12 pin to the button (the button has two terminals, one connects to the battery +
, A12 connects to the other) -
Use heat shrink tubing to avoid contact and short circuits (on the capacitor/resistor, etc.).
Step 6: Isolate the Display from the Electric Mosquito Swatter Circuit
It is suspected that this is due to electromagnetic interference from the high voltage changes affecting the display circuit and connections.
The fix is simple: stick some tape or aluminum foil (electromagnetic shielding) on the circuit, then tape it down.
Of course, do not place the aluminum foil directly on the circuit…
Step 7: Load Sounds onto the SD Card
The sounds played by the DFPlayer are stored on the SD card.
It’s simple: just insert the card and copy the selected sounds:
-
The sound played at startup (“Get ready for the next fight”) -
A sound for “monster killed” -
A sound for “level up” -
Some sound files that play randomly when a kill is detected
The DFPlayer will play sounds based on the “track number”.
It has been observed that files are not sorted by their names but by theirinode
number on the card (which can be viewed in Linux using ls -id
).
ls -id * | more
647 1_Monster_kill.mp3
648 2_mixkit-final-level-bonus-2061.wav
649 3_get_ready_to_the_newt_fight.mp3
650 mixkit-arcade-retro-scoring-counter-273.wav
651 mixkit-arcade-video-game-bonus-2044.wav
652 mixkit-arcade-video-game-scoring-presentation-274.wav
653 mixkit-game-bonus-reached-2065.wav
654 mixkit-game-experience-level-increased-2062.wav
655 mixkit-winning-an-extra-bonus-2060.wav
If you start with a new formatted card, the track number/inode order will be the order of copying the sound files (i.e., the first file copied on the card will be number 1).
In the code below, the selection of files/tracks is done throughsetTrack()
.
// 0 is random between tracks 4 to 9
// 1 is monster kill = track 1 (listed by inode on card (ls -id))
// 2 is level up
// 3 is power on
if (sound_type==0) setTrack(int(random(4,9))); //SD card contains 9 files
if (sound_type==1) setTrack(1); // monster kill
if (sound_type==2) setTrack(2); //level up
if (sound_type==3) setTrack(3); //power on
You can modify this part to match the actions ofsound_type
with the audio played.
The audio can be downloaded at the end of the article.
Step 8: Print a New Handle
If it is different, you may need to design one yourself.
However, some swatters have large handles with almost nothing inside, and you can directly install the additional circuit. Remember, we still need to find a position for the display and speaker.
The 3D printed files can be downloaded at the end of the article.
Step 9: Assemble It All Together
The speaker is also directly glued to the swatter.
Step 10: Where Are the Mosquitoes?
Again, if you don’t care how it works and just want to get your “ultimate” electric mosquito swatter player, you can skip this step… or come back to it later.
Once we have soldered all the components together, if we load a simple program onto the ATtiny that just does a simulated read (A12), we can check the raw data:
The raw data looks very noisy, and we cannot know where/when there is a mosquito (or something else, I didn’t wait for a mosquito to hit my swatter to debug the code 🙂 it hit the mesh of the electric mosquito swatter itself (see figure 1).
The average is a good way to clean up some noise, and my thought was to compare the last average with a “long-term” average, but the result was also a bit disappointing (see figure 2).
https://www.iese.fraunhofer.de/blog/change-point-detection/
This seems to be exactly what we are looking for; calculating the standard deviation of the signal should allow us to detect when a mosquito is killed (see the “Animation of change point detection via sliding window” section in the above link).
In the program, we calculate the square of the standard deviation, and we can see that when the button is pressed or released, it reaches a very high value (this is expected, the signal goes from 0V to nearly 5V), but once these stages are excluded, we can monitor this standard deviation and assume that if it reaches a high value, we have an interference in the circuit, which must be a mosquito that has been “killed” (figure 4)!
To be more precise, we added some more things:
-
A 470uF capacitor (it provides some more noise filtering and acts as a “power bank” when large current is needed); -
We have a two-level averaging mechanism (as seen in the code, we measured the voltage at pin A12 five times in its raw state, took the average, and then stored this average in the sliding window for standard deviation calculation).
Step 11: Load the Program onto the Digispark Pro
This is relatively simple, and you can program the ATtiny using the Arduino IDE.
Wiki:http://digistump.com/wiki/Digispark/tutorials/connectingpro
Some explanations of the code:
In thesetup()
function, we initialize the serial communication required for the DFPlayer, read the potentiometer value to adjust the volume (read only once during setup, meaning the swatter needs to be turned off/on to consider the volume adjustment).
For resetting the counter, if you want to reset the score to zero, you need to press the reset button, turn on the power of the swatter, and wait for the display to show “0”.
Then it will read the score stored in EEPROM.
It sets the brightness of the display (otherwise it will remain off).
In theloop()
function, we basically handle the average power of the swatterprocess_average()
and the square of the standard deviation, which tells us whether there is lethalityprocess_std_dev()
.
The relevant code can be downloaded at the end of the article.
Step 12: Update the Digispark Micronucleus (Optional)
The Digispark micronucleus is a piece of code responsible for “booting” the Digispark.
It checks whether we have uploaded a new program; if not, it runs the already loaded program.
The issue is that it needs to wait for 6 seconds, which is too long for us to want to start our weapon to swat mosquitoes.
However, the micronucleus has some variants with different checking mechanisms. If you follow these instructions to update the micronucleus (using the “recommended” configuration), the swatter will be ready in a second or two.
Reference:https://github.com/ArminJo/micronucleus-firmware
After updating the micronucleus firmware, reload your program.
Step 13: Troubleshooting
Hopefully, you won’t need to read this,
Here are some tips, just in case……
1. Not working much…… Check the wires and soldering;
2. If the electric mosquito swatter restarts by itself (you hear the startup sound but it doesn’t turn on/off), please charge the battery;
3. The electric mosquito swatter will automatically turn off after about 30 seconds.
-
Some USB charger circuits have an automatic standby mode (mine is like this, using the IP5306 chip); if the current consumption is below a certain amount (IP5306 is 45mA), it will enter standby mode. -
The first possible solution is to periodically press the swatter button…… like every 20 seconds. The circuit board (with IP5306) has a “key” function that can turn the power on or off, marked with “K” on the circuit board. The watchdog()
function suggested in the code above will keep the power working properly.
4. If the swatter’s detection ability is really poor or frequently detects incorrectly… some code adjustments may need to be made.
If you want to display some variables using the USB port, you must modify the code to use the DigiCDC library and remove SoftSerial (used for the 4-digit display). But more importantly, when doing this, we will be getting power from the USB port instead of the battery charger port, which makes a big difference… the quality of VCC has a significant impact on our calculated average and standard deviation…
In other words, any adjustments made while connected via USB may not work when running on battery.
A good way to obtain some small information is to use the display itself (i.e., display the last standard deviation when pressing the reset button).
Knowing this, you can try adjusting the following values in the code, which have a significant impact on our detection.
Number of samples for single read:
int samples=10;
Size of the sliding window for averaging:
int nbr_slot=15;
int value[16]; // array of (nbr_slot + 1)
Threshold for standard deviation:
int threshold=110;
int monster_threshold=250;
Step 14: Continue Improving the Electric Mosquito Swatter, Share Your Improvements
If you find a simpler way to modify the electric mosquito swatter or a design, feel free to share it!
Author: lmu34
Source: DFRobot Maker Community
Original address: www.instructables.com/Ultimate-Mosquito-Swatter-Mod-for-Gamer-Add-Kill-C
Recommended Reading

Add WeChat and reply “Join Group“
We will pull you into the technical exchange group!
Domestic chips | Automotive electronics | IoT | New energy | Power supply | Industry | Embedded…..
Reply with any content you want to search for in the public number to easily obtain relevant professional technical content feedback. Try it out!
If you want to see our articles regularly, you can go to our homepage, click the three small dots in the upper right corner, and click “Set as Favorite”.
Welcome to scan the code to follow


