Introduction: Ultimate Mosquito Swatter Mod for Gamer: Add Kill Counter, Sound, Rechargeable Battery.
Where I live, from spring to autumn we have to compete for territory against tiger mosquito.
Local stores offer a impressive list of anti mosquito devices, candles, including sophisticated traps sold a few hundred euros, I even found one sold 2000€ - this give you an idea of how desperate people are to get rid of those invaders.
One of my favorite weapon to fight against mosquito is this cheap electric swatter, but to make this fight even more rewarding I thought I should upgrade my weapon.
In this instructable, I will show and explain how to hack an electric swatter to :
- add electronic to detect kills.
- add a 4 digit counter.
- make it usb rechargeable.
- add sound for a better experience.
My thought was that when an insect hits the wire mesh of the swatter and the electric arc occurs, there must be some electric variation on the swatter circuit. If I could find a place in the circuit that is readable by an arduino or attiny (that is between 0 and 5 volts) it would then be easy to count and display a score and to play some sound.
We can easily add sound/music capabilities to an attiny with a dfplayer module
Score would be displayed with a 4 digits 7 segment display which as an onboard tm1637 which allows to drive the display with only two wires (two IO pins of the attiny)
Because those electronic modules run at 5V and the swatter are usually running from 2 x 1.5 v batteries, I also upgraded the power part of the swatter with a usb rechargeable battery.
In other words, the upgrade is made with off-the-shelf electronic modules that are easily found, it is simple electronic, the only "complexity" is in the signal computation, but this is handled by the attiny through programming.
In this instructable I assume you have some knowledge of ardiuno and how it is programmed, if not you can find good tutorials on arduino site or explore arduino project on instructables.com
One more thing before starting, safety: electric swatter use high voltage (hundred of volts on the mesh when button is pressed) even if current is very low, be carrefull not to touch it or its internal circuit when battery is connected.
The Sticker says Caution keep away from children (and yourself)
Supplies
For this Ultimate Mosquito Swatter Mod for Gamer you will need :
- an electric mosquito swatter (there are several type of swatter circuit, this instructable and the program I suggest is adapted to one type of swatter, check the step 'Open the swatter' to verify your swatter matches what I use)
- digispark pro (convenient board with attiny, easily found online)
- dfplayer (easily found online)
- resistors: 1Ω, 1kΩ
- 8 Ω speakers
- sd card (a small capacity should be enough to hold a few sound files)
- li-ion rechargeable battery : salvage battery
- battery charger, something like this one
- potentiometer (I used a 1MΩ, it is not very important but a high value will limit current consumption through the potentiometer)
- Four digits LED display with tm1637 (make sure it is a 4 digit display + the TM1637 and not a 4 digit display only)
- capacitor : 470 µF
- on/off toggle switch
- push button
- wires (reuse old phone or ethernet cables)
For the tooling part, you will need a soldering iron, a hot glue gun and a 3D printer (or some creativity to modify the swatter handle...)
Step 1: How an Electric Swatter Works, How Can We Upgrade It?
Well, if you do not care about the way it work and just want your Ultimate Mosquito Swatter for Gamer, you can skip this step...
Resources explaining how an electric swatter works can be found on internet. (ie https://www.homemade-circuits.com/mosquito-swatter-bat-circuit/)
So it is oscillating circuit and a circuit to boost voltage up to hundreds of volts connected to the racket wire mesh.
Unfortunately, I could not find much to hook a attiny here (high voltage side is not directly usable due to the 5 volt limit of the attiny).
To work around this, my second thought was to measure current consumption. When an arc occurs on the net and the mosquito is fried, there must be some energy consumption that should be readable by an attiny.
The best way to measure this energy is to measure current consumption, and the easiest way to measure current is to measure voltage across a resistor, which an attiny can do.
So the only trick to count mosquitos is to insert a small resistor between the battery and the swatter circuit and monitor voltage across this resistor.
Beside that, I used already made electronic modules (one for each function : the sound, the display, the charger etc) so its is a fairly simple electronic project.
Step 2: Plan for the Circuit
The main components added are
- attiny (digispark pro)
- dfplayer
- USB charger and the battery
- display
- reset button
- on/off switch
- potentiometer for volume adjustment
- two resistors and a capacitor
We need to lay them out so they can fit in the handle, digispark and dfplayer can be kept close from each other, allow the right wire length for this other component based on where they will be located in the final mod (ie the usb charger has a usb port onboard that will need to be accessible for recharge)
see images and photos
Step 3: Open the Swatter
Remove the battery and open the swatter (it should be only a few screws).
It allows you to see how much room you have to place the add-on components but also check if your swatter matches what I use in this instructable...
The major difference to care about it the "location" of the push botton of the swatter. On mine, it is located between the + of the battery and the swatter circuit. If this is the case you are good to go (see photo).
On some swatter, this push button is located between the ground (-) and the circuit. In this case my modification and code will not work. I am pretty sure I can make it work with such swatter but it will need some adjustment on the hardware and software side. I will update this intructable once I have worked on this second type of swatter.
Step 4: Modify the Swatter
In this step we :
- make some room for the battery in the compartment that was design for two AAA battery (and reuse the battery connector for the rechargeable battery)
Step 5: Build the Circuit, Solder All Components
Now that we know what is connected where, we can proceed with the soldering.
Layout all components based on their final location in order to estimate the various wires lenght.
In the previous step, for clarity purpose I did not draw the ground and VCC (5V) wires, but all ground need to be interconnected, all VCC need to be interconnected.
For VCC, the digispark has 3 pin labeled 5V, they are linked together and can be used to redispatch to other components. Do not use the VIN of the digispark (VIN is a voltage input that need to be above 6V, we do not use that but rather the 5V ouptut from the battery charger).
I suggest to start with the digispark :
- solder the digispark to the dfplayer.
- the digispark to the display, push button and potentiometer.
- use heat-shrink tubing to avoid contact and short cuts (like for the resistor between the digispark and the dfplayer).
Then, proceed with the swatter circuit, battery chager, on/off switch:
- battery - to charger battery - input
- battery + to charger battery + input
- 1 ohm resistor on the swatter circuit (+)
- the capacitor on (+) and (-) of the swatter circuit, watch the capacitor polarity !
- pin A12 of digispark to the push button (the push button has two connectors, one connected to the battery +, A12 goes to the other one)
- use heat-shrink tubing to avoid contact and short cuts (on the capacitor, on the resistor, etc )
See pictures for the progression...
Step 6: Isolate the Display From the Swatter Circuit
During my firsts tests I had display issues...the display would turn off or go crazy when a mosquito hit the mesh of the swatter.
I suspect it was due to electronic disturbance generated by the high voltage variation impacting the display circuit and connections.
The fix is simple, some tape on the circuit, aluminum foil (electromagnetic shield) and tape again.
Of course, do not place the aluminum foil directly on the circuit or it will create shortcuts...
Step 7: Load Sound on SD Card
Sound played by the dfplayer are stored on an SD card.
I kept it simple, formated the card and copy my selected sounds
this is
- a sound played at power on ("get ready to the next fight")
- a "monster killed" sound
- a "level up" sound
- some sound files played randomly when a kill is detected.
Once on the card dfplayer will play sounds based on a "track number".
I could not find a clear description of the link between the dfplayer track number and the files on the SD card.
Based on observation, I suspect files are not sorted based on their name but rather with their inode number on the card (which can be seen with "ls -id" on linux)
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
I think that if you start from a freshly formated card, the sequence of track number / inode will be the order of the copy of the sound files (ie first file copied on the card will have tranck number 1)
In my suggested code, the file/track selection is done with setTrack :
// 0 is random betwen 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
So you could modify that part to have a match between the action (sound_type) and the track played.
Attachments
1_Monster_kill.mp3
2_mixkit-final-level-bonus-2061.wav
3_get_ready_to_the_newt_fight.mp3
mixkit-arcade-retro-scoring-counter-273.wav
mixkit-arcade-video-game-bonus-2044.wav
mixkit-arcade-video-game-scoring-presentation-274.wav
mixkit-game-bonus-reached-2065.wav
mixkit-game-experience-level-increased-2062.wav
mixkit-winning-an-extra-bonus-2060.wav
Step 8: Print a New Handle
In case you are modifying the same swatter as used here, you could directly print my handle design.
If not you will have to design your own...
However some swatter have quite big handles with almost nothing in it, it might be possible to fit the add on circuit in without printing anything. You still need to find a place for the display and speaker.
Step 9: Assemble Everything
I used a hot glue gun to secure the parts in their final location.
The speaker is also glued directly on the swatter.
Step 10: Where Is the Mosquito ? Math and Stats to the Rescue
Once again, if you do not care about the way it works and just want your Ultimate Mosquito Swatter for Gamer, you can skip this step...and maybe come back later.
Once all components are soldered together if you load a simple program on the attiny that only do a analogRead(A12) and look at the raw data... it is a bit disappointing, raw data looks very noisy and you cannot tell where/when on the graph a mosquito (or something else, I did not wait for mosquitos to hit my racket to debug the code :) ) hit the mesh of the racket (see figure 1).
Averaging if a good way to cleanup part of the noise, and my idea was to compare the last average to a "long term" average, but well it was a bit disappointing too (see figure 2).
Next step is to read and learn what smarter people do...https://www.iese.fraunhofer.de/blog/change-point-detection/
This looks exactly what I am looking for, the calculation of the standard deviation of my signal should allow me the detect those kills (see the animation "Animation of change point detection via sliding window " on the link above).
Applied to our setup it give the following results (figure 3). In my program I calculate the square of the standard deviation, we can see it reaches very high values when I push or release the racket button (this is expected, the signal goes from 0V to close to 5V), but once those phases are excluded, I can monitor this standard deviation and assume that if it goes to some high values, we have a disturbance in the circuit which must be a mosquito kill (figure 4) !
Now that we know how to find a kill, the rest is easy (play a sound, increase score).
To be honest and more accurate, some more things were added :
- a 470 uF capacitor (which by it self provide some more noise filtering and serve as some sort of power bank when high current is needed)
- we have a two level averaging mechanism (you will see in the code that I measure 5 times in a raw the voltage on pin A12, average it and then store this averaged value for the sliding window of the standard deviation calculation)
Step 11: Load Program on the Digispark Pro
This is pretty straighforward, the attiny can be programmed using the arduino IDE
instructions : http://digistump.com/wiki/digispark/tutorials/connectingpro
Some explanations on the code I am suggesting:
in the setup() funtion, we initialize the serial communication needed for the dfplayer, read the potentionmeter value to adjust the volume (it is read only once at setup time to avoid using cycles for this, which means the swatter woud need to be power off /on to take into account a volume adjustment).
Samething for the counter reset, I you want to reset score to zero, you need to push the reset button, power on the swatter and wait for the display to show "0".
It then read the score stored in EEPROM.
It sets Brightness of the display (otherwise it remains off).
In the loop() function we basically process the average of the swatter power process_average() and the square of the standard deviation which tells us if we have a kill or not (process_std_dev() )
Attachments
Step 12: Update the Digispark Micronucleus (optionnal)
The digispark micronucleus is the piece of code in charge of "starting" the digispark.
It checks if we are trying to upload a new program and if not start the program already loaded.
The problem is that it waits for 6 seconds for this check, which is fairly long when your are waiting for your swatter to be ready for a hunt...
Thanksfully there are some variants of the micronucleus with a different checking mechanism. If you update your micronucleus following those instructions (use the "recommended" config), the swatter will be ready after one or two seconds only.
Instructions : https://github.com/ArminJo/micronucleus-firmware
Reload your program after updating the micronucleus firmware.
Step 13: Troubleshooting...
Hopefully you will not have to read this but...some tips just in case...
- not much work...check wire and solder
- if the swatter restarts by itself (you hear the starting sound but have not switched on/off), recharge the battery
- the swatter shutoff by itself after about 30 seconds.
- some USB charger circuit have an automatic standby mode (that was the case for mine which is using chip IP5306) and will go in standy mode if less than some amount (45mA for the IP5306) of current is consumed.
- the first workaround possible is to press the swatter button on a regular basis...like every 20sec. this would maintain the power up
- the board (with IP5306) has a "key" feature allowing to power on or off. it is labeled "K" on the board. Solder this to pin 10 of the digispark. the watchdog() function on the code I suggested will keep the power up.
- if the swatter is really bad at detecting or wrongly detect...well you may have to do some code adjustment...
I spent hours tuning this device and its code. The major difficulty is to monitor what is going on...
If you want to use the USB port to display some variables, you have to modify the code in order to use the DigiCDC library and remove the SoftSerial (which is used for the 4 digit display). But more over when doing so, you get power from the USB port and not the battery charger port and this makes a big difference...The quality of VCC impacts a lot our calculated average and standard deviation...
In other words any tuning performed while connected on the USB will probably not work when running from battery...
One way to get some little information is to use the display itself (ie display the last standard deviation when the reset button is pressed)
Knowing that, you can try to adjust the following values in the code which impact (a lot) our detections:
the number of samples taken for a single read :
int samples=10;
The size of the average sliding window :
int nbr_slot=15; int value[16]; // array of (nbr_slot + 1)
The standard deviation thresholds :
int threshold=110; int monster_threshold=250;
Step 14: Improve the Swatter, Share Your Improvements
Things could be done differently of course, If you improve the swatter, find simpler way to do it, design a handle for other models...share your work...

