Go Down

Topic: Muxing 8 ultra sonic sensors (Read 5476 times) previous topic - next topic

tamirsagi

Jan 30, 2016, 03:27 am Last Edit: Jan 30, 2016, 03:34 am by tamirsagi
Hi all,

I'm working on a project where I need to sense the environment. I use Arduino Mega, Motor Shield(L293D) which is connected to it.
Im gonna be using 8 Ultra Sonic sensors, model : HC-SR04. however, i dont have enough available ports for all sensors  so I ordered Multiplexer, CD74HC4067.

I'd like to connect 8 sensors to the multiplexer and get the data when needed.
my problem is:
1. I'm new to Arduino.
2. first time working with sensors
3. this specific sensor has 4 legs,  I dont know how to connect 8 sensors to the multiplexer
4 I dont know how to connect the mux to the Arduino.(which ports)

as I mentioned, I already installed Motor Shield for both DC and Servo motors.

I found these tutorials :

Muxing + Arduino

arduino-hc-sr04-sensor-through-cd74hc4051e-multiplexer-using-single-wire

interfacing-multiple-ultrasonic-sensor-arduino

connecting-multiple-ultrasonic-sensors-to-one-arduino

hc-sr04-using-multiple-ultrasonic


Thanks alot!!

Grumpy_Mike

5) you ordered the chip without asking anyone here if it would work.

Sadly it won't because you need a dual 8 channel multiplexer not a 16 channel one.

The ultrasonic sensor has two power pins, which can be common with all the sensors and two signal pins which multiplexing.

PaulRB

#2
Jan 30, 2016, 08:25 am Last Edit: Jan 31, 2016, 01:02 am by PaulRB
I think it could work. However, for 8 sensors, the 4067 (16-way) was a waste because a 4051 (8-way) would have been enough. For that matter, why use a multiplexer at all? Your Mega has lots of pins! Using the multiplexer will use 4 Arduino digital pins. Not using a multiplexer would use only 8 digital pins.

On those sr04 sensors, 2 pins are for power as Mike says, connect them to 5V and ground. The other 2 pins are trigger input and pulse output. These can be wired together with a 1~2K resistor and are normally frequently* connected to a single digital pin on the Arduino, but in this case to one of the "I0" to "I7" pins on the multiplexer. The "common input/output" pin connects to an arduino digital pin. Three more arduino digital pins connect to the "S0" to "S2" pins on the multiplexer.

With these types of chips, i understand it's important not to leave any pins unconnected. So connect the 8 unused "I8" to "I15" pins, the "E" pin and the unused "S3" pin to ground.

* Amended based on comments from Grumpy_Mike

tamirsagi

#3
Jan 30, 2016, 09:32 am Last Edit: Jan 30, 2016, 09:38 am by tamirsagi
@Mike, I ordered a MUX while knowing it should work find. I ordered 16-way because I might have more than 8 sensors, including IR sensors as well.(may have up to 10 sensors) and I dont have enough pins on The Mega

@PaulRB,
Im adding my arduino snapshot, to show you how many ports I have left. Would you please guide me how to connect these 8 sensors with 16-way mux??

Thanks for your fast and wonderful respond.


Paul__B

I'm adding my Arduino snapshot, to show you how many ports I have left.
A few dozen by the look of it.  What do you suppose that whopping great connector at the top of your picture is for?

Would you please guide me how to connect these 8 sensors with 16-way mux??
No.  You have been told.  When you start talking sense, we may be able to help.

PaulRB

#5
Jan 30, 2016, 10:43 am Last Edit: Jan 30, 2016, 10:45 am by PaulRB
NewPing library:

