IoT Module 2
IoT Module 2
Arduino UNO
The Arduino UNO is a standard board of Arduino. Here UNO means 'one' in Italian. It was named as UNO to label the first release of
Arduino Software. It was also the first USB board released by Arduino. It is considered as the powerful board used in various projects.
Arduino.cc developed the Arduino UNO board.
Arduino UNO is based on an ATmega328P microcontroller. It is easy to use compared to other boards, such as the Arduino Mega board,
etc. The board consists of digital and analog Input/Output pins (I/O), shields, and other circuits.
The Arduino UNO includes 6 analog pin inputs, 14 digital pins, a USB connector, a power jack, and an ICSP (In-Circuit Serial
Programming) header. It is programmed based on IDE, which stands for Integrated Development Environment. It can run on both online
and offline platforms.
○ There are 20 Input/Output pins present on the Arduino UNO board. These 20 pis include 6 PWM pins, 6 analog pins,
and 8 digital I/O pins.
○ The PWM pins are Pulse Width Modulation capable pins.
○ The crystal oscillator present in Arduino UNO comes with a frequency of 16MHz.
○ It also has a Arduino integrated WiFi module. Such Arduino UNO board is based on the Integrated WiFi ESP8266
Module and ATmega328P microcontroller.
○ The input voltage of the UNO board varies from 7V to 20V.
○ Arduino UNO automatically draws power from the external power supply. It can also draw power from the USB.
● Arduino’s processor basically uses the Harvard architecture where the program
code and program data have separate memory.
● It consists of two memories- Program memory and the data memory.
● The code is stored in the flash program memory, whereas the data is stored in the
data memory.
● The Atmega328 has 32 KB of flash memory for storing code (of which 0.5 KB is
used for the bootloader), 2 KB of SRAM and 1 KB of EEPROM and operates with
a clock speed of 16MHz.
Setup IDE
The Arduino software (IDE) is open-source software. We are required to write the code and upload the code to the board to perform some task.
The Arduino IDE software can be used with any type of Arduino boards. The software is available for various operating system such as, Windows,
Linux, and Mac OS X.
1. Go to the official website of Arduino (https://www.arduino.cc/) > Click on SOFTWARE < click on DOWNLOADS, as shown
below:
2. A page will appear, as shown below:
3. Scroll the screen a little, as shown below:
4. Click on the 'Windows Installer' as we are operating
with the Windows. We can select the Linux or Mac OS X,
accordingly.
5. A contribution window will appear. We can
contribute according to our choice and click on the
'CONTRIBUTE &DOWNLOAD' option.
Otherwise, click on the 'JUST DOWNLOAD' option,
as shown below:
6. The downloading process will start. The downloading file will look like the below image:
10. Accept the license by clicking on 'I Agree' button, as shown below:
11. Click on the 'Next' button. It is shown below:
12. The window specifying the location of the installed folder will appear.
13. The installing process of Arduino will start, as shown below:
Wait for the installation process to complete.
14. Now, we have to accept the security for the installation. We are required to accept the security Installation three times.
The Arduino IDE software will appear on your desktop, as shown below:
20. The Arduino IDE environment is written in the programming language named as Java. So, we need to allow access to
the Java Platform.
As soon we open the Arduino software, a license window will appear, as shown below:
Accept the license by clicking on the 'Allow access' button.
21. The Arduino window will appear as:
Writing Arduino Software
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code,
a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the
Arduino hardware to upload programs and communicate with them.
Writing Sketches
● Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and
are saved with the file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The
message area gives feedback while saving and exporting and also displays errors.
● The console displays text output by the Arduino Software (IDE), including complete error messages and other
information. The bottom righthand corner of the window displays the configured board and serial port. The toolbar
buttons allow you to verify and upload programs, create, open, and save sketches, and open the serial monitor.
● Versions of the Arduino Software (IDE) prior to 1.0 saved sketches with the extension .pde.
● It is possible to open these files with version 1.0, you will be prompted to save the sketch with the .ino extension on
save.
Arduino libraries
Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. To use a library in a sketch, select
it from the Sketch > Import Library menu. This will insert one or more #include statements at the top of the sketch and compile the library
with your sketch. Because libraries are uploaded to the board with your sketch, they increase the amount of space it takes up. If a sketch no
longer needs a library, simply delete its #include statements from the top of your code.
1. Robotics
2. Communication
SPI - for communicating with devices using the Serial Peripheral Interface (SPI) Bus.
Wire - Two Wire Interface (TWI/I2C) for sending and receiving data over a net of devices or sensors.
SoftwareSerial - for serial communication on any digital pi
3. Connectivity
Libraries to access radio modules on different IoT boards (Wi-Fi, Bluetooth®, LoRa®, GSM, NB-IoT, Sigfox).
● ArduinoIoTCloud - This library allows to connect to the Arduino IoT Cloud service. .
● ArduinoBLE - library to use the Bluetooth® Low Energy on a selection of boards.
● Ethernet - for connecting to the Internet via Ethernet.
● GSM - for connecting to a GSM/GRPS network with the GSM shield.
● MKRWAN - library for MKR WAN 1300/1310, for connecting to LoRaWAN® networks.
● MKRGSM - library for MKR GSM 1400, for connecting to GSM/GPRS networks.
● MKRNB - library for MKR NB 1500, for connecting to NB-IoT / Cat M1 networks.
● SigFox - library for MKR FOX 1200, for connecting to the Sigfox network.
● WiFi - library for the WiFi shield, for Internet connections via Wi-Fi.
● WiFi101 - library for the MKR 1000 WiFi and WiFi101 shield, for Internet connections via Wi-Fi.
● WiFiNINA - library for boards with a Wi-Fi NINA module, for Internet connections via Wi-Fi.
4. Memory
5. Display
● AudioFrequencyMeter - library to sample an audio signal and get its frequency back.
● AudioZero - library to play audio files from a SD card.
● ArduinoSound - simple way to play and analyze audio data.
● Audio - allows playing audio files from an SD card. For Arduino DUE only.
● I2S - library for using the I2S protocol on SAMD21 (included in SAMD platform).
7. USB
Other
● Firmata - for communicating with applications on the computer using a standard serial protocol.
Basics of Embeded C programming for arduino
What is an Embedded System?
● An Embedded System can be best described as a system which has both the hardware and software and is
designed to do a specific task.
● A good example for an Embedded System, which many households have, is a Washing Machine.
● We use washing machines almost daily but wouldn’t get the idea that it is an embedded system consisting of a
Processor (and other hardware as well) and software.
● Embedded C Programming Language, which is widely used in the development of Embedded Systems, is an
extension of C Program Language. The Embedded C Programming Language uses the same syntax and semantics
of the C Programming Language like main function, declaration of datatypes, defining variables, loops, functions,
statements, etc.
● The extension in Embedded C from standard C Programming Language include I/O Hardware Addressing, fixed
● There is actually not much difference between C and Embedded C apart from few extensions
and the operating environment. Both C and Embedded C are ISO Standards that have almost
same syntax, datatypes, functions, etc.
● Embedded C is basically an extension to the Standard C Programming Language with additional
features like Addressing I/O, multiple memory addressing and fixed-point arithmetic, etc.
● C Programming Language is generally used for developing desktop applications, whereas
Embedded C is used in the development of Microcontroller based applications.
Keywords in Embedded C
A Keyword is a special word with a special meaning to the compiler (a C Compiler for
example, is a software that is used to convert program written in C to Machine Code).
For example, if we take the Keil’s Cx51 Compiler (a popular C Compiler for 8051
based Microcontrollers) the following are some of the keywords:
● bit
● sbit
● sfr
● small
● large
The following table lists out all the keywords associated with the Cx51 C
Compiler.
Data Types in C Programming Language (or any programming language for that matter)
help us declaring variables in the program. There are many data types in C Programming
Language like signed int, unsigned int, signed char, unsigned char, float, double, etc. In
addition to these there few more data types in Embedded C.
The following are the extra data types in Embedded C associated with the Keil’s Cx51
Compiler.
● bit
● sbit
● sfr
● sfr16
The following table shows some of the data types in Cx51 Compiler along with their
ranges.
Basic Structure of an Embedded C Program (Template for Embedded C Program)
The next thing to understand in the Basics of Embedded C Program is the basic structure or Template of Embedded C Program. This will help us in
understanding how an Embedded C Program is written.
● Comments: Comments are readable text that are written to help us (the reader) understand the code easily. They are ignored by the
compiler and do not take up any memory in the final code (after compilation).
There are two ways you can write comments: one is the single line comments denoted by // and the other is multiline comments denoted
by /*….*/.
● Preprocessor Directive: A Preprocessor Directive in Embedded C is an indication to the compiler that it must look in to this file for
symbols that are not defined in the program.
In C Programming Language (also in Embedded C), Preprocessor Directives are usually represented using # symbol like #include… or
#define….
In Embedded C Programming, we usually use the preprocessor directive to indicate a header file specific to the microcontroller, which contains
all the SFRs and the bits in those SFRs.
In case of 8051, Keil Compiler has the file “reg51.h”, which must be written at the beginning of every Embedded C Program.
● Global Variables: Global Variables, as the name suggests, are Global to the program i.e., they can be accessed anywhere in the program.
● Local Variables: Local Variables, in contrast to Global Variables, are confined to their respective function.
● Main Function: Every C or Embedded C Program has one main function, from where the execution of the program begins.
Interfacing LED
PUSH Button
For the circuit you will need:
● Arduino board
● Breadboard
● Some wires
● Push button