Making a digital phone ringer turn on and off

Dear All,

New to Arduino.

I am trying to make a prop telephone ring on stage.

The inside of the telephone has a buzzer in it, which i have been able to make noises with.

I have made a loop where the frequency shifts to make a classic digital phone ring (think the ding-a-ling)

I now want this loop I have created to follow this pattern:

400 ms on, 200 ms off, 400 ms on, 2000 ms off. (this is the Ring-Ring of a UK telephone)

I am struggling to code this and would appreciate some help.

I tried to make the Ring a function and try and turn the function off and on, but that didn't work for me.

Please see the code so far:

int buzzer = 10;

void setup() {
** // set buzzer to output**
pinMode (buzzer, OUTPUT);
}

void loop() {
** // the pattern and frequency**

analogWrite(buzzer, 500); // the DING-a-ling of the ring
delay(0100);
analogWrite (buzzer, 580); // the ding-a-LING of the ring
delay(0100);

}

Many thanks for your help hive mind!

So far, so good. I can almost hear it.

What are you going to use to initiate a ringing sequence, and when should it stop?

Like "ring in the pattern as long as an input is HIGH"

OR

"ring in the pattern for N number of rings"

Either at this point is a very simple extension of your already success, although to do it in a simple way would compromise a future ability to do more sophisticated things.

If it's just (just, haha, no value judgment, I like the art and science or prop-ology or whatever you call it)

If it is a stage prop, it probably only needs to do one thing reliably and simply.

Do you need to be able to STOP the ringing when an actor lifts the handset? Could that come in the middle between a Ding and an Aling?

We close, just a few pesky dets, THX.

Wouldn't mind seeing your code when you "tried to make the Ring a function and try and turn the function off and on, but that didn’t work...", we could prolly tell you where you went wrong.

a7

Thanks for the notes and questions!

To clarify, when it comes to the phone ring begining on cue, and the phone stopping ringing when answered, so far i am not worried about that, i just want to make it sound like an actual telephone ring at the moment.

In the future, I am going to try and get the handset switch involved, but that is a lot further down the track!!

For the function code I just did this:

tab a:

void phoneringF() {

{analogWrite(buzzer, 300);
delay(0100);
analogWrite (buzzer, 450);
delay(0100);
}

}

Tab b:

void phoneringF();
int buzzer = 10;

void setup() {
// put your setup code here, to run once:
pinMode (buzzer, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly: 400 ms on, 200 ms off, 400 ms on, 2000 ms off.
phoneringF;

}

but i got a bit lost by the end trying return functions and delays which didn't do what i wanted.

So to clarify further in basic terms what I want to code is:

Ding-a-ling (already written and working)
Ring for 400ms

Stop ringing for 200ms

Ding-a-ling (already written and working)
Ring for 400ms

Stop ringing for 2000ms

What model Arduino are you using? Most have an upper limit of 255 on analogWrite() and any value above 254 is equivalent to 'digitalWrite(pin, HIGH);'

Note that your '0100' constants are OCTAL constants because of the leading zero. You should probably use the decimal equivalent: 64.

Dear Johnwasser,

I am using Arduino nano.

Would you recommend I change to digitalWrite? I can do that.

I was intending on writing my delay() in milliseconds, i will avoid having unnessary zeros. So if i stick to delay(100) that would mean delay for 100ms?

thanks

analogWrite is what you want, just fix the numbers you're passing it.

Yes, delay(100) is a hundred millisecond delay.

Yes. That way you can use any pin instead of only one of the six analogeWrite() pins.

Yes. That would change the delay from 64 (0100) to 100 milliseconds.

This is the basic set up.

Yes, OK.

Adding a hook switch won't be a giant leap for a man. Or woman.

And with such a small program typically it would all be in one tab. Using only what you posted and fixing a few things as noted above by others

int buzzer = 10;

void setup() {
  pinMode (buzzer, OUTPUT);
}

void loop() {
	phoneringF();
	delay(2000);
}

void phoneringF()
{
  analogWrite(buzzer, 300);
  delay(100);
  analogWrite (buzzer, 450);
  delay(100);
}

Obvsly this rings forever. Adding a hook switch won't be a giant leap for a man. Or woman.

I suggest thinking about "it rings as long as an input says to, and it will always Aling if it Dinged, that is to say it can't be ceased between the two parts of each thing coming along every two seconds.

a7

I will work on this and report back!

Not relevant to the type of phone you have but I thought this might be of interest

@arkwent2sea published a bit of code for a ringing sound

void loop() {
 // the pattern and frequency

analogWrite(buzzer, 500); // the DING-a-ling of the ring**
delay(0100);
analogWrite (buzzer, 580); // the ding-a-LING of the ring**
delay(0100);

}

And assured us that it worked.

I had a few questions about that, but I never argue against success, so I let those questions be for the moment.

I did not notice the octal constants! But that's OK, just means the OP should use 64 (as noted) if the sound is satisfactory, or 100 if the timing is important. Certainly dealing with decimal values is less tricky, at least for me.

and a recommendation to use digitalWrite, and then there is

I have tested a shower theory: At least on the UNO, analogWrite will use only the lower 8 bits, so the OP's 500 and 580 are the same as 244 and 68 in decimal respectivelyl, and would be more obvious as points of departure for tinkering experimentation. So that should be "fixed" in the code.

As always and especially when multiple radices are involved, check my calculations!

The analogWrite frequency I measure is fixed and 976 Hz. The two tones are coming from the duty cycle of analogWrite's PWM mechanism. This raises questions about what the transducer in the telephone really is... again, I do not argue with success, but I am curious about it.

Nice! I may have to do that to one of the old telephones rotting carefully stored in the basement.

a7

OMG! You're right! analogWrite() takes an 'int' and does not constrain it properly!

void analogWrite(uint8_t pin, int val)
{
	// call for the analog output pins.
	pinMode(pin, OUTPUT);
	if (val == 0)
	{
		digitalWrite(pin, LOW);
	}
	else if (val == 255)
	{
		digitalWrite(pin, HIGH);
	}
	else
	{

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.