Quote
New in version 1.4:
You can now interface with all but the SRF06 sensor using only one Arduino pin. Added support for the Parallax PING)))™ sensor. You can also interface with the SRF06 using one pin if you install a 0.1uf capacitor on the trigger and echo pins of the sensor then tie the trigger pin to the Arduino pin (doesn't work with Teensy). To use the same Arduino pin for trigger and echo, specify the same pin for both values. Various bug fixes.

tamirsagi

#6
Jan 30, 2016, 12:08 pm Last Edit: Jan 30, 2016, 12:28 pm by tamirsagi
@Paul__B
Im not sure I got you. what do you mean "start talking sense"
1. The great connector is a shield, for DC and Servo motors.
2.I explained that I have no idea how to connect 8 sensors using Mux on the pins I've left.
 I was told there are not enough available pins for 8 sensors(may be more) thats the reason I ordered the Mux

@PaulRB Thanks for the reference, looks good.

Thanks

Paul__B

It's late at night.

I'm "leaving this for the keeper"! :smiley-lol:

PaulRB

#8
Jan 30, 2016, 02:41 pm Last Edit: Jan 30, 2016, 02:50 pm by PaulRB
I was told there are not enough available pins for 8 sensors(may be more) thats the reason I ordered the Mux
I'm no expert on Mega, but it looks to me like you have around 50 spare digital & analog pins (analog can also be used as digital). Yet you have bought a multiplexer to save pins. That's was does not make sense to either of us.

Did the person that gave you advice think you had an Uno instead of a Mega?

I explained that I have no idea how to connect 8 sensors using Mux on the pins I've left.
On those sr04 sensors, 2 pins are for power as Mike says, connect them to 5V and ground. The other 2 pins are trigger input and pulse output. These can be wired together and are normally connected to a single digital pin on the Arduino, but in this case to one of the "I0" to "I7" pins on the multiplexer. The "common input/output" pin connects to an arduino digital pin. Three more arduino digital pins connect to the "S0" to "S2" pins on the multiplexer.

With these types of chips, i understand it's important not to leave any pins unconnected. So connect the 8 unused "I8" to "I15" pins, the "E" pin and the unused "S3" pin to ground.
If some of that was not clear enough, just ask. If you want to add more sensors to the multiplexer, you would connect them to I8 to I15, but you will then need anther Arduino pin to connect to S3. Make sure to connect any unused pins to ground.

tamirsagi

Thanks @PaulRB,

Just to make things more clear,it can be referred from the picture I uploaded that pins 24-52 under digital and A8 - A15 under Analog are available.


I have 8 HC-04 ultra sonic sensor, each one of them has 4 legs.
1. GND
2. Echo
3. Trig
4. Vcc

I ordered the mux because the person has told me I dont have enough pins for that(he probably was wrong) So the Mux is unnecessary.

Where does each leg go? I need 32 available pins(theoretically) but from what I understood, there might be a way of assembling few legs together and save pins.


please elaborate a bit more .

Tamir.

PaulRB

#10
Jan 30, 2016, 04:45 pm Last Edit: Jan 30, 2016, 04:50 pm by PaulRB
Just to make things more clear,it can be referred from the picture I uploaded that pins 24-52 under digital and A8 - A15 under Analog are available.
Yes, you seem to have digital pins 14 to 21 on the left, analog pins 8 to 15 on the right and digital pins 22 to 53 at the top, all available. I would use the ones at the top, since they are "ordinary" digital pins and don't have extra functions that make them more valuable.

I have 8 HC-04 ultra sonic sensor, each one of them has 4 legs.
1. GND
2. Echo
3. Trig
4. Vcc

Where does each leg go? I need 32 available pins(theoretically) but from what I understood, there might be a way of assembling few legs together and save pins.
You need 8 pins for your 8 sensors. The GND & Vcc for all 8 sensors can be daisy-chained and go to GND & 5V from the Mega, perhaps the big connector at the end. On each sensor, the Echo & Trig pins can be connected to each other and to a digital pin on the Mega.


Grumpy_Mike

#11
Jan 30, 2016, 10:10 pm Last Edit: Jan 30, 2016, 10:14 pm by Grumpy_Mike
The other 2 pins are trigger input and pulse output. These can be wired together and are normally connected to a single digital pin on the Arduino,
Now I would take exception to that, they are not normally connected to the same pin, they normally have separate pins.

Yes that library says
Quote
New in version 1.4:
You can now interface with all but the SRF06 sensor using only one Arduino pin.
But all the examples given show two pins being used, and the library is written by someone who posts here occasionally and who is "controversial" to say the least. Especially where hardware is concerned.
If you connect the trigger pin to the echo pin you are connecting an input to an output, fine as far as it goes but:-
1) If you want to trigger a reading then you have to make the Arduino pin an output and so two outputs together don't want to do that. In the code it says:-
Code: [Select]
#if ONE_PIN_ENABLED != true
 *_triggerMode |= _triggerBit; // Set trigger pin to output.

2) Any returned echo signal will trigger another pulse, and that in turn will trigger another pulse and so on.

So it might work but I would contend that it would not work well and would also put the hardware under an out of specification strain.

Just because some one puts a technique in a library does not make the technique valid.

Anyway he has more than enough pins free to have a separate trigger and echo pin.

PaulRB

#12
Jan 31, 2016, 12:53 am Last Edit: Jan 31, 2016, 12:58 am by PaulRB
So it might work but I would contend that it would not work well and would also put the hardware under an out of specification strain.
Mike's challenge is a fair one. In my defence, I had encountered this method being used long before I became familiar with Arduino, having seen Picaxe circuits doing the same thing. But I can't deny that describing it as "normal" is a bit of a reach. After all, why would they be manufactured with separate trigger and echo pins otherwise?

Checking Google, the other circuits I have seen that connect the trigger and echo pins use a 1~2K resistor between the two, to limit the current and prevent damage. For example here.

Grumpy_Mike

That link says it works because the pulse in function when called to measure the returned echo immediately sets the pin to an input. This library makes great play of how the pulse in function is not used.

I still can't see how my other point that of self retriggering is addressed. As you have the pins anyway I would use separate ones.

Paul__B

No shortage of pins!

This appears to be a particularly nasty case of ingrained "Shield-itis".

Go Up