How to add multiple sensors to a single Arduino nano

I am making a RC Car has multiple sensors for various data collection (rover type exploration car model for school project). My rough diagram contains the data pin connections to various modules. Even though my model contains the Bluetooth and IR connectivity, I wanted to add the NRF24L01 (with base module) connection to my model. How I do so? all the pins are taken up by sensors or other modules then how to multiplex? I don't want to use Arduino mega or another nano.

I am a newbie so please help me out.

The NRF24L01 requires the SPI bus (pins 11/12/13 and one pin of choice). So you will have to make those available.

Can you please add the types of sensors in your drawing for each sensor. I can recognise some (DHT, HC-SR04, possibly some IR pairs) but I have no idea about most of them.

The usual way is to add multiplexers and/or SPI/I2C port expanders and/or shift registers if you need more pins.

You could use a port expander for some of the sensors that output a digital HIGH/LOW signal. This can help freeing up the SPI pins as @sterretje suggests.
A popular expander is MCP23017. It connects with I2C.

I see IR (twice in fact - why?), I don't see Bluetooth. I do see this:
image
which suggests you'll use TX/RX for something...maybe a Bluetooth module? That may work, but occupying your only hardware UART with this means you can't use the Serial monitor to troubleshoot your code through Serial.print. All you'll see is whatever happens between the Nano and the Bluetooth module (assuming that's what will connect there).

I'd strongly reconsider this and go for a board with more GPIO's and preferably more than one hardware UART. It'll make your life a lot easier.

I have updated the image. Plz see.

What concerns me is how you're powering all of this. Please take a moment to elaborate on that topic.

I have no idea, plz suggest. But previously without the modules, I was using 3S 18650 Li-ion batteries to power the car.

I am not sure if the current consumption by the modules will fry the board or not? I have stated my wants in the question but don't know how to proceed.

Okay. Step 1. Find and review code that reads/controls each one of your sensors. If you can't make them work individually, you'll never converge on a code that uses all, or most, of them. As part of this step, note which ones require which power - 5V, 3.3V, other. If you can, identify the current requirements of each, as well as the voltage.

Step 2 - Now you're able to assess what power your project needs; it's quite likely that, in addition to running some parts directly from the battery, you may need voltage converters to create the voltage/current requirements of other items.

Yes all the components (modules) are individually working properly.

But if the car is stopped and then a snapshot of all the data is collected then less amount of current passes though arduino.

But it should be that the data should be collected continuously while it is moving (like a Mars rover) (then plot the data in a graph). Then more amount of current passes though arduino.

How to manage the power supply in this case? Moreover I don't know how to connect the NRF24L01 as I am running out of I/O pins. Plz help.

In terms of current consumption, only the motors are a concern. The rest is chips.

Feed the motor driver directly from the 3S 18650 back. Use a DC-Dc step down to 5V for the MG90s. The rest can be powered through either that 5V step down or through the Arduino's 5V pin. The former is better. So you need an additional DC-DC step down to make the separate 5V.

Earlier advice given to you in #2, #3 and #4 still applies.

The rest can be powered through either that 5V step down

A silly question-- Will lm7805 work or LM2596S as a DC-DC step down for powering my modules directly by my battery pack ( ≈7.6V to 5V) instead of the Arduino's 5V pin? or should I use anything else?

Preferably the latter. The former is an ancient linear regulator that will run unnecessarily hot and waste power. The latter is already better. There are hundreds or thousands of suitable step down converters on the market; choose a type that is actually a step-down "buck" converter, not a linear regulator.

The 7805 also has the disadvantage that it may not work well once your batteries are starting to drain and their voltage drops, since the 7805 requires a fairly high voltage overhead to maintain regulation. How well the 2596 does in this regard, I don't know. You may want to consider more modern types that have overall better performance and efficiency. Both types you mentioned are pretty old and outdated; the 7805 very much so, the 2596 is also not very modern anymore.

