Arduino In-Range/Out-of-Range Alarm
by 20MinuteTech in Circuits > Arduino
1415 Views, 0 Favorites, 0 Comments
Arduino In-Range/Out-of-Range Alarm
A few years ago I was having dinner in a restaurant and for whatever reason I had my work bag with me. Typically I don't take it with me while dining out and I was telling myself often "don't forget it when you leave..." I placed my bag under the table, ate, left, ...and the bag was still under the table... It was only after arriving home I panicked and realized what happened, luckily, it was still there but I could have used a real reminder while I was in the area. That situation, along with some examples of Arduino alarms, is the idea behind this particular project, It could be used to alert you if something is left behind, an object or a person is out of range between 3 - 100 meters(ideally). If having an 'out-of-range' alarm isn't something you need but prefer to be notified when the transmitter is in range, a small change in the receiver sketch can be made(and is also provided).
This project consists of 2 Arduino controller boards, for my testing I used Arduino Nano boards. One Nano is setup as a transmitter while the other is a receiver. The transmitter does nothing but send out a repeated character signal "0". The 'Receiver_out_of_range' program for the other Arduino Nano is set to check for the received signal and flash an LED as confirmation. If a signal is not received after 3 attempts, the receiver will produce a repeated tone over a small speaker until either the signal is received again from the transmitter or unless the receiver is turned-off.
Supplies
(1) Arduino Nano compatible micro controller boards (Uno's, and other similar boards should work fine, one will be the transmitter and one will be the receiver).
(2) LED's, color of your choice
(2) Breadboards
(2) 220 Ohm resistors
(2) antennas - length dependent on your application
(1) mini speaker/piezo speaker
(1) 433 Mhz receiver
(1) 433 Mhz transmitter
Putting Together the Transmitter and Uploading the Transmitter Code
Above is the wiring diagram for the 433 Mhz transmitter module along with the ino file/sketch code.
#include <VirtualWire.h> const int ledPin = 9; char *data; void setup() { pinMode(ledPin,OUTPUT); vw_set_ptt_inverted(true); vw_set_tx_pin(12); vw_setup(4000); } void loop() { data="0"; vw_send((uint8_t *)data, strlen(data)); vw_wait_tx(); digitalWrite(ledPin,HIGH); delay(25); digitalWrite(ledPin,LOW); delay(500); }
Downloads
Putting Together the Receiver and Uploading the Receiver Code
Above is the wiring diagram for the 433 Mhz receiver module along with the ino file/sketch code.
#include <VirtualWire.h> const int buzzer = 8; //buzzer to arduino pin 8 void setup() { vw_set_ptt_inverted(true); // Required for DR3100 vw_set_rx_pin(12); vw_setup(4000); // Bits per sec Serial.begin(9600); pinMode(9, OUTPUT); vw_rx_start(); // Start the receiver PLL running } void loop() { int i = 0; int chk1 = 0; int chk4 = 0; uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; Serial.println(); if (vw_get_message(buf, &buflen)) // Non-blocking { for (i ; i < 2; i++ ) //loop to check for a received signal { if (buf[0] == '0') int chk1 = 1; else int chk1 = 0; chk4 = chk4 + chk1; } { delay(1000); { if (chk4 >= 1); //if at least 1 signal was received, flash LED digitalWrite(9, HIGH); delay(25); digitalWrite(9, LOW); } } } else // if no signal is received, produce audio tone { tone(buzzer, 1000); // Send 1KHz sound signal... delay(1000); // ...for 1 sec noTone(buzzer); // Stop sound... delay(1000); // ...for 1sec } }
Downloads
Testing the Receiver When the Transmitter Is Out of Range
Receiver to Notify When the Transmitter Is in Range
With a minor edit to the sketch, the receiver can notify when the transmitter is in range.
#include <VirtualWire.h> const int buzzer = 8; //buzzer to arduino pin 8 void setup() { vw_set_ptt_inverted(true); // Required for DR3100 vw_set_rx_pin(12); vw_setup(4000); // Bits per sec Serial.begin(9600); pinMode(9, OUTPUT); vw_rx_start(); // Start the receiver PLL running } void loop() { int i = 0; int chk1 = 0; int chk4 = 0; uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; Serial.println(); if (vw_get_message(buf, &buflen)) // Non-blocking { for (i ; i < 2; i++ ) //loop to check for a received signal { if (buf[0] == '0') int chk1 = 1; else int chk1 = 0; chk4 = chk4 + chk1; if (chk4 < 1); //check to see if any signal is received, play audio tone { tone(buzzer, 1000); // Send 1KHz sound signal... delay(1000); // ...for 1 sec noTone(buzzer); // Stop sound... delay(1000); // ...for 1sec } } } else { delay(1000); digitalWrite(9, HIGH); delay(25); digitalWrite(9, LOW); } }
Downloads
Range of the Transmitter/Receiver
The transmitter/receiver operate at a frequency of 433 MHz. Transmission Distance: 3 meters (without antenna) to 100 meters (maximum), so depending on whether or not you wish to use an antenna, you have some flexibility over the range. Experiment with the antenna lengths, 13" should be fine.
Both the transmitter and receiver module have a hole clearly marked where to solder an antenna.
More on Application
I haven't tested the project with a smaller Arduino controller, ideally a smaller transmitter could easily fit in a purse, work bag, luggage, baby stroller, etc,.
I didn't provide any information on enclosures because that would be dependent on the application you want to use it for and how much you wish to customize it. The LED's are not crucial to the transmitter/receiver operation, they can be omitted from the circuits/sketch code if desired.
Both the transmitter and receiver sketches can be easily modified. The additional 'in range' sketch was a simple change to have the receiver play an audio tone once the transmitter is in range of the receiver. Another application - if you set your computer to automatically power down at a certain time but you wanted to test it from a distance, the 'Out of range' receiver sketch could be used while the transmitter is powered via USB from a computer. Once the transmitter loses power from the shutoff computer, the receiver would lose the signal and produce the audio alert.
Thanks for viewing.
TMT