Lucasd2002
Member
Hi, I'm trying to figure out why my project for my daughter's Valentine's day box isn't working. We used this project on YouTube. I *think* I wired/soldered everything correctly. The idea is a Valentine's box that looks like a dog house. When the IR sensor is tripped, the speaker is supposed to play a sound effect of a dog barking. I 3d printed a dog house and the plan was to hot glue the sensor near the slot at the top of the house to detect when a card/Valentine was inserted into the house. The only change from the YouTuber's code is the type of sound effect (the file name of the .wav file). I have Teensy loader and Arduino IDE, which appear to be communicating with the Teensy 4.1. This is the speaker, this is the board, and this is the IR sensor.
The green wire goes from pin 12 to the speaker and the yellow wire goes from pin 29 to the IR sensor. The sd card only has 1 file on it, DOG.WAV
Do I need to format the sd card in a certain way for the Teensy to read it? Any ideas for troubleshooting the system would be very much appreciated. I am not a programmer. How can I confirm that the Teensy has the code and/or is executing it?
When I connect to power (3x AA in series), the sensor light turns on. The sensor's also reacts when something is close (2nd light comes on) but there is no sound at the speaker. At times, I have heard static from the speaker. The Teensy will blink red if I touch the manual program button, so it appears to have power.
Here is the code:
The green wire goes from pin 12 to the speaker and the yellow wire goes from pin 29 to the IR sensor. The sd card only has 1 file on it, DOG.WAV
Do I need to format the sd card in a certain way for the Teensy to read it? Any ideas for troubleshooting the system would be very much appreciated. I am not a programmer. How can I confirm that the Teensy has the code and/or is executing it?
When I connect to power (3x AA in series), the sensor light turns on. The sensor's also reacts when something is close (2nd light comes on) but there is no sound at the speaker. At times, I have heard static from the speaker. The Teensy will blink red if I touch the manual program button, so it appears to have power.
Here is the code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1;
AudioMixer4 mixer1;
AudioOutputMQS MQS1;
AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord5(mixer1, 0, MQS1, 0);
AudioControlSGTL5000 sgtl5000_1;
// GUItool: end automatically generated code
int IR = 29;
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
void setup() {
pinMode(IR, INPUT);
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.6);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
mixer1.gain(0, 0.5);
mixer1.gain(1, 0.5);
delay(1000);
}
void loop() {
if (digitalRead(IR) == LOW) {
if (playSdWav1.isPlaying() == false) {
playSdWav1.play("DOG.WAV");
delay(10);
}
}
}
Last edited: