IOT — Getting Started #04

Aditya Narain Gupta
4 min readJan 2, 2018

--

In the previous blog we had discussed about Arduino development board one of the component of Arduino environment. In this blog we will be covering its other component it’s software environment ‘Arduino IDE’.

You can download and install Arduino IDE from arduino.cc/en/Main/Software . It’s a open source software available for all OS (Windows, Linux, Mac). After installation on opening you can see similar window (I’m using Windows version).

Arduino Sketch

Arduino IDE (Integrated Development Environment) has a cross compiler which compiles the sketch for target platform. For eg. in case of Arduino Uno its ATmega328.

Let me introduce you to five important basic features of IDE.

  1. Arduino Sketch: Area where a programmer writes an application code.
  2. Message Area: An area where a completion message like compiling done or done uploading appears and error message appears with line numbers which help the programmer rectify errors.
  3. Verify button: It compiles the code and check for programming errors.
  4. Upload button: This button compiles the code, check for errors and upload the code to board. It’s both in one scoop (verify & upload).
  5. Serial Monitor: Opens a window to communicate with board.
    Embedded devices don’t have screens. If we want to send data or read data from device we can directly do this by the serial monitor.

Arduino is programmed mainly in C with little bit of C++. Every Arduino Sketch has two important and necessary functions: Setup() and loop().

You may be thinking: in Arduino we are using C & C++ but we are not having any main function and as execution always start from main function so how the code executes. The answer is quite simple Arduino sketch looks different from actual C code but in this also main function is created automatically in backend at the time of compilation.

Let us now discuss two must functions of Arduino Sketch:

  1. Setup() Function:

Void setup() {
……
}

This function is executed only once as soon as the device is powered. It is used for initialization operations like to setup serial communications, set pin modes, etc. It’s a void function i.e. it doesn’t return any value, at the same time nor take any arguments.

2. Loop() Function:

Void loop() {
……
}

This function executes after the setup function and continues iteratively as long as the Arduino is powered. In an infinite loop. This function consist of actual application code written inorder to perform the desired task.

If you have doubt why this infinite function is required here is simple answer to that:
The IOT devices have to be operated in an infinite loop as they constantly have to wait for input to trigger some action as long as the system is powered.

This was all about the IDE that you must know, lets now learn how to upload/flash code to Arduino with a simple hands-on.

Lets write a simple code for blinking of LED.

int led = 13;
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
}

void loop() {
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
}

In order to learn coding and predefined function do refer here. Its a advice to go through the functions atleast once as it will help you to learn and understand coding part easily.

Setup for LED Blinking
It’s a very simple setup connect anode of LED (longer wire) to pin 13 and cathode to GND of Arduino. Connect your Arduino with Arduino Uno cabel to your host (Desktop/Laptop).

So we have our code and setup ready. Time to flash code.
Here are two tips always keep in mind, these will protect mistakes which we often make.

  • Make sure you have selected the correct board you are using from tools in menu bar.
    Tools →Board → Arduino Uno (choose the board you are using)
  • Make sure a port is selected and a correct one otherwise code will not upload.
    Tools →Port → COM3 (choose the port available in your system like COM5, COM8, /dev/ttyUSB0(for linux))

If any of these points is missed the code will not compile or will not upload.

Now, click on upload button. This button will verify and upload the code to Arduino. You can see message ‘compiling sketch’ in message area at time of verifying and ‘uploading sketch’ at time of uploading code arduino and ‘Done uploading’ when code is uploaded.

Woaah, I hope you can see LED blinking now.
I believe this was very simple for you. Now explore the internet search for new innovative ideas and bring them to reality.

If you see any errors in message area or face any problem first Google search it to resolve, try your best, if then also problem is not solved I’m here to help you.

In the next blog I’ll be bringing one project on Embedded system later we will transform that project into IOT project.
Now you are at a level with required theoretical knowledge to go for practical learning. So do some crazy hacks now.

If you have any doubts/queries do mention them in comments.
If you have want to follow the series, make sure to follow this account for regular updates.

Link to previous blog on Arduino Uno.

Link to next blog on Automatic Irrigation System.

--

--