Alex Glow
Published

NERD ALERT! // Smart Doorbell with Arduino

We needed a doorbell for our office's freight elevator.

BeginnerFull instructions provided1 hour7,765
NERD ALERT! // Smart Doorbell with Arduino

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Grove starter kit plus for Intel Edison
Seeed Grove starter kit plus for Intel Edison
We just need the Buzzer and RGB Backlit LCD modules, as well as the Base Shield with Arduino headers.
×1
Big Red Dome Button
SparkFun Big Red Dome Button
Any ol' button will do.
×1

Story

Read more

Code

NERD ALERT doorbell code

C/C++
Cobbled together from a couple of Seeed Grove kit examples. Extremely annoying.
/*
  Cobbled together from Grove_Buzzer and Grove_RGB_Backlit_LCD examples
  in the Seeed Grove Kit repo:
  https://github.com/Seeed-Studio/Sketchbook_Starter_Kit_V2.0

  See the full project at https://www.hackster.io/glowascii/nerd-alert-e31fc2
*/

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;
const int buttonPin = 2;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status

int speakerPin = 3;          // Grove Buzzer connect to D3
int length = 2;             // the number of notes
char notes[] = "ca"; // a space represents a rest
int beats[] = { 4, 4 };
int tempo = 50;

const int colorR = 255;
const int colorG = 0;
const int colorB = 0;

void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
        digitalWrite(speakerPin, HIGH);
        delayMicroseconds(tone);
        digitalWrite(speakerPin, LOW);
        delayMicroseconds(tone);
    }
}

void playNote(char note, int duration) {
    char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
    int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

    // play the tone corresponding to the note name
    for (int i = 0; i < 8; i++) {
        if (names[i] == note) {
            playTone(tones[i], duration);
        }
    }
}

void setup() 
{
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT_PULLUP);
    
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    lcd.setRGB(0, 0, 0);

    pinMode(speakerPin, OUTPUT);
}

void loop() 
{
    buttonState = digitalRead(buttonPin);

    if (buttonState == LOW) {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.print("NERD ALERT! ");
      for (int i = 0; i < length; i++) {
        if (notes[i] == ' ')
          {
            delay(beats[i] * tempo); // rest
          }
        else
          {
            playNote(notes[i], beats[i] * tempo);
          }
        // pause between notes
        delay(tempo / 2);
        }
    } else {
      lcd.setRGB(0, 0, 0);
      lcd.clear();
    }
}

/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

Credits

Alex Glow

Alex Glow

5 projects • 1119 followers
The Hackster team's resident Hardware Nerd. I like robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments

Add projectSign up / Login