Using IR Receiver to control Passive Buzzer notes

As described, I want to change the pitch of the buzzed when buttons are pressed on my remote. I have compiled and verified the code before uploading but I don't get any sound out of it. The IR receiver flashes like it should but no sound.

I didn't use the Tone.h library because it uses the same interrupts as IR Remote (or so I'm told). If you have any other suggestions to get around that I'm open to it. The pitchlist.h is just pitches.h with all the frequency numbers for each note with a different name. Didn't want mine to have the same name.

My setup is ground and power to the IR receiver and passive buzzer with pin 7 going to the IR and pin 9 to the buzzer.

I've attached a fritzing of the setup. My buzzer has a ground, power, and signal; couldn't find one like it in fritzing.

Thanks in advance!

#include <IRremote.h>
#include <TonePlayer.h>
#include "pitchlist.h"

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;

TonePlayer tone1(TCCR1A, TCCR1B, OCR1AH, OCR1AL, TCNT1H, TCNT1L); //pin 9
int duration = 200;
int notepin = 9;
 
// notes in the melody:
int melody[] = {
  NOTE_C5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6};

 
void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
}

void loop(){
  if (irrecv.decode(&results)){
 
        if (results.value == 0XFFFFFFFF)
          results.value = key_value;

        switch(results.value){

          case 0xB92:
          playNote(melody[0], duration);
          break;
          case 0x80B92:
          playNote(melody[1], duration);
          break;
          case 0x40B92:
          playNote(melody[2], duration);
          break;
          case 0xC0B92:
          playNote(melody[3], duration);
          break;
          case 0x20B92:
          playNote(melody[4], duration);
          break;
          case 0xA0B92:
          playNote(melody[5], duration);
          break;
          case 0x60B92:
          playNote(melody[6], duration);
          break;
          case 0xE0B92:
          playNote(melody[7], duration);
          break;
          case 0x10B92:
          playNote(melody[8], duration);
          break;
          case 0x90B92:
          playNote(melody[9], duration);
          break;

        }
        key_value = results.value;
        irrecv.resume(); 
  }
}
void playNote(int note, int time) {
  tone1.tone(note);
  delay(time);
  tone1.noTone();
}

A link to where your TonePlayer library came from would be useful. I only know of one and you don't use it like that.

Anyway start from basics, does the buzzer work at all? E.g. if you just put an unconditional playnote() in setup() does that make a sound?

Steve

Steve,

Ah! The buzzer worked using the normal Tone.h library but not with my function using TonePlayer. Hadn't thought of checking that. I also noticed that I did not set pin 9 as output. I double checked that with the buzzer using playNote and worked but not with IR.

Here is the link to the TonePlayer library Gammon Forum : Electronics : Microprocessors : Timers and counters.

If you don't feel like reading through and you have a way that you know works, great! I'm not at all attached to using Tone Player.

That got a bit confusing but I think you're saying that your playnote() function now plays notes as it should when called directly. Is that right?

If so then stick some debug prints in to see if you're receiving what you expect, perhaps

  if (irrecv.decode(&results)){ 
        Serial.print(Got value: ");
        Serial.println(results.value, HEX);

Can't think of much else to try

Steve