I'm planning on putting six HC-SR04 ultrasonic distance sensors in my next project.
The thing is I don't have enough pwm pins on my Arduino Pro Mini (3.3v 8Mhz) for all the six trig pins (I also need the SPI pins 10/11 for a USB Host Module).
Would a software-pwm library (like softPWM) work for this purpose?
I also came across the NewPing library where it LOOKS like it can use any digital pin. But I can't confirm whether that is correct or not.
As I understood it, you need to make a 40khz soundwave (using pwm) on the trig pin using the Arduino. Not correct?
All the "hc-sr04 Arduino wiring" google examples also wire the trig pin to a PWM pin. Is that a coincidence?
You need to send the trig pin a 10µs pulse. The module will then send a 40KHz burst (8 cycles) and then you need to monitor the echo pin to measure the time the 40KHz burst took to reach an object and come back.
The Arduino does not need to generate the 40KHz pulses. This is done by the module.
What you have to worry about, is that the echo can be "heard" by more than one of your sensors, depending on the surrounding conditions (walls, etc.), so measuring distances simultaneously can be tricky.
Aaaaaah. Ok. I misunderstood then. I thought the Arduino was generating the 40khz directly.
So that means I can use any GPIO pin, including 'analog' pins. Correct?
Interference will not be a problem I think since I plan on doing the measurements one by one.
You need one pin for the trigger, which can be shared by all sensors. And one echo pin for each sensor. 7 pins for 6 sensors.
Sharing the trigger pin means that all sensors will emit a pulse at the same time, but that should not be a problem because you will listen to only one sensor echo pin at a time.
Yes, indeed. It will ultimately depend on the specific setup you have and its surroundings. If you have enough pins you will be better off using separate triggers.
You might be able to receive the reflection pulse of all the devices if you connected each to one input pin through a 1N4148 diode with a 10k resistor to ground at the input pin
Then you will only receive the reflection pulse from the sensor you trigger.
There are of course more complex methods as this is seen as a bit if a hack, but it will work.