Hey there! I'm working on an autonomous robot for which I picked up the Arduino UNO as the drive train control board. I am using 3 HC-SR 04 Ultrasonic sensors plus 2 L293d Motor drivers, (not the IC, its a complete module, see this - http://forum.arduino.cc/index.php?topic=394191.0 ). Now the thing is, I'm short of pins on the Arduino. 3 HC-SR 04 mean 6 pins, plus, 6 pins for one motor driver, and I'm already out of pins.
So is there any way with which I can either increase the number of pins that I have or can I use one pin for more than one thing (lets say pins 7 & 8 for the sensor as well as output for the motor driver).
For the ultrasonic sensors, could you common up all the pulse outputs? You may need to use some diodes for this to make a crude "or" gate. Then you can trigger the sensors one by one and listen for the output pulse on the same pin. Alternatively, common up the trigger inputs. Trigger all sensors at the same time but listen for pulses on the outputs one by one. Danger of the sensors picking up each other's pings that way, though.
Upgrade to Mega
Change to use sensors/controllers that connect via a bus, either i2c or spi
PaulRB:
Danger of the sensors picking up each other's pings that way, though.
Interesting point. Would that matter? Why would that matter?
The transducers are pretty directional, so what actually is the likelihood of picking up a reflection from another direction?
If an object is sufficiently close to cause such a thing, would not the closest reflection be picked up by the transducer pointing directly to the object and be more relevant than an offside reflection?
If a reflection can be picked up from a transducer pointing in another direction, does that not also imply that any given transducer can pick up reflections from similarly off-axis to its own ping?
Is not pulsing all the transducers together, essentially the same as emitting the ping omnidirectionally, but receiving it with a directional transducer?
OK, there is a trick to this last question, but I will leave it to someone else to point it out.
JimboZA:
Did you factor the analog pins into your sums? They work as normal digital pins too:
Well if they do, that can pretty much solve my problem as I can run the servo directly from the Arduino and run the motor driver from the 6 analog pins. Till now I was only counting the Digital(PWM) pins, I thought the Analog pins were something different
PaulRB:
Analog pins can also be digital pins on UNO,
To be clear, Analog pins on the UNO simply are digital pins which happen to have an additional function in that they are inputs to the ADC multiplexer. This means that they can be set as INPUT_PULLUP to enable the internal pull-up while reading an analog voltage such as across a LDR or photodiode.
The SMD versions of the chip as on the Pro Mini and Nano do have A6 and A7 which are not digital pins.
JimboZA:
Did you factor the analog pins into your sums? They work as normal
Yes they do work! I hooked up all the HC-SR 04s to the Analog pins, and they are working perfectly fine! Now I've got all the Digital PWM pins for the motor driver!