arduino speaker wiring? - The Planted Tank Forum
 
LinkBack Thread Tools Display Modes
post #1 of 4 (permalink) Old 12-11-2014, 05:32 PM Thread Starter
Wannabe Guru
 
PTrader: (44/100%)
Join Date: Apr 2012
Location: San Diego - CA
Posts: 1,028
arduino speaker wiring?

cant seem to get the speaker to play or do anything...

is there a test sketch or something to test if the speaker works? maybe the wiring is wrong? i'm not even sure where to begin -.-

5v was powered from the arduino
gnd was also from the arduino...


i tryed both of these :


the left side i tryed using a 4.7k resistor not a 120 as i dont have one...
the right side i tryed using a bc546B trans as i dont have a bc337 trans. wired it up just lik the diagram showed...




i have also tryed this:


just the top where it uses a cap and i was using a 220uF as the cap and still doesnt work...


the data pin i was using is the Digital pin 47 on the arduino mega 2560


this sketch was what i was testing it on:
Code:
/*
  Melody
 
 Plays a melody 
 
 circuit:
 * 8-ohm speaker on digital pin
 
 created 21 Jan 2010
 modified 30 Aug 2011
 by Tom Igoe 

This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/Tone
 
 */
 #include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

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

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; 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];
    tone(47, 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(47);
  }
}

void loop() {
  // no need to repeat the melody.
}
Bryanmc1988 is offline  
Sponsored Links
Advertisement
 
post #2 of 4 (permalink) Old 12-11-2014, 09:17 PM
Children Boogie
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 16,743
To test a speaker, take a AA battery and swipe the + wire and you should hear it in the speaker. It should be a small 8 ohm speaker btw.
mistergreen is offline  
post #3 of 4 (permalink) Old 12-11-2014, 10:00 PM
Children Boogie
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 16,743
this sketch works for me
http://arduino.cc/en/Tutorial/Tone

Except I had to copy & paste the note #define into my sketch. Adding a separate library wouldn't compile.

Try another digital pin.
mistergreen is offline  
 
post #4 of 4 (permalink) Old 12-11-2014, 11:07 PM
Planted Tank Obsessed
 
PhysicsDude55's Avatar
 
PTrader: (0/0%)
Join Date: Oct 2011
Location: Dallas, TX
Posts: 339
4.7K ohms might be too much resistance.

DIY Enthusiast


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
PhysicsDude55 is offline  
Reply

Tags
None

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the The Planted Tank Forum forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome