Tone library - at a complete loss

I am getting nothing out of my speaker. What am I doing wrong?

#include <Tone.h>

// You can declare the tones as an array
Tone tonePlayer;

void setup(void)
{
  Serial.begin(115200);
  tonePlayer.begin(2);
  Serial.println(F("Setup complete"));
  pinMode(2, OUTPUT);
  analogWrite(2, 50);
  tonePlayer.play(500);
}

void loop(void)
{
}

ArduinoSpeaker.jpg

I know nothing about the tone library.

Does your hardware work with the regular-old [u]tone()[/u] function?

Like I said, I know nothing abut the library but your analogWrite() seems strange.... If you stick a couple seconds of delay() after the analogWrite() you should hear the PWM.

DVDdoug:
I know nothing about the tone library.

Does your hardware work with the regular-old [u]tone()[/u] function?

Like I said, I know nothing abut the library but your analogWrite() seems strange.... If you stick a couple seconds of delay() after the analogWrite() you should hear the PWM.

I get absolutely nothing with either tonea.h or tone.h

This does not even work:

bool bOn = false;

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Setup complete"));
}

void loop(void)
{
  if (bOn)
  {
    digitalWrite(2, LOW);
    bOn = false;
  }
  else
  {
    digitalWrite(2, HIGH);
    bOn = true;
  }
  delay(10);
  //toneAC(1000, 10, 5000);
  //noToneAC();
}

What exactly is XFG1?
Is the emitter of the transistor connected to the Arduino ground?
What is the purpose of the transistor? You don't appear to use it.

Pete

el_supremo:
What exactly is XFG1?
Is the emitter of the transistor connected to the Arduino ground?
What is the purpose of the transistor? You don't appear to use it.

Pete

el_supremo:
What exactly is XFG1?
Is the emitter of the transistor connected to the Arduino ground?
What is the purpose of the transistor? You don't appear to use it.

Pete

The software is Multisim and XFG1 is just a virtual function generator for simulation purposes. It is not part of the real circuit.

Emitter of BD139 is connected to Arduino GND.

Transistor is meant to boost the power through the speaker and so the arduino pin is not driving it directly.

The 8 ohm resistor is a stand in for my speaker as multim does not have a speaker component.

I get absolutely nothing with either tonea.h or tone.h

The regular tone() function doesn't require a '.h' library.

Or again, this should make a tone:

analogWrite(2, 127);   // 50% PWM @ the default PWM frequency
delay(10000);        // Hold tone for 10 seconds

Maybe your speaker or transistor is blown? Try disconnecting the base resistor from the Arduino and momentarily connect it to Vcc. That should turn-on the transistor and make a "click" from the speaker. If it's a bare speaker and you can see the cone, you'll probably see the speaker cone move.

The Blink Example (modified for pin 2 or wherever your transistor is connected, or connect the transistor to pin13) will also produce a click when the LED goes on or off (with or without an LED actually connected). If you see the LED blinking but you get no sound, you know you've got a hardware problem.

Or if you have some (known good) powered computer speakers, connect the Arduino to those speakers to see if you're getting anything out of the Arduino. (Turn the speaker-volume down before you start because the Arduino 5V output is a "hot" signal.)

Maybe you've got a wrong or broken connection? Maybe the transistor is wired wrong? Maybe your Arduino is bad? Maybe you're not connected to pin 2? Maybe the resistor is wrong (megohms, or something)?

P.S.
That base transistor should probably be somewhere around 200 Ohms. (125 Ohms would be the minimum, for the maximum allowed current from the Arduino.) At around 1K, you should get sound and it might work fine, but the transistor might not turn fully-on and it might overheat.

best way to do it is start with code that works, and i have been playing with this code for the last hour, so i know it works,

get code here

try it out and see if that works, then you will know if you have a software problem, if that works then try your code is messed up, if it doesnt then you have a hardware problem :slight_smile:

P.S.
if that does work you can check out this >>Here<< which is a bunch of tones that work with that code :slight_smile: just tryna give you a jumpstart :slight_smile:

P.P.S
i took your code and loaded it into my arduino, it is annoying, but it definitely works... so you have a simulator problem, or a hardware problem... if you are going to simulate arduino and have aspeaker you should really look at Proteus, it has a speaker that works throught the headphone output of the computer, and is a much better simulator. DVDdoug is right though swap out your transistor, or try it with a piezo buzzer first, you can salvage them from alot of old junk (smoke alrms, microwaves, washer/dryers computer MB) if you have a headphone jack (female, you can actually connect this to anything with an AUX cable (which is 90% of audio toys these days, including car stereos) just be sure to have the volume all the way down and work it up slowly as to not destroy anything ..