Connecting ground between L298 and Sensors

Hi everyone,
I'm quite new to Arduino but already amazed about the possibilities we can do :slight_smile:

I'm working on a little project with infra-red sensors. Long story short, when there is an obstacle between the sensors, my program stops the motor.
To pilot the motor, I'm using an old L298N driver.

Even though I found similar questions to mine, I cannot get a proper answer, and that's why I would need your help.
I created the following wiring schema.

My question is, how do I connect the ground to make sure it is the same between the 12V coming from the Barrel jack, and the 5V coming from the USB cable and the Arduino?

I appreciate the question might be trivial, but I couldn't find an answer.

Thanks in advance for your help! <3

Welcome to the forum

You connect a wire to the GND connector on the driver to a GND connector on the Arduino using the breadboard GND line if you want to. All of the GND connectors (the barrel, the pins labelled GND and the GND on the ICSP header) are already connected together

What part of that are you having a problem with ?

Hi UKHeliBob,
Thank for your kind words and your prompt reply!

My problem is that I'm not sure that all the GND are connected together, and I know it's important to do that (even though, I'm still having issues understanding exactly why).

So if I understood correctly your first sentence, I should change the wiring to the following, is that correct? I put the new cable in pink.

In addition, I'm not sure if all the GND on the Arduino board are the same. For instance, compared to my first wiring diagram, I changed the GND cable coming from the Arduino to the breadboard (it's the purple cable).
Is this configuration the same?

They are. All pins labeled 'GND' at the UNO are connected together. So it doesn't matter which one you use.

Thanks, MicroBahner!
So my last diagram is correct, and all the GND are properly connected if I understood you all? :slight_smile:

It's correct.
And you can connect the "pink" Gnd directly to arduino GND pin instead of breadboard (I expect your final setup doesn't use breadboards).

Now that you know what to do let's explain why you need to do it

If your project had a single power supply then all signal levels would be at voltages measured as the difference between the power supply GND and the point on the circuit being measured. However, your project has 2 power supplies at different voltages. 12V for the motors and motor controller and 5V for the Uno.

When the Uno sends signals to the motor controller they will be either at 0V or 5V with respect to the Uno GND but the motor controller has no way of knowing that or measuring it. By connecting the Uno GND to the motor controller GND it gives the latter the same base voltage level to measure the input against. This is usually known as a common GND

1 Like

Thank you, kmin for confirming! :slight_smile:

That's so great, UKHeliBob!
Thank you for explaining that to me it's way much more clear!

My only concern to be honest when it comes to wiring, is that I do something wrong and that I burn my laptop :confused:

It's very unlikely if you are careful. Never do wiring while connected to laptop, or any power source.

It's noted! :slight_smile:

Thank you all everyone, you have been fantastic!

I don't think your circuit is correct.

Those two thing I assume are an beam emitter and receiver.

The receiver is the one with the yellow wire on the right and the one on the left is the emitter. Now this seems to be connected directly to the power supply. This will / should burn it out. Get a new one, read the data sheet to it and find out what current it needs. Then insert a series resistor to make sure you are not over driving it.

Hi @Grumpy_Mike,
That's correct, these are beam emitter and receiver from Adafruit. :slight_smile: I followed the wiring instructions provided in the product page:

After reading carefully again, there is this sentence that I missed:

The receiver is open collector which means that you do need a pull up resistor. Most microcontrollers have the ability to turn on a built in pull up resistor. If you do not, connect a 10K resistor between the white wire of the receiver and the red wire.

I believe I understand why you are saying it will burn out, but I would like more details, if you don't mind.
In case it helps, the datasheet of that particular product is available here.

As I didn't know what a pull-up resistor was, I have done some research and came up with the following new wiring diagram. For what I understood, it's to ensure I always the same state for the sensor. In my case, it needs to be between the 5V and the Arduino pin for the data.

As a result, I came with the following new diagram. I'm still not sure if I cabled everything properly. More specifically, I'm not sure about the purple cable.
Could you please let me know if I need to do further modifications?

Thanks again for your support!

Does your code work?

Hi all,
So I believe I made the proper modifications regarding the wiring.

Here is the final diagram:

I also think that I'm using the internal pull-up resistor from the Arduino, thanks to the following line of code:

digitalWrite(SENSORPIN, HIGH);

Or maybe simply:

pinMode(SENSORPIN, INPUT_PULLUP);

Indeed, yes.
My void setup() looks as follows:

void setup() {
  pinMode(LEDPIN, OUTPUT);
  pinMode(SENSORPIN, INPUT);

  digitalWrite(SENSORPIN, HIGH); // pull-up
}

Both work, but your code can confuse someone....

Oh?
How come? Would you mind detailing a bit more? I'd like to have a clean code :slight_smile: