For example if we take a 2 input AND gate . And want to apply 0 and 1 to the input terminals ..one terminal will be connected to a voltage source . But the other terminal where logic 0 is to be given , why do we ground it . Logic 0 means low voltage than logic 1 . Why can't we just let the other terminal hang freely in air ....not connected to anything ..Will it not have zero voltage when in contact with air ?
Will it not have zero voltage when in contact with air ?
No, it will not. Imagine an isolated node (input of an AND gate). If some charge get trapped on that node it cannot go anywhere. The node will have some voltage and a charge. That charge can be enough to open a MOSFET (and most AND gates use MOSFETs) which will influence the behavior of the AND gate.
Leaving logic gate inputs open / floating is an extremely bad habit as that makes the input undefined. The input does not have to be grounded, it can also be connected to the supply voltage. The connection can also be made through a resistor as long as the charge is not trapped on the gate's input.
But what if I simply discharge the input and then let it float?
Won't work either because there are ALWAYS leakage currents and non-ideal isolators (like MOSFET gate oxide) which cannot prevent some charge to accumulate on the input. So after some time there will still be some unknown charge on that input giving it some unknown voltage. Who knows what can happen then? No one knows, so the input needs a connection.
The reason is electromagnetic fields. Instead of seeing current flowing in wires, another way to see reality is as a universal sea of electromagnetism which is, um, channelled by wires and components. It's everywhere. Our electrical circuits operate in this context.
In fact I have this joke that electronic circuit design is about building radios that may do other things. This is very noticeable with any audio circuit where you can randomly and very easily pick up radio stations just by letting wires "hang" in the air, or having unshielded wires, or just touching bits of it with a finger.
High impedance inputs like logic gates only need a tiny current to drive them (in that case, to logic 1 or 0). Dipping into the ocean of electromagnetism as they are, they will easily drive as they pick up EM fluctuations, like little radio receivers (not really "like"- they are little radio receivers). They will oscillate. Current will flow in them. This means the transistor spends most of its time in a state of somewhere between on and off, which means some current is flowing in its output stage, which means two things;
Firstly it will produce random results at the output. Secondly, it will dissipate power as heat.
So to avoid this, you "lock" it to a steady voltage from a low impedance source to ensure that the stray fields of this ocean of electromagnetism we live in cannot drive it.
Broadly speaking, much of circuit design involves avoiding building radios. Unless you actually want a radio. Which is presumably why the point where "electrics" became "electronics" was when humanity started building radios.
Unconnected inputs can float, randomly switching between 0 and 1, especially in modern electronics where it takes less than 1uA of current to drive an input. Floating inputs can cause the extra switching after the input. In a CMOS chip, switching states uses current. To keep things at low power, one wants to avoid unneeded switching.
Earth is a very big conductor . When you ground the base terminal , all the charge flows to the ground and you have 0 volts at the base and transistor is in cut off region. But now you have a wire that is hanging in the air. The electrons see an infinite potential barrier at the free end so they can't escape into the air. It's like a wall of infinite potential that you can't cross. Now if an electromagnetic wave comes then it induces oscillating currents on the surface and inside the wire , also producing an electric field and hence a voltage drop at base terminal of the transistor making it's input 1 .