Frequency Measure

I'm new to Arduino, and trying to do a project which produces different frequency at different pulse width range.

I have an ultrasonic sensor which produces an output at 5V with different pulse width, depending on the distance it measures. Using that pulse width, I want to convert it into frequency. But I want to produce different frequencies every 600us. Like between 0 - 600us, 60Hz, between 600- 1200us, 100Hz.

Once it's over 25ms, I want it to stop producing any frequency. Also, before the next detection, I want it to keep beeping.

Is there any way to implement this?

Thanks.

Are you planning to change the "frequency" of the sound generated by the ultrasonic sensor?

Paul

jiwonie:
I want to produce different frequencies every 600us. Like between 0 - 600us, 60Hz, between 600- 1200us, 100Hz.

You need to do some maths.

How long is 1 cycle at 60Hz ?

How long is 1 cycle at 100Hz ?

Yours,
TonyWilk

Your specification is not exactly clear. Do you mean that you want to continually read an ultrasonic sensor and then create sounds using a separate buzzer (which you didn't mention)? And the frequency of the buzzer sound should vary depending on the pulse width returned from the ultrasonic sensor?

Steve

Sorry for the unclear specifications.

I would like to produce different sound depending on the where the input comes from.

The ultrasonic range finder I have senses an object between 2 and 400 cm, and produces an output at 5V with pulse width corresponding to the time ultrasonic sound wave takes to travel from the transmitter to receiver. It is also compatible with Arduino.

I want to detect an object from 2 to 100cm ahead. I want to convert pulse width produced between 50 and 100cm to one slow frequency. Then, from 50cm, I want to convert pulse width produced every 10cm to different frequencies. So when the object comes closer to the sensor, I would like to produce faster sound to alert.

To produce sound, I will have a speaker connected to the Arduino board. There are some Arduino boards available at school, so I'm going to try different ones. I haven't decided which Arduino board to use yet. I would really appreciate if you guys could recommend me one.

If there're more things to clear, let me know.
Thanks!

jiwonie:
I want to convert pulse width produced between 50 and 100cm to one slow frequency. Then, from 50cm, I want to convert pulse width produced every 10cm to different frequencies. So when the object comes closer to the sensor, I would like to produce faster sound to alert.

Ah... some info on your ultrasonic range finder would be handy

Meanwhile, assuming you can just tell the rangefinder to GO and then want to read a pulse, have a look at pulseIn()

You can then test the result value and use tone() to generate the sound.

Yours,
TonyWilk

It should be possible with any Arduino. I'd probably use a Uno or Nano.

From the examples in the IDE you should be able to find some code to read the sensor and print pulse widths or distances to the serial monitor.

Another example will show you how to use tone() to create different frequencies.

Then you combine them putting in some if statements to say things like if pulse is between 50 and 100 then do tone(60Hz), if pulse is 40 to 50 do tone(100Hz) etc. though you'll probably want to choose different frequencies because they're too low for buzzers or small speakers.

Steve

Thanks for the all replies! I tested one sensor, and it is working!

Another Question.

I have two transducers and three sensors.
One transducer is placed on the left, and another on the right.
One sensor is placed in the middle, and the others on the left and right.

I want to produce an output according to the direction where the sensor detects an object from. And when the middle sensor detects, I would like both transducers to react.

What would be the best way to do it?

Thanks.

jiwonie:
I tested one sensor, and it is working!

Great!

Please post your working code and we'll see if it can be modified to add your other sensors.

Yours,
TonyWilk

if(duration<=900 && duration > 10)
{
tone(outPin, 150, 25);
}

I have 6 of this code for different range setup, and 1 with noTone(outPin).
I understand that this generates different tone, but I wanted to produce same frequency of the sound, but different frequency of beeps. So once the object comes closer to the sensor, it will beep faster.

I was thinking that I can just change the tone( , ,duration) <- this duration short, but the longest frequency of the beeps will be 1s. Wouldn't this delay entire code? then, the sensor wouldn't be able to detect an object approaching fast to the sensor.

How can I resolve this problem?

Thanks

jiwonie:
I wanted to produce a sound at different speed, not tone.
So once the object comes closer to the sensor, it will beep faster.

Have a look at the Blink Without Delay tutorial

change the 'interval' value and consider how you could use your 'duration' value as the 'interval'

and how you could use tone() and noTone() instead of blinking an LED.

Yours,
TonyWilk

Wouldn't this delay entire code? then, the sensor wouldn't be able to detect an object approaching fast to the sensor.

You can probably do other things while the beep sounds. But do you want a new beep to start while the 1 s beep still sounds?