New project help - random interval tone

I was directed to this site by a good friend, and I’ve spent the better part of today exploring it. There is a ton of great info, but I have not come across what I need to accomplish exactly.

I aM looking to build a button that initiates a tone. The tone signals the beginning of a pre-determined length of time during which a second tone will sound at random.

Example: button clicked-> first tone signals beginning of countdown-> second tone goes off at random between the preset time frame (ex. 2-4 seconds) to alert the user to complete the action.

The preset length of time needs to be easily changed, tone sounds need to be customizable and I’d love to be able to link an app to this as well.

Does anyone have any pointers, thoughts, ideas? I am new to this side of technology and an open to any and all insight.

Thank you.

How much help do you need? Do you know anything about electronics or programming?

There is a [u]random()[/u] so it's easy to set a random time (within a range) and/or a random-frequency [u]tone()[/u].

You'll probably also have to use [u]millis()[/u] timers.

The preset length of time needs to be easily changed,

It's easy to change a variable in the program. But if the user needs to change things, it's going to require a "user interface" of some kind.

tone sounds need to be customizable

You can change the pitch & duration, but there is no DAC in a regular Arduino so you'll only get simple tones unless you add some hardware.

and I'd love to be able to link an app to this as well.

That's not easy, and you might have to add hardware depending on how you are going to communicate between the two devices. And, if you are going to write an app for your phone or computer you might as well do the whole thing on the phone/computer instead of using an Arduino.

Thank you for the response, DVDdoug

I actually need a lot of help. I’ve never done anything like this before. I just see a problem many people face, I’ve worked up a solution and now I just need to construct it the way it best suits the application. I’d be more than happy to pay someone to construct it.

Simple tones are great. It will need a user interface. I would not need the app if the user can change the settings, tailor their training etc.

What products would I need for a simple button and microphone?

HARDWARE -

What products would I need for a simple button and microphone?

You might want to get a "Arduino starter kit" but I can't recommend one so maybe someone else can help.

The "extra" parts in the starter kit will allow you to try some of the other example programs so you can learn some more programming concepts. i.e. You might use some ideas from an example in a different way with your button & speaker.

Not a microphone. A microphone converts acoustic sound to an electrical signal. You want the opposite - a speaker (or piezo "transducer") to convert electrical signals to sound.

The Arduino can't drive a regular 4 or 8-Ohm speaker so I'd start out with a piezo transducer and then if it's not adequate you can add an amplifier and speaker. (Or, you can use "powered" computer speakers.)

There are two kinds of piezo devices for generating sound. Like I said, a "piezo transducer" or "piezo speaker" converts electrical signals to sound and that's what you want if you want to "make music", etc.

There are also "piezo buzzers" or "beepers". These have a built-in tone-generating circuit so you can't control the sound. It gets tricky because some people (and some "cheap" suppliers) say buzzer or beeper when they really mean transducer.

For the button, you generally want a "momentary pushbutton switch".

SOFTWARE -
There are [u]Examples[/u] for how to read a pushbutton switch and for making tones, etc., and each example has a schematic showing the required electrical components and wiring.

The two most important concepts in programming are conditional execution (if statements, etc.) and loops (doing something over-and-over, usually until some condition is reached). Once you understand those concepts you can start writing "useful" software.

When you start writing your own programs, don't try to write the whole program at once. Write and test one or two lines of code at a time. That's not as simple as it seems because the compiler has to "see" a "complete program", so you can't just start at the top and work down. (i.e. If you delete the bottom half of a working program, it's not going to compile.)

For testing & debugging, it's helpful to use the serial monitor to display variable values and to send little messages about what your program is doing. (See the Analog Read Serial Example.)

For your "user interface", in some cases if you can use toggle switches or potentiometers the user can see the physical setting/position. Other times a few LEDs can show "status" or a certain "beep code" might tell you what's going on, etc. Or, you may need an LCD display and keypad or multiple buttons, etc.

you can use this code, it should be self-explanatory.
I've just put it on my repository, it might evolve a bit in the future: garvuino/simple_beep.ino at master · farvardin/garvuino · GitHub

(note: I forgot about the random time, but you might adapt it easily)

// Simple beep generator for Garvuino
// https://github.com/farvardin/garvuino/


int switchInPin = 6; // Switch connected to digital pin 6
int speakerPin = 9; // Speaker connected to digital pin 9 (connect the other end of the speaker to the GND)

#define LED 13      // on board led

int reading;   // variable to store the button's state

// define your own values there:

int pre_delay = 2000;      // delay before sending the beep (in ms)
int beep_frequency = 440;  // frequency of the beep. A4 = 440
int beep_duration = 400;   // how long will last the beep (in ms)
int beep_repetition = 4;   // how many time shall we repeat the beep
int beep_interval = 500;   // time in ms between two beeps

 


void setup() {
  // put your setup code here, to run once:
  pinMode(switchInPin, INPUT_PULLUP); // uses internal arduino resistor
}

void loop() {
  // put your main code here, to run repeatedly:
  reading = digitalRead(switchInPin);

  // switch
  if (reading == HIGH  ) {
    // do nothing while switch is not activated
  }
    else
      { led_blink(4);
        delay(pre_delay-200); // we remove 200 which is the delay added by the led blinking
        for (byte j=0;j<beep_repetition;j++)
        {
          make_beep();
          delay(beep_interval+beep_duration);  // tone is running in parallel with delay so we add them together
        }
      }
}


void make_beep() {
  
  for (byte j=0;j<beep_repetition;j++)  // make a loop
  {
    digitalWrite(speakerPin,LOW);       // make sure the speaker is off
    tone(speakerPin, beep_frequency, beep_duration);   // turn speaker on
  }
}


void led_blink(byte num)         // Basic blink function
{
    for (byte i=0;i<num;i++)
    {
        digitalWrite(LED,HIGH);
        delay(20);
        digitalWrite(LED,LOW);
        delay(30);
    }
}

Thank you farvardin!