Problem on musical ashtray school project

Hello,
i’am currently working on a school project. I would build an ashtray (i attach a picture of my prototype) that could emit a sound when a cigarette butt is drop in the tube. I’ve done a simple electronic editing with an IR distance sensor, a SD card sheild and a speaker for the test but the sound that leave the speaker is just like a crackling noise (maybe because of the saturation).

Could you help me to see things more clearly? Any suggestions or advices are clearly welcome (as you may have noticed i’am a rookie in arduino)

I used :
-arduino UNO
-SD card shield (with 256 Mb SD card)
-TCRT5000 IR sensor
-10K and 220 ohms resistors
-6 ohms speaker
-WAV files 16Mhz, 8 bits (TMRpcm.h is a WAV library)

I also attach my code and pictures of my editing

EDIT : My bad, sorry. First time on Fritzing, please be supportive.

#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>

#include <SPI.h>
#include <SD.h>
TMRpcm audio;
File soncorne;
void setup() {
 Serial.begin(9600);
 Serial.println ("software's startup");
 if (!SD.begin(4)) { //test com pin 4
   Serial.println ("communication error");
   return; //close the software
 }
 audio.speakerPin = 9;
 audio.setVolume(5);
}

void loop() {
 int sensorValue = analogRead(0); //ir sensor pin A0
 boolean etataudio;
 Serial.println(sensorValue);
 if (sensorValue < 1000) {
   audio.play("funnyv.wav");
 }
}

Testproto.ino (578 Bytes)

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

I’ve tried to draw it clearly… but i am not sure about IR sensor on the draw so i attach an additionnal picture here.

Thanks for the feedback

Henri

Your pic isn't very helpful..

How are you driving your loudspeaker ?

regards

Allan

First time on Fritzing

Please let it be your last time. What we need to see is a schematic. Connecting a speaker direct to a digital output is a bad idea, it will over drive your Arduino. You need to put an amplifier between the digital output and the speaker. You should also have a reconstruction filter on the digital output to smooth the PWM signal.

What you really need is to drop the TMRpcm library and have a real D/A with an amplifier on the end of that.

Smoking in school??

My first thought would be not a "musical" ashtray, but one that retches and gags when the cigarette is dropped in. :)

Yep that's the plan, one aplause, one joke ... for each cigarette in the box.

So i have questions about the amplifier. What class ? Could a T-Amp be the solution for a 9V power supply? What power output ? 5W, 10W?

If you're running this off a 9v battery the most you can can draw is probably rather less than a watt - perfectly audible at close range,

You used to be able to buy very cheap and nasty AM radios - you could use the amp and speaker from one of those....

regards

Allan

Here is an electronic editing with a LM386. How could i transform it for use it in my project ?

Sincerly,

Gresse Henri

Parts List:
power supply (5V to 15V DC)
100uf capacitor (used for power supply decoupling)
1/8 stereo or mono audio jack (fits standard mp3/mp4 players)
LM386N - 3 (purchase a quality chip from a reputable company)
220 to 1000uf capacitor (between amp output and speaker)
470pf capacitor (used to reduce RF interference)
10uf capacitors (x2) (gain and bypass)
0.1uf capacitors (x3) polyester tends to sound better than ceramic
10 ohm resistor
10K resistor
8 ohm speaker (1 watt minimum)
standard hookup wire
breadboard
—resistors should be rated for at least 1/4 watt (a higher wattage rating is fine)
—capacitors should be rated for 2 to 3 times the amount of voltage one expects them to ‘see’, e.g., if the circuit is powered with 9V, then one would want to use capacitors rated for 18 or more volts

Here is an electronic editing with a LM386.

What is "editing", from the diagram it looks like you mean amplifier.

I would also add a 1000uF capacitor across pins 4 & 6 as well as the one already there.

0.1uf capacitors (x3) polyester tends to sound better than ceramic

No the one between 4 & 6 HAS to be ceramic. Also the circuit, and signal you are driving into it, is too poor to bother about polyester capacitors sounding nicer, you will not notice the difference. Leave that to the gold plated mains connector nutter brigade.

Hi Grumpy_Mike

having worked in both the hi-fi and professional audio world as a detail designer for a while ( Cambridge Audio and Neve) I quite agree - there are a lot of nutters out there - that's why I got out....

these days some people reckon the best sound is from single - ended - triodes and horn speakers ... oh really ?

I give up. And did.

regards

Allan

I once had to interview a candidate for the Power supply group manager. In his CV he said he "invented" the gold plated mains connector for use in Hi-Fi. After a few warm up questions about transformers and low drop out regulators, he asked to be excused to go to the toilet. We sat their for fifteen minuets and then went exploring. He had done a runner.