Running out of pins on the Arduino UNO!

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).

Thanks!

Did you factor the analog pins into your sums? They work as normal digital pins too:

The analog input pins can be used as digital pins, referred to as A0, A1, etc.

Hello, a couple of suggestions from me:

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

Paul

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.

(An "exercise left for the reader" :grinning: )

Paul__B:
(An "exercise left for the reader" :grinning: )

My favourite in technical explanations especially mathematical was always....

It can be shown that....

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

YaddyVirus:
Till now I was only counting the Digital(PWM) pins, I thought the Analog pins were something different

Can you clarify what you need for the motor driver? Not all digital pins are pwm pins. Analog pins can also be digital pins on Uno, but none are pwm

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.

http://www.aliexpress.com/item/PCA9685-16-Channel-12-bit-PWM-Servo-motor-Driver-I2C-Module-For-Arduino-Robot/32592084002.html?spm=2114.01010208.3.1.F15RC4&ws_ab_test=searchweb201556_0,searchweb201602_2_10017_10005_10006_10034_10021_507_10022_10020_10018_10019,searchweb201603_7&btsid=ae0a1515-924a-4581-b509-b7ad312b30e7

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!

Glad it works.

Just remember in case you didn't know, only the digital pins marked ~ are PWM-enabled.