an open red flush door

Open Project Journey: Door Open Notification (Part 2) – Breadboard Prototype and Arduino Code

Remember to read Part 1 first before following.

Now that we have all the materials that were ordered from Amazon. The next step is to test our theory by using the breadboard and a simple Arduino code.

An overall flowchart of what we are going to code in Arduino.

Let us begin by wiring the Receiver and the Transmitter circuits on the breadboard.

After wiring the circuits as shown above, your breadboard should look something like this:



Now we move on to the fun part. Plug in your Arduino Uno into the PC and upload the following Arduino code. You can find the code in our Github account as well.


#include <VirtualWire.h>

const int rec_pin = 12;

void setup() {
  // put your setup code here, to run once:
  vw_setup(50);   // Bits per sec
  vw_rx_start();       // Start the receiver PLL running

void loop() {
  // put your main code here, to run repeatedly:
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
      // Message with a good checksum received, dump it.
      Serial.print("Message: ");
      if(strcmp((char*)buf,"0") == 0)
        Serial.println("Someone is knocking your door!");
      } else if(strcmp((char*)buf,"1") == 0)
        Serial.println("Someone just opened your door!");

Now keep the Arduino Receiver connected to your PC.

Moving on to the ATtiney85 MCU, you will need to plug it into your PC and set it up to use with your Arduino. Here is a great article that explains how to setup your ATtiney85 MCU to use with Arduino.

After setting up the ATtiney85 MCU on your Arduino, you will need to upload the following code to it.


// Includes needed
#include <VirtualWire.h>

// Pin Allocations
const int transmit_pin = 1;
const int hallsen_pin = 2;
const int piezo_pin = 2;
const int led_pin = 0;

// Package Messages
const char *knock_msg = "0";
const char *open_msg = "1";

// the setup routine runs once when you press reset:
void setup() {                
  // initialize IO and transmitter
  vw_setup(50); // Bits per sec

  // IO


// the loop routine runs over and over again forever:
void loop() {

  // Check piezo for any vibrations
  if(analogRead(piezo_pin) > 10)
    digitalWrite(led_pin,HIGH); // Indicate we are sending something
    vw_send((uint8_t *)knock_msg,sizeof(knock_msg));
  }else if(digitalRead(hallsen_pin) == HIGH)
    digitalWrite(led_pin,HIGH); // Indicate we are sending something
    vw_send((uint8_t *)open_msg,sizeof(open_msg));

After the upload is complete. Go ahead and unplug from your PC and transfer back to the breadboard. Now you can test your module by applying a 5 V to the voltage input pin. You will need to provide it from an outside source, I recommend using a USB cable to provide the 5 V or possibly a battery.

Open the serial monitor on the Arduino that is currently plugged on your PC.

When you knock on the surface, it should output a message on the terminal “Someone is knocking your door!”

When you open the door (i.e. remove the magnet that is close to the Hall Sensor) then a message should show up on the terminal “Someone just opened your door!”

Awesome. We have completed Part 2 of this project. We have another part coming up. For the next part of this project, we will attach a battery on the transmitter and attach on my door. Then setup the magnet and the buzzer. Then we will want to write a Python script to read the serial monitor and push out a notification to Windows letting us know of the two events. Part 3 coming soon!

Open Project Journey , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: