2

I am an amateur. I know about Arduino, but I am still learning.

And I was making this Bluetooth rover with a camera, ultrasonic sensor, mecanum wheels, air-soft shooter, and sand sample collector. I am using two L298 motor drivers, because L23D requires soldering and is a bit less compatible with me. So, when creating this amazing robot I realised that I ran out of pinmode spaces for the air-cannon and some other features.

So, is there a way to increase the number of output pins in an Arduino Uno or can I connect the Rx and Tx pins of the Bluetooth module and the trig and echo pin and use them both as one for two more spaces?

1
  • There is I2C I/O expanders that can solve this issue.
    – MatsK
    Commented Sep 12, 2023 at 10:23

3 Answers 3

4

As an extension to Dario.Casciato’s response, there are not only I²C I/O expanders, but also the simple 74HC595 IC, which can be cascaded and used via Arduino's shiftOut function. It needs three signal pins for 8 / 16 / 24 ... outputs.

The link is not a purchase recommendation, but rather a technical hint.

1
  • thank you! I was able to use this and increase the number of features originally planned
    – Anik Singh
    Commented Sep 14, 2023 at 15:43
3

What you probably want is called an ‘I/O Expander’. They come in many different varieties based both on exact means you use to communicate with them, how many I/O pins they give you, and what you can do with those pins.

The usual recommendation for use with an Arduino is an I²C based I/O expander, such a Microchip MCP23017 (available readily online from many sources and available in a DIP format so that you can use it with solderless breadboards), because this provides a reasonably fast interface that is very well supported on the Arduino and uses relatively few pins (only 2 pins are required, not counting Vcc and ground).

I’ve also personally used a Analog Devices DS2408 for this purpose before. It uses a 1-Wire interface, cutting the required pins down to only 1 not counting Vcc and ground, and also not actually requiring the use of a specific I/O pin like a proper I²C device would, but it’s also slower and not as nice to work with (you need a separate library to work with 1-Wire on most Arduino chips), and also only comes in SOIC packages (so requires some precise, but not necessarily difficult, soldering).

In theory you could also use an SPI I/O expander, but they are often a bit more of a pain to work with, and eat at last three pins (possibly four) other than Vcc and ground.


In theory, there are two other options in specific circumstances.

The first is a multiplexer chip, which is essentially a fancy solid-state switch with multiple outputs. These are only really practical if you just need to trigger external devices individually, though that may be viable for your use case (it could easily drive a simple level trigger for the airsoft gun and a simple edge trigger for the sand sample collector).

The second is to use a shift register. These are only viable if you have some way to latch outputs (for example, putting a gated D-latch on each output) or only need the outputs to be valid at specific points in time, because updating the outputs cycles each pin through the output values of each other pin. They’re great if you are doing something like implementing a parallel bus, but not as good if you need fast outputs that retain state.

2
  • 3
    Re “[shift registers] are only viable if you have some way to latch outputs”: the 74HC595, which is kind of a standard in Arduino land and has been mentioned in a previous answer, is double-buffered. A rising edge on RCLK latches the shift register proper into the storage register, which is the one you see on the outputs of the chip. Commented Sep 12, 2023 at 18:44
  • thank you so much I was able to complete the air cannon and even add more features!
    – Anik Singh
    Commented Sep 14, 2023 at 15:40
3

It sounds like you are using some GPIOs ;) If you need more digital pins, you can use the analog pins as digital pins (if you didn't already).

Arduino Uno analog pins as digital pins

If you already occupied these pins, then I would think about getting an I/O expander. It's a chip/IC that can be mostly controlled via I²C, offering you a way to scale your project's GPIO capabilities.

2
  • 1
    thank you for your comment, I wanted it to be a small robot for a competition but with your help I was able to add even more features than the air cannon!
    – Anik Singh
    Commented Sep 14, 2023 at 15:41
  • @AnikSingh That's nice to hear! glad i could help! Commented Sep 15, 2023 at 6:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.