Doorbell using IR Reciever. Please help

Hello, I am Kristian a 16 year old student and could need some help with my school project. I am building a wireless doorbell and I am a little bit stuck right now. I have made a circuit which doesn't work as intended. I am using a IR Receiver and an IR Diode and to make a sender and receiver. The Arduino is used to make the doorbell play a melody and to register the signal from the IR Receiver. I am using this code to make a melody but my in my final code I added some few more lines.

The problem I have is that the doorbell plays the melody instantly without me pressing the button.

A little bit of help with my circuit and code would be very much appreciated.


Here is my code

#include "pitches.h"

int IrReceiver = A1;
int melody[ ] = {

NOTE_E4, NOTE_C4, NOTE_D4, NOTE_G3, 0, NOTE_G3, NOTE_D4, NOTE_E4, NOTE_C4,
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {

2, 2, 2, 2, 1, 2, 2, 2, 2,
};

void setup() {

// iterate over the notes of the melody:

for (int thisNote = 0; thisNote < 9; thisNote++) {

// to calculate the note duration, take one second divided by the note type.

//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

int noteDuration = 1000 / noteDurations[thisNote];

if (digitalRead(IrReceiver) == HIGH) {
  tone(8, melody[thisNote], noteDuration);
}
// to distinguish the notes, set a minimum time between them.

// the note's duration + 30% seems to work well:

int pauseBetweenNotes = noteDuration * 1.30;

delay(pauseBetweenNotes);

// stop the tone playing:

noTone(8);

}
}

void loop() {

// no need to repeat the melody.
}

Hi,
Welcome to the forum;
Apart from some minor code tag problems, you have all your code in void setup, it is only use once.
You need the working part of your code in the void loop part where it is continually run.
What IR sensor do you have and what IR LED?

Thanks.. TOM... :grinning: :+1: :coffee: :australia:

Hi,
Can I suggest you try this code;
You need to establish that you are receiving the IRLED signal, before attempting to make sounds.
This code will make the LED on the UNO turn ON when the IRLED is detected by the IR Receiver.

If you are using a simple IRLED and a three lead IRReceiver, you may be out of luck.
The three lead IRReceiver can only detect 38kHz IR signal.
So we need to know your IRLED type and IRReceiver.


int IrReceiverPin = A1;
int LEDPin = 13;
bool SigStatus = false;

void setup()
{
  pinMode(LEDPin, OUTPUT);
  pinMode(IrReceiverPin, INPUT_PULLUP);
}

void loop()
{
  SigStatus = digitalRead(IrReceiverPin);
  if ( SigStatus == HIGH)
  {
    digitalWrite(LEDPin, HIGH);
  }
  else
  {
    digitalWrite(LEDPin, LOW);
  }
}

The code should work if you have the correct combination of IR emitter and detector.

Tom... :grinning: :+1: :coffee: :australia:

Hi Tom,
Thank you for your help. I am not sure what kind of IR sensor and LED I am using but they look similar to these IR LED, IR Receiver.

I added the code that you wrote and it unfortunately didn't work i think this might be because i am using a three lead IRReceiver. If you have any idea of what i can change in the circuit to fix this it would be greatly appreciated

Thank you very much for your help!

Hi,
IR LED, OP165D Optek, 935Nm IR LED, 3mm (T-1) Through Hole package
Is just a simple IR emitter.
The IR REceiver is, Infrared Receiver VS1838B
The specs state that it is tuned to receive IR modulated at 38kHz.

Infrared Receiver VS1838B_1-1000x750
You need to be able to make your IRLED oscillate at 38kHz.
Here is a good link that may help you.
https://learn.sparkfun.com/tutorials/ir-communication/all
Tom... :grinning: :+1: :coffee: :australia:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.