Guitar Amplifier & Door Alarm Guidance

Hi All,

I'm a high school teacher working with some science students. We are working on a project that is both a door alarm and guitar amplifier! It lives in a shoe-box sized tupperware and uses an arduino nano, an 11 V battery (or 12V DC wall plug) LM386 Amplifier circuit, magnetic door switch (wired to normally open), and a toggle switch in series with the magnet switch so I can trouble-shoot and set it up without it blaring at us. The speaker is a Samsung 8Ω, 10W.

/*Door Alarm
*/

// ----- boolean variables
    boolean sirenOn = false;
  
// ----- Constant variables
  const int SwitchIn = 12;
  const int speakerPin = 5;
  const int heartbeatPin = 13;
 
// ----- interger variables
  int val = 0;
  int totalSirenTime = 1000; // one second sweep time
  int startFreq = 500;
  int stopFreq = 8000;
  int stepSize = 100; // takes 100 Hz steps
  int currentFreq;

// ----- Functions
  void playSiren(){
    static boolean midWhoop = false;
    static unsigned long lastStep = millis();
    long elapsedTime = millis() - lastStep;

    int numberOfSteps = (stopFreq-startFreq)/stepSize;
    int timePerStep = totalSirenTime/numberOfSteps;

    if(!midWhoop){      // new round, reset the variables
    lastStep = millis();
    currentFreq = startFreq;
    midWhoop = true;

    } if(elapsedTime >= timePerStep){
        currentFreq += stepSize;
        lastStep = millis();
        if(currentFreq > stopFreq){
          stopSiren();
        midWhoop = false;
        return;
        }
      }
      tone(speakerPin, currentFreq);
    }

  void startSiren(){
    sirenOn = true;
    }

  void stopSiren(){
    sirenOn = false;
    noTone(speakerPin);
    }

  void heartbeat(){
    static unsigned long lastBlink = millis();
    unsigned long elapsedTime = millis() - lastBlink;
    if (elapsedTime >= 250){   //0.5Hz blinking light
      digitalWrite(heartbeatPin, !digitalRead(heartbeatPin));
      lastBlink = millis();
      }
    }

void setup() {
    Serial.begin(9600);
    Serial.println("Door_Alarm_Code.ino");
    
    pinMode(SwitchIn, INPUT);
    pinMode(speakerPin, OUTPUT);
    pinMode(heartbeatPin, OUTPUT);
    Serial.print("Ready");
}

void loop() {
    
    val = digitalRead(SwitchIn);

    if((digitalRead(SwitchIn) == HIGH) && !sirenOn){
      startSiren();
    }

    if(sirenOn) {
      playSiren();
    }

    heartbeat();
}

(sorry for the confusing amplifier breakout, but its what I could make using cloud-based freeware) . Everything works great!

We tried hooking the amplifier inputs up to a guitar cable (bypassing the arduino) and it sounded pretty good, so we thought we'd make a hardwired option, but when we put the new wires in... things went wrong, we either lost the guitar input (image 2 below) or lost volume control (image 3 below) depending how we connected the guitar wires. I think the best options are to create either a physical switch to mechanically select the input that will be sent to the amplifier, or a pushbutton and state-change in the arduino program to select the input to be sent to the amplifier.

We are leaning toward the second option because then we have the future option to program in effects such as reverb or audio delays, using the arduino like a pedalboard.

Any suggestions are welcome!
Thanks!

Image 2: lost guitar input

Image 3: Lost volume control

Hi, @vogtm2.

A strange combination of features.

Instead of LM386, I recommend a modern class D amplifier, for example from the PAM (8403, 8406, 8610) or TPA (3110, 3113, 3116) series, which are of good quality and high efficiency. As for guitar effects, I think this link is worth a look.

1 Like

Thank you both for the learning resources. We'll check those out and post an update soon.

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