A common mistake for people new to electronics is to have 2 circuits fed from different power supplies with signals passing between the circuits, but with the grounds not connected. This leads to questions asking why the project doesn't work. You don't have to spend long reading the questions on this forum to see this is asked often. Here I attempt to explain the problem and why it matters to connect the grounds. Note that in all of the schematics that follow I have used a battery as a power supply but this is not important; the power supply could by anything that can supply the appropriate DC voltage. What is important is how the power supply is connected.
Electrical circuits are called 'circuits' because for them to work there has to be a complete, uninterrupted circuit all the way around and back to the power supply. Not just any power supply, the power supply that is supplying that bit of the circuit.
Consider these two circuits with a power supply and LED:
In the top circuit the LED does not light as the circuit is not complete and the current cannot flow all the way round. The bottom circuit is complete and the current can flow, lighting the LED. This is an important principal and applies to all circuits, however complex, including micro-controllers, which are very complex inside.
This schematic shows 2 devices connected to separate power supplies and with a signal between them.
Device 1 has an output connected to an input on device 2. In this schematic the ground of device 1 is not connected to device 2, which means there is no complete path for current to flow; so the signal connection between the two devices does not work as the circuit is not complete.
In this schematic the grounds are connected:
Now the signal from device 1 to device 2 has a complete circuit from the power supply of device 1, through the output of device 1 to the input of device 2 and then back to device 1's power supply. The circuit is complete and will work.
What is ground?
There is a common related misunderstanding associated with this about what counts as ground. Ground is a point in the circuit designated by the circuit designer as being the point against which all voltages in the circuit are measured in relation to. Ground can also be known as 0(zero)V. Ground is often, but does not have to be, the negative pole of the supply. Ground could be the positive pole of the supply or the mid point of a split supply. Ground is not a point on a particular component, for example the negative (or positive) pole of a battery is not ground.
Thank you Robin 2 and Ballscrewbob for your help with this tutorial.