Hack a Mousetrap with a 433MHz RF Module
You can buy cheap 433MHz RF modules from Mouser and DigiKey. This article will show you how to use them with a PICAXE microcontroller to hack your own mousetraps.
Learn how to use 433MHz RF modules with a PICAXE microcontroller to control a pest invasion.
- A computer with LinAXEPad, PICAXE Editor 6 or PICAXE Programming Editor installed
- PICAXE 08m2
- PICAXE 20M2
- 433MHz RF module
- An LCD display
- Jumper wires
- Parts according to part list from Eagle
If you are new to the PICAXE microcontroller, I suggest you start with this article.
Let's make a mouse trap surveillance system! In Autumn, the rats and mice that had been active outside during the warmer months tend to come inside our houses and do a lot of expensive damage. Gnawing on wires makes a potential fire one of the worst-case scenarios. But rats and mice are tricky to catch, and setting up traps and checking them every day can be a boring and tedious task. Why not install some small RF transmitters on some traps? When a rat or mouse gets caught in a trap, the power is applied to the microcontroller. The microcontroller is programmed to send a number after 10 seconds. It will repeat that until the trap is emptied, or the battery is empty. In this setup, we use two traps and two transmitters. We will transmit one byte of data, and that is the trap number. You can increase the number of traps to an amount that is reasonable for you.
The transmitter is based on a SAW resonator. The datasheet says, "The R433A is a true one-port, surface-acoustic-wave (SAW) resonator in a low-profile metal TO-39 case. It provides reliable, fundamental-mode, quartz frequency stabilized i.e. in transmitters or local oscillators operating at 433.92MHz." When the transmitter is on, it is transmitting a solid carrier wave. This can make disturbance to other applications around that frequency, which is why we are controlling the power to the transmitter with the PICAXE and a transistor. The transmitter work from 5-12vDC. The more volts, the longer the distance. In our circuits the transmitter is connected to 12vDC. The data can be anything from ADC values, temperatures, text, and in our case, a number. The number represents the trap number.
The receiver is a simple regenerative receiver. It picks up the radio signal and puts it through two stages of amplification and filtering before sending it to the PICAXE. It receives all kinds of noises, so the first bytes may be corrupted. To fix that, we need to synchronize the receiver with the transmitter. To synchronize, we send 25 "U"s (those are capital U's). When the receiver gets that, it synchronizes, and is ready to receive the data. In the transmitter source code, we wait about 50 mS before we send the data.
The antenna for these modules is usually a wire with a solid conductor. To find the correct length of the antenna, you use this formula:
Speed of light is actually 299 792 458 m/s, but it is rounded up to 300 000 000. The first division gives us the length of the antenna in meters. That is for a full wave antenna, and it is 0.69m. We then divide that with 4, to get a quarter wave antenna. A quarter wave antenna for the 433MHz frequency is about 17cm long.
We need two different circuits: one circuit that sends data, and one circuit that receives data and displays the data on an LCD. Here are the two block diagrams.
We need to:
- have a way of programming the PICAXE -> The AXE027 box
- have a microcontroller to send some data -> The PICAXE 08m2
- have a 433 RF module to transmit the data -> The RF 433MHz
The receiver is a bit more complicated, and we need:
- a way to program the PICAXE -> The AXE027
- a module to receive the data and feed it to the PICAXE -> RF 433MHz
- a microcontroller to process the data and send it to an LCD
- an LCD to display the data
The LCD we are using is directly connected to the PICAXE, and we are using 6 pins: Enable, Register Select and D4-D7. Since we are connecting it this way, we need to make some "library" functions. The functions are init, wrins, wrchr.
The init function, initialize, is run immediately after the power is applied, and initializes the LCD, so it is ready to accept instructions.
The wrins function, write instructions, sends an instruction stored in b1 to the LCD.
The wrchr function, write character, sends a character stored in b1 to be "printed" on the LCD.
For a full explanation of this way of connecting an LCD to a PICAXE, please read page 36 and the following pages in the PICAXE manual "Microcontroller interfacing circuits"
To program the PICAXE, I am using the AXE027 Download cable, and I have made my own little breadboard/PCB adapter.
This plugs perfectly into a breadboard, and a female pin header on a PCB.
We need two different pieces of software: one that transmit data and one that receives data. Let's start with the transmitter. The code is well commented and does not need any further comments.
The source code for the transmitter and receiver is available in the link below.
In this article, we have made a rat trap surveillance system. The transmitters are all off until a rat or mice gets caught. When the trap closes, the two wires make contact and the "trap switch" is closed. Now the transmitting circuits is on and will transmit every 10 seconds. When the trap is emptied, the circuits is off.
The receiving circuit is always on, and is ready to receive information from the traps.
A challenge would be to rearrange the transmitting circuits so the LED is on C.4 and use C.2s ADC function to send temperature at the same time.
You could also add a temperature function using one of the available pins on the receiving circuit. Have fun!
Pictures and video
Transmitter on breadboard
Receiver on breadboard
The trap is loaded and ready to catch. It acts like a switch, and now it is open.
The trap has snapped, and the switch is closed. The microcontroller is on.
Give this project a try for yourself! Get the BOM.