Table of Contents

Electronic Door Greeter

Introduction

A simple device implemented using an Arduino which plays a sound whenever a person enters a room. The device, which is to be positioned at the entrance of a room, utilizes infrared sensors to do this. The device only plays a sound when it detects a person entering.

General Description

The device uses 2 infrared sensors and an infrared emitter to detect movement. The sensors detect the infrared reflection reflecting off an object passing in front of them. The device is able to tell the direction of movement of the object depending on which infrared sensor gets triggered first. A short sound will be played by the use of a passive buzzer only when detecting an entry.

Block Scheme

untitled_diagram_1_.jpg

Required Components

Hardware Design

Software Design

Notes:

project.ino
const int buzzer=5;         //pin 5 is the buzzer output
const int ir_led=4;         //pin 4 is the ir_led output
const int push_button=3;    //pin 3 is the push_button input
volatile byte alarm = LOW;  //alarm state = on or off
 
int noteArray[] = {740, 587};
 
void setup(){
  Serial.begin(9600);
  pinMode(buzzer,OUTPUT);       //configure pin 5 as OUTPUT
  pinMode(ir_led, OUTPUT);      //configure pin 4 as OUTPUT
  //pinMode(push_button,INPUT); //configure pin 3 as INPUT
  attachInterrupt(digitalPinToInterrupt(push_button), on_off, RISING);
}
 
void loop(){
  if (alarm){
    int sensor0=analogRead(A0);
    int sensor1=analogRead(A1);
 
    Serial.println((String)"sensor0 = " + sensor0);
    Serial.println((String)"sensor1 = " + sensor1);
 
    if(sensor0 < 1000){
      buzzer_sound(true);
    } else if (sensor1 < 1000) {
      buzzer_sound(false);
    } 
 
  }
}
 
void on_off(){
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  // if interrupts come faster than 500ms, assume it's a bounce and ignore
  if (interrupt_time - last_interrupt_time > 500){
    alarm = !alarm;
    //digitalWrite(ir_led, alarm);
    tone(ir_led, 38000);
  }
  last_interrupt_time = interrupt_time;
}
 
void buzzer_sound(bool in_out){
  noTone(ir_led);
  delay(100);
  if(in_out){
    for(int i = 0; i < 2; i++){
        tone(buzzer, noteArray[i], 750);
        delay(500);
    }
  } else {
    for(int i = 1; i > -1; i--){
        tone(buzzer, noteArray[i], 750);
        delay(500);
    }
  }
  noTone(buzzer);
  tone(ir_led, 38000);
  delay(2500);
}

Video Demonstration

https://www.youtube.com/watch?v=9Z3g-g3RlNs

Conclusions

This project has taught me a lot about IR technology. For one, I've learned that working with IR was more complex than I anticipated. There's a lot of things that needs to be accounted for when choosing the proper IR component for your project, such as operating range, operating frequency, whether the IR sensor is sensitive to continuous rays or pulses, how the sensor handles noise etc.

Journal

2022/05/27 - Completed Milestone 2

Resources

https://forum.arduino.cc/t/how-to-create-a-38-khz-pulse-with-arduino-using-timer-or-pwm/100217/ https://docs.arduino.cc/