In the present day, the microcontroller is ubiquitous. Even though we may not see it, one or many of the household appliances that are used everyday, is using a microcontroller to become a “smart” and “intelligent” device. TV’s, Set Top boxes, Microwave ovens, Washing machines are some of the examples which instantly spring to mind.
Why do you need to learn about microcontrollers?
If you are an engineering student, the embedded systems domain is the best place to be in right now. It is growing at a frantic pace. Where ever you go, you are sure to hear the words “Automation”. Be it in a factory or at some office, everything is getting automated. Microcontrollers are at the heart of “Automation”. It works as the brain of the system. In factories, usually PLC(Programmable Logic Controllers) are used. PLC’s may look huge compared to a tiny microcontroller, but do not get intimidated. If you know microcontrollers, learning PLC’s is very easy.
But if you are not a student, what then? Is it worth the time and money that you have to invest?
Remember the times when you are feeling very sleepy and have almost no energy to get up and turn off the light and wished you had a remote by which you could turn off the light. But when you went to the market and enquired about such a device, they quoted such a big figure that leaving the light on and falling asleep seemed the cheaper option. Guess what; building such a remote controlled system is quite easy. But that is if you know microcontrollers. Microcontrollers and their programmers can be bought quite easily both online and from the electronics market in your city.
You must be bored by now. So I will stop lecturing you about why you need to learn these and go on to the next section.
Some example scenarios
If we think in very simple terms, a microcontroller can be thought of to be a set of switches whose position in the circuit can be changed by the user.
If in the above circuit, we want to turn on the light, we close the switch. This allows the current to flow from the source to the device and to ground, which completes the circuit and allows it to work.
The microcontroller can act as the switch and we can open/close the switch based on whatever criteria you want.
Now let us complicate matters a bit. Many people keep their lights on even during the daytime, even when there is ample sunlight in the room. Let there be a light sensor which detects the amount of light in the room. The microcontroller senses the output of the sensor. If the sensor detects there is enough light in the room, the microcontroller opens a switch and if there isn’t enough light, it closes the switch. If we place these two in series, like in the circuit below, we can make an interesting thing happen.
When there is sufficient light in the room, the microcontroller keeps the switch open. So even if the other switch is closed, the circuit cannot be completed. And since the current cannot jump over discontinuities, power cannot reach the bulb. So the bulb cannot be turned on when there is more than enough light. But if the light in the room falls below the threshold level, the controller will close the switch and complete the circuit thereby allowing the light to glow.
In digital electronics this is known as AND logic.
In this type of logic, only when both input are high, the output is high. In all other cases, the output is low.
Let us consider another scenario. There are two rooms. There is a smoke/fire detector in each room. They are connected to a microcontroller which senses their output. To the controller, an alarm is also kept connected, which will alert the nearby fire station. When the smoke detector detects a fire, it closes the switch. So if there is a fire in any one of the room or in both rooms, the alarm should be sounded.
In the following circuit, the alarm is represented by a bulb.
Even if one of the switches closes, the circuit will be completed. In digital electronics this is known as OR logic. When both of the inputs are low, the output is low. Otherwise the output is high.
The AND/OR logic required for performing many mathematical operations, which will be taken up in the next tutorial.