Second Prize in the
Electronics Contest
39 Comments
2 months ago
I finalized mine and it works fine. I lowered many of the thresholds you proposed to make it work properly. For the sound files, you need to : format your SD card (low level), create a folder named 01, copy your sounds inside this folder. Sounds must be named 001, 002... 009. And that's it! Thanks again for this interesting little mod, which makes the whole family addict to a new activity, the MosquitoHunt !
Reply 2 months ago
Great ! Thanks for sharing.
Have fun :)
Question 6 months ago on Step 14
Bonjour IMU34, Bravo pour cette réalisation, j'adore ! J'ai un souci de compilation du soft à téléverser dans le digispark pro :
mosquito_std_dev_instructables.ino:3:20: fatal error: EEPROM.h: No such file or directory
#include <EEPROM.h>
^
compilation terminated.
exit status 1
Compilation error: EEPROM.h: No such file or directory
J'ai réinstallé complètement mon IDE. Je peux téléverser un autre programme dans le Digispark Pro, ça fonctionne.
EEPROM.h devrait faire partie des bibliothèques standard mais ça ne semble pas être le cas. Où la trouver ?
Cette petite machine sera bien utile à Palavas l'été prochain... Merci d'avance !
Answer 5 months ago
I made it. Looks like it works ! I'm waiting impatientely for my first flying target, but it does initialize, beeps and resets as expected. At least a good start... For some reason, I had to change the CLK and DIO pins to pins 4 and 5 respectively, and of course change the setup in the software. It was impossible to display anything with the original setup... Strange... Another question. 1 ohm resistors are hard to find. Would 10 ohm work the same ? Thanks !
Reply 5 months ago
:)
well the clk and dio swap could be my mistake, I may have uploaded a sketch not matching the circuit I draw in the instructable, thanks for reporting that.
For the resistor, I have tested 1 ohm only. I think 10 ohm could be problematic, for the same current we would have a x10 drop of voltage. I imagine it would mainly affect time for the swatter circuit to "recharge" after a discharge. But maybe it is okay....it is worth trying.
You can test it with a humidified blade of glass....it simulates well a mosquito :)
If it does not work well with 10 ohm, you can still reduce the resistor by placing a few 10ohm resistors in parallel. R=10/n for n resistors of 10 ohm in parallel, so with 3 or 4 it would significantly lower the resulting resistor.
After the last step, or on the top menu bar on the right, there is a "I Made It" button...
Reply 5 months ago
Thanks !
- Your drawing and sketch are matching. It is not the source of the problem. Out of curiosity, I tried the test sketch of the TM1637 library (https://github.com/avishorp/TM1637), altering the CLK and DIO settings to CLK 7 and DIO 6, as per your drawing. It does not work either. That's why I shifted to CLK 4 and DIO 5, which work with both the test and the operational sketches.
- As for the resistors, I'll try. I thought of the parallel option, of course, but no more space on my veroboard, I'll try to find some space somewhere else. I'm lazy enough not to be willing to rebuild everything from scratch for a resistor...
- A humidified blade of glass... Who could have thought of that? Good trick!
- When completed, I won't forget to click on the "I made it" button! Good day to you!
Reply 5 months ago
Ok, 10 ohms seem to be on the high side. I tried 5 and 2.5 ohms, both seem to work. Thanks !
Answer 6 months ago
Hello Denis, nice to hear that some fighting gear is being setup close by in Palavas !
Right, EEPROM.h is supposed to be a "built-in" library now but maybe it is not in the library path when the digispark board is selected.
Anyway you can install it from the zip file (instruction here : https://docs.arduino.cc/software/ide-v1/tutorials/...
and you can find the zip file link in this forum https://forum.arduino.cc/t/official-eeprom-library...
or the direct link :
https://forum.arduino.cc/uploads/short-url/vbJyT55...
Reply 6 months ago
Thank you so much. I naively thought that every built-in library from the IDE was readily available for all boards but it is not the case... Thanks for your help, it works now! Starting the integration in the handle! Congrats again, I just love that stuff!
1 year ago
Was reading your adventures in kill-detection. It looks like you're using the ADC to detect changes in the supply current using the 1 ohm resistor as a shunt. Since contact with a mosquito, your finger etc. discharges the capacitor on the high-voltage side instantly, there will be a massive negative (or positive) voltage spike on the 'hot' side of the output capacitor which you could detect with a digital input via a high-voltage ceramic capacitor (and 2 protection diodes to clamp the signal within -0.6 to +5.6Volts). Any discharge however small would likely generate a full-scale signal and, if you filtered the signal with another capacitor, the length of the pulse would indicate the strength of discharge, saving you some math and a 10-turn pot..
Reply 5 months ago
The idea looks promising indeed. Did you provide any schematics ? Thanks !
Reply 1 year ago
Thanks for the lead ! looks promising.
Tip 1 year ago
Haha, excellent!
I came across this video to transform an old-school calculator into a counter. Perhaps that's another way to do it (no sounds then though...) https://www.youtube.com/watch?v=s3lSUfAhe6M
1 year ago
Great idea to make a game out of it! Make a few of these and set the youngsters loose in the yard for an afternoon of exhausting play!
Oh. And another detector idea that would eliminate any mod to the swatter circut would be to listen for the arc using and ultrasonic sensor. The arc should give off a very big spike that could eaisly be detected.
Reply 1 year ago
Good Idea, btw I was surprised by how loud the spikes are on the video. I mean much louder than what my ears sensed.
Reply 1 year ago
Yes! Electronic sensors, like thoes used in recording devices, are quite sensative to ultrasonic as well as IR.
1 year ago
Also modified one - with UV LED's and a computer fan to suck in the 'suckers'
Great fun, but the fan was way to noisy!!
Great project!
1 year ago
Man, that's hilarious!! I think you need a light-sabre mode to complete your journey to the dark side...
Reply 1 year ago
I have been looking for some light-sabre ignition sound to play at power on...but I could not find anything that would play correctly on the small speaker.
Reply 1 year ago
You can use the following circuit. https://efcomputer.net.au/blog/light-saber-build-p...
Lightsaber effect can be found here
https://efcomputer.net.au/blog/product/lightsaber-...