A6 and A7 are analog inputs exclusively, you cannot use them as digital inputs, much less as outputs.
The BMP280 must be connected to pins A4 and A5 because it uses I2C communication.
The HC-05 has logic levels of 3.3V and needs you to adapt the Rx signal because the Tx signal of the Nano is 5V.

I thought of using "PCF8574T I2C I/O Extension Board", will it work?
What more changes do I have to make?

There are ways to do this between bus IO (SPI bus, I2C bus, RS485 bus) and "pin multipliers" like port expanders, driver ships and daisy-chained shift registers (how 8x8x8 RGB led cubes were run by Uno's before WS28xx came along).

Dallas Semiconductor has a large catalog of I2C devices including sensors. You might connect 127 devices on 2 pins... if you don't need really fast IO.

Oh, you haven't scratched the surface yet, but Necessity is The Mother of Invention!

Yeah, should work, although it only gives you an additional 8 IO's. An MCP23017 takes up the same amount of space and resources, but will give 16 GPIO's, so I always use that. However, if you're only one or two IO's short, the PCF8574 will be fine.

I would suggest not using the IO expander for the DHT11, the SR04 and the servo. It'll work alright, but you may have to be a little creative with coding (maybe modifying a library here and there, even) to get this to work. It'll be easier to move the IR modules and/or the buzzer to the GPIO board instead.

If you use an expander with more than 8 ports (e.g. MCP23017), you can free up a pair of digital pins on your Arduino so you can connect the HC05 to those and run a SoftwareSerial port on those pins. That way, you can use D0 and D1 for the Serial monitor and this won't be interfered with communication to/from the HC05.

Also, in your diagram you have connected the IO expander to two of the analog ports of your Arduino; that won't work. The SDA and SCL pins will be shared with the BMP280 sensor. There will be not conflict since each device has its own unique address on the I2C bus; you can simply connect these wires together (i.e. A4 goes to SDA on both the BMP280 + PFC8574, A5 goes to SCL on both boards; the same applies if you use an MCP23017 port expander instead of the PCF).

What are shift registers and daisy-chaining?

One example video.

Infinite pins for Arduino? Video.

8 RGB leds run by 24 added pins. Video.

There are INPUT Shift Registers and even bi-directional shift registers.

And then there's I2C bus. 2 pins, many devices.

Multiple devices on I2C Video.

scratch scratch

Greatly appreciate your answer. I changed the schematic according to your advice. Is there anything that needs to be altered?

The battery is connected to the L298N Motor Driver Module through its +12V terminal. And obviously the 4 motors are also connected to the driver module.
There is a +5V out in the motor driver. I am powering the arduino by connecting its VIN port with that +5V.

Will I power all the modules through that +5V of motor driver also? or will I use a buck converter and connect the modules to the battery through it? or will I power the modules through +5V out of arduino.

Looks OK; you could even more the two line tracking IR sensors to the expander, but it's optional. It should work this way, too, if you keep in mind the pins you've connected to them now are analog pins. I don't think digitalRead will work on A6/A7 (never tried to be honest) so you may have to do with an analogRead and a comparison.

No, that's not correct. If you have +5V coming from the motor driver board, you can/should put that directly on the 5V pin of the Arduino, not on Vin.

Yeah, should work alright.

That'll work, too. In fact, that's ultimately preferable because the regulator on the motor driver board is probably not really intended to run e.g. MG90's etc, although you might just get away with it. Just observe if the regulator on the motor driver board gets very hot; if so, you'll need to choose a different solution.

If you power the Arduino with 5V from the motor driver, then any modules connected to that same 5V net will also be powered by the motor driver.

When you start building this thing, start with the Arduino and a single module and try to get that to work first. Then add another module, get that to work, etc. Don't try to build the whole thing at once; odds are you'll make a mistake somewhere and won't be able to locate the error because you don't know where to look. Start small.

Correct.

https://forum.arduino.cc/t/nano-a6-a7-as-digital-i-o-reference-needed/856654/16

1 Like