Create a remote snail mail alarm that signals whenever a snail mail is arriving at your mailbox.

What will I learn?

You will learn how to read analog values from a connected sensor and perform some action based on the value read from the sensor. You also learn about the LDR resistor and laser usage in Arduino projects.
Furthermore you will learn how to send and receive messages via the RF modules.
Finally, you will learn about how to install external libraries to further enhance the possibilities with your Arduino.

Prerequisites

A Computer with a configured Arduino IDE tested and working. If you don’t know how to get the basic set up working, check out my guide for Getting started (1/5)

This instruction relies on the VirtualWire library, so this must be installed before uploading the code to Arduino. You can download the library from here:

To install it, extract the library zip file (VirtualWire.zip) to the library directory of where you installed the Arduino IDE. After this, you must restart all open Arduino IDE editors.

Now you can upload code to the Arduino utilizing the VirtualWire library.

Important notes

  • Respect minus and plus, otherwise you may damage the components.
  • The threshold value of 500 should be modified for whatever environment you are working in. If you are in a very lit environment, you may need to increase the value.

What you need

  • Breadboard
  • Dupont wires & connection wires
  • CP2102
  • 2x Arduino Pro Mini
  • LDR GL5539 50-90K light resistor
  • 1 KOhm resistor
  • 10 KOhm resistor
  • RF module receiver (RX)
  • RF module transmitter (TX)

This is an image of the RX (to the left) and the TX module (to the right)

screenshot-from-2017-01-07-20-11-44                  screenshot-from-2017-01-07-20-11-38

Connecting instructions for the Transmitter (TX)

  • Arduino VCC → TX module VCC
  • Arduino GND → TX module GND
  • Arduino D12 → TX module DATA (on some modules marked ADAT)
  • Arduino VCC → LDR resistor first pin
  • Arduino A0 → LDR resistor second pin
  • LDR resistor second pin → 10KOhm resistor and then to GND

See below for an image of how the transmitter could look:

screenshot-from-2017-01-07-20-12-17

 

Connecting instructions for the Receiver (RX)

  • Arduino VCC → RX module VCC
  • Arduino GND → RX module GND
  • Arduino D12 → RX module DATA 1
  • Arduino D9 -> Positive pin of Red LED
  • LED negative pin -> 1KOhm resistor and then to GND

See below for an image of how the receiver could look:

screenshot-from-2017-01-07-20-12-08

 

Fritzing

snail-mail-alarm_bb

Transmitter code (TX)

/**
* This is the transmitter of the Snail mail alarm. The transmitter send out a message to
* the receiver when the light sensor senses that the mailbox have been opened
* and the receiver reads this and turns on an LED.
*
* Connecting instructions:
* – Arduino VCC → TX module VCC
* – Arduino GND → TX module GND
* – Arduino D12 → TX module DATA (in some modules incorrectly marked ADAT)
* – Arduino VCC → LDR resistor first pin
* – Arduino A0 → LDR resistor second pin
* – LDR resistor second pin → 10KOhm resistor and then to GND
*
* Author: Jakob Maaløe
* https://wackydeveloper.wordpress.com
*/
#include

int lightSensor = A0; // Light sensor input
int transmitPin = 12;

int internalLed = 13;

char *controller;

int value; // Value for reading from the light sensor

void setup() {
Serial.begin(115200);

pinMode(internalLed, OUTPUT);

pinMode(lightSensor, INPUT);

vw_set_ptt_inverted(true);
vw_set_tx_pin(transmitPin);

vw_setup(4000);// speed of data transfer Kbps
}

void loop() {
value = analogRead(lightSensor); // reads the sensor value

Serial.print(“Sensor value: “);
Serial.println(value);

if (value > 500) { // If the value is above the threshold, send an alarm

controller = “MAIL”; // Message to send

Serial.println(“Sending snail-mail alarm!”);
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone

// Turn internal LED on to show that we are sending
digitalWrite(internalLed, 1);
}

delay(2000);

digitalWrite(internalLed, 0); // Turn off the LED again!
}

Receiver code (RX)

/**
* This is the receiver of the Snail mail alarm. The transmitter send out a message to
* the receiver when the light sensor senses that the mailbox have been opened
* and the receiver reads this and turns on an LED.
*
* Connecting instructions:
* - Arduino VCC → RX module VCC
* - Arduino GND → RX module GND
* - Arduino D12 → RX module DATA 1
* - Arduino D9 -> Positive pin of Red LED
* - LED negative pin -> 1KOhm resistor and then to GND
*
* Author: Jakob Maaløe
* https://wackydeveloper.wordpress.com
*/

#include 

int transmitPin = 12;
int internalLed = 13;
int mailLed = 9;

void setup() {
Serial.begin(115200);

pinMode(internalLed, OUTPUT);
pinMode(mailLed, OUTPUT);

vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(transmitPin);
vw_setup(4000); // Bits per sec

vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
String str = (char*)buf;
delay(100);
Serial.print("Incoming message: ");
Serial.println(str);

if (str.startsWith("MAIL")) {
Serial.println("You've got mail!");

digitalWrite(mailLed, HIGH); // Turn on the Message light!

delay(1000);

digitalWrite(mailLed, LOW); // Turn off the Message light!
}

}
}

Next steps

Add a buzzer or some other alarm to signal that mail has arrived. You can also continue to the next example project, the LCD Display (1602 w. I2C module).

Advertisements