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?
Are you planning to change the "frequency" of the sound generated by the ultrasonic sensor?
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 ?
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?
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.
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() (https://www.arduino.cc/en/Reference.PulseIn)
You can then test the result value and use tone() (https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/) to generate the sound.
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.
Thanks for the all replies! I tested one sensor, and it is working!
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?
I tested one sensor, and it is working!
Please post your working code and we'll see if it can be modified to add your other sensors.
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?
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 (https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay)
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.
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?