Introduction
Being a Web application developer and with the huzz buzz going on around about IOT, I felt left out way behind in the crowd. So, I decided to start my journey on learning the IOT. Since I am a baby in this arena, I would keep sharing my crawling experience as I believe there would be many who would be waiting to crawl.
I have decided to use ARDUINO board in order to start my learning experience. Why!! Because it is economical, easy & has its own IDE to let us write the code and upload to the board. Let's learn something about Arduino first.
ARDUINO
Arduino is a simple micro-controller which is based on input output receiving unit. We can have it attached to any sensors, leds, switches, etc. The best part is it is open source and easy to understand and use. You can also contribute to the Arduino community, creating your own prototype programming. For beginners, Arduino is the best option, I would say!
To get started with, you would need an Arduino Board first. :P So get it online at a very minimal rate, for around Rs. 500 (Indian currency!). I would be using Arduino UNO board.
The above is the simple Arduino Board which does miracles. Let's understand the points mentioned in the diagram and their usage!
For more information on the pins, please refer to Arduino Pins.
So this is it about the Arduino board, a brief summary I would say. There is much more to this. Please refer here.
Some Pre-requisites
Here are some pre-requisites required to learn and start on the work with the Arduino. After you get the Arduino board from the market, the next job is to install the Arduino IDE on your system in order to interact with the microcontroller.
To install the IDE, visit the link: Arduino IDE Download. Here, you get a list of OS where you can install, this proves it is cross platform! :O Wow!! Another great feature!
After the installation, you need to connect the USB jack to the computer via the jack cord and get the Arduino connected.
The IDE somewhat looks like:
Mark the highlighted portion below, it says Arduino UNO on COM3. COM3 is a serial port id, which suggests we select the Board connection on COM3 port.
For getting on with MAC, please follow the link here. The selection is to be done under:
Tools-> Port-> "Select"
The default code as you see goes like:
void setup() {
}
void loop() {
}
Pretty simple to understand. It first does the set up and then the loop code gets executed in order to perform the main task you have configured. There are many sample programs inbuilt with the code, which we can find under
Files->Examples->Basic->Blink.
Run the Blink program and try to understand what has been done. It is very simple.
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(13, LOW);
delay(1000);
digitalWrite(13, HIGH);
delay(1000);
}
Here, the pinMode
function activates the pin which you specify as input or output. Here it is Pin 13 and is Output. Pin 13 is as we all know the default LED. Here it sets the pin and then in loop method, we find the method with digital-Write prefix, which says that the connection is on the Digital pins. The method, which we see has the Pin port number and the other parameter as LOW/HIGH which can be considered as 1/0 in order to light up and light off the LED 13. Delay has been given, to mention the Led light up with the specified delay time.
Before checking build up which we will be making in due course, let's have a look at the other components to be used.
- Bread Board: The board which is familiar to all electrical or engineering students also.
Still let's have a brief of this. As we see in the image, + symbol, meaning the voltage connection to be done to this port. The entire line, column wise is connected. Every whole in the plus column is connected internally. You can use a multimeter to check and verify the bread board.
Same applies for the - symbol column. But, this is usually used for the grounded pins connection from the Arduino. The a,b,c,d.. columns are used to connect the Leds and the resistors, which we will see in a while. Unlike the +/-, these are connected internally ROW-WISE.
- Jumper Wires: These are the connecting wires to be used in order to connect the Arduino and the bread board ports. They are cheap and reliable as well. They look like:
- Few LEDs and resistors.
Next is to design our circuit, which looks like:
The above is the basic bread board connection circuit. I will give a pictorial image of the entire circuit connection. In this article, I will be sharing how to take user inputs through the Serial port and use it to Lid on and off the LED. The circuit connection looks like below:
The connection diagram goes below:
The above diagram is a reference. For any doubts, you can add your queries related to the connections.
As you have seen, I have used Pin 13 to connect the Arduino program to the Bread board. That is the programming uploaded will be used to manipulate the LED on/off via Pin 13. Let's have a look at the code involved:
int userInput = 0;
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
userInput = Serial.read();
Serial.print("Received Input: ");
Serial.println(userInput, DEC);
}
if(userInput==49){
digitalWrite(13, HIGH);
delay(1000);
}else{
digitalWrite(13, LOW);
delay(1000);
}
}
Thus, the above code is simple to understand. We have used the Serial port to track the user input, which is a part of the Arduino IDE.
Here, the user adds the input and our code checks, if 1 with ASCII code 49, is hit then the LED lights ON and any other key pressed the LED goes OFF.
Conclusion
We have covered a brief introduction about Arduino board and the circuits involved and basic programming uploaded to the Arduino board via Arduino IDE. This same concept can be integrated to check for the movement in a room and if no movement switch off the room's MCB using Motion detection sensors! This is it all folks! I really found this interesting and this is surely the future! IOT is the future. I wish to come up with more sensors attached and programming done! I will do my homework! It would be great if all developers start throwing their hands on this and create miracles!! Share your experience and also please rectify me if I am wrong! I am still in the womb.