Can I connect the GND lines of each sensor to a single Arduino GND pin? As Arduino has several GNDs I don't know if I can only connect one per pin.
I have two motors that I will use with 9V and I will connect them to the 12V input of the L298N.
My question is regarding the GND of the L298N. Is it connected only to the battery or should I also connect it to the arduino? I ask because I see several images, in one it is connected and in another it is not.
A 9 volt battery cannot supply enough current for very long. For a real project, make sure the motor power ground goes directly back to it's negative of it's power supply and use a wire size that will carry the motor current. Use a separate wire to connect the signal ground to the power ground.
I use a step-down voltage at 9V, it is not a small battery, it is a 9,000 mAh battery.
I didn't understand the last thing you said. Imagine that I have a ground wire, I will connect that wire with the negative battery, with the GND of L298N, and with the GND of the arduino and all the other sensors. That tells me @LarryD it's possible, right?
For your project, all negatives and grounds connected together.
For future projects where something like motors that use a lot of current, use appropriate sized wire for + and - to the motors and/or controllers, but use your smaller wires for all other connections.
Still use the smaller wire to make one connection between the high current - and the smaller wire - so all grounds are electrically connected. You do not want the high current and the small signal current to share the same wire, only connect at one point.
Correct me if I'm wrong, please (remember I'm new, sorry if it's basic). You tell me to connect the small wires to the arduino and the big ones to the motor and battery, right? That is, do not use the same size cables.
But what if all the cables are very thick? Would something bad happen or just for aesthetics?
Every wire and every connection has resistance, no matter the type of connection or even if soldered or welded. Ohms law states there will be a voltage produced whenever electrical current flows through a resistance. When a high current pulse flows through even a tiny resistance, a voltage is created at that point.
If your Arduino signal also must pass through that connection, it will naturally see that same voltage pulse. If your Arduino pin connected to that signal wire is looking for a pulse on that wire in order to trigger an interrupt, that voltage pulse will trigger the interrupt, even though there was no signal from an attached sensor.
Same applies if your Arduino signal is being watched by an analog pin. That pin will now see the voltage pulse as it is measuring the voltage and will add to or subtract that voltage from what the signal voltage actually is.
In those case you have a condition that is not expected and might confuse the Arduino program. Very hard to debug!