Lab Manual - RA3CO35 - Embedded Systems
Lab Manual - RA3CO35 - Embedded Systems
MEDICAPS UNIVERSITY
INDORE (M.P.)
LABORATORY MANUAL
Embedded Systems
(RA3CO35)
V SEM
Study the Temperature sensor and Write Program for monitor temperature using Arduino.
4
its IDE.
Theory:
Arduino is an open-source hardware and software company, project and user community that designs and
manufactures single-board microcontrollers and microcontroller kits for building digital devices and interactive
objects that can sense and control objects in the physical and digital world. Its products are licensed under the
GNU Lesser General Public License (LGPL) or the GNU General Public License (GPL), permitting the
manufacture of Arduino boards and software distribution by anyone. Arduino boards are available
commercially in preassembled form.
Arduino board designs use a variety of microprocessors and controllers. The boards are equipped with sets of
digital and analog Input / Output (I/O) pins that may be interfaced to various expansion and other circuits. The
boards feature serial communications interfaces, including Universal Serial Bus (USB) on some models, which
are also used for loading programs from personal computers.
The Arduino project started in 2003 as a program for students at the Interaction Design Institute Ivrea in Ivrea,
Italy, aiming to provide a low-cost and easy way for novices and professionals to create devices that interact
with their environment using sensors and actuators. Common examples of such devices intended for beginner
hobbyists include simple robots, thermostats and motion detectors.
The name Arduino comes from a bar in Ivrea, Italy, where some of the founders of the project used to meet. The
bar was named after Arduin of Ivrea, who was the margrave of the March of Ivrea and King of Italy from 1002
to 1014.
Arduino Boards:
Most Arduino boards consist of an Atmel 8-bit AVR microcontroller (ATmega8, ATmega168, ATmega328,
ATmega1280, ATmega2560) with varying amounts of flash memory, pins, and features. The 32-bit Arduino
Due, based on the Atmel SAM3X8E was introduced in 2012. The boards use single or double-row pins or
female headers that facilitate connections for programming and incorporation into other circuits. These may
connect with add-on modules termed shields. Multiple and possibly stacked shields may be individually
addressable via an I²C serial bus. Most boards include a 5 V linear regulator and a 16 MHz crystal oscillator or
ceramic resonator. Some designs, such as the LilyPad, run at 8 MHz and dispense with the onboard voltage
regulator due to specific form-factor restrictions.
Arduino microcontrollers are pre-programmed with a boot loader that simplifies uploading of programs to the
on-chip flash memory. The default bootloader of the Arduino UNO is the optiboot bootloader. Boards are
loaded with program code via a serial connection to another computer.
Description
Power USB
Arduino board can be powered by using the USB cable from your computer. All
you need to do is connect the USB cable to the USB connection (1).
Power (Barrel Jack)
Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack (2).
Voltage Regulator
The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and other
elements.
Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does
Arduino calculate time? The answer is, by using the crystal oscillator. The
number printed on top of the Arduino crystal is 16.000H9H. It tells us that the
frequency is 16,000,000 Hertz or 16 MHz.
Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning.
You can reset the UNO board in two ways. First, by using the reset button (17)
on the board. Second, you can connect an external reset button to the Arduino
pin labelled RESET (5).
-6-
AREF
AREF stands for Analog Reference. It is sometimes, used to set an external
reference voltage (between 0 and 5 Volts) as the upper limit for the analog input
pins.
Unsigned Unsigned
void Boolean char byte int word
char int
Unsigned String- String-
long short float double array
long char array object
void
The void keyword is used only in function declarations. It indicates that the function is expected to return no
information to the function from which it was called.
Boolean
A Boolean holds one of two values, true or false. Each Boolean variable occupies one byte of memory.
Char
A data type that takes up one byte of memory that stores a character value. Character literals are written in
single quotes like this: 'A' and for multiple characters, strings use double quotes: "ABC".
byte
A byte stores an 8-bit unsigned number, from 0 to 255.
int
Integers are the primary data-type for number storage. int stores a 16-bit (2-byte) value. This yields a range of -
32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1). The int size varies from board
to board.
Word
On the Uno and other ATMEGA based boards, a word stores a 16-bit unsigned number.
short
A short is a 16-bit data-type. On all Arduinos (ATMega and ARM based), a short stores a 16-bit (2-byte) value.
Long
Long variables are extended size variables for number storage, and store 32 bits (4 bytes).
float
Data type for floating-point number is a number that has a decimal point. Floating-point numbers are often used
to approximate the analog and continuous values because they have greater resolution than integers.
-8-
double
On the Uno and other ATMEGA based boards, Double precision floating-point number occupies four bytes.
void loop(): After creating a setup() function, which initializes and sets the initial values, the
loop() function does precisely what its name suggests, and loops consecutively, allowing your
program to change and respond. Use it to actively control the Arduino board.
Viva Questions:
1. What is Arduino?
2. What do you mean by Open – Source Hardware?
3. What are the different extensions for a file?
4. Can I Program the Arduino Board In C?
5. Can I Program an Arduino Board Without the Arduino Ide?
Viva Answers:
1. Arduino is an open-source hardware and software company, project and user community
that designs and manufactures single-board microcontrollers and microcontroller kits for
building digital devices and interactive objects that can sense and control objects in the
physical and digital world.
2. Open-source hardware is a term that refers to any type of device whose hardware
specifications are fully documented or otherwise available.
3. While creating a sketch in the Arduino IDE, you have access to a number of different file
extensions for use with your source code files. Each one has its own particular use:
a. .ino
b. .pde
c. .h
d. .cpp
e. .c
4. Arduino uses its own language to program Arduino boards, because its programming
language is easy to understand. But it can also be programmed in C language.
5. If you're not using Arduino IDE, you can't use Arduino syntax. You need to write your
code in C. You need to be familiar with AVR architecture for that. You will need a
compiler like WinAVR to generate the hex code file. Then you will need a software like
AVRdude to flash the hex code into your device.
INTERNET OF THINGS LABORATORY -9-
EXPT. No. – 2. Write program using Arduino IDE for Blink LED.
Theory:
LEDs are small, powerful lights that are used in many different applications. To start, we will work on blinking
an LED, the Hello World of microcontrollers. It is as simple as turning a light on and off.
Components Required:
You will need the following components
−
l 1 × Arduino Uno R3
l 1 × LED
l 1 × 330Ω Resistor
Note:
1. To find out the polarity of an
LED, look at it closely. The
shorter of the two legs, towards
the flat edge of the bulb indicates
the negative terminal.
2. Components like resistors need to have their terminals bent into 90°
angles in order to fit the breadboard sockets properly. You can also cut the terminals shorter.
Sketch:
Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit.
Open the new sketch; File New.
digitalWrite(2, HIGH) − When you are using a pin as an OUTPUT, you can command it to be HIGH (output 5
volts), or LOW (output 0 volts).
Viva Questions:
1. Which statement in the sketch describes that you are using the particular pin for Input / Output?
2. Can the Arduino board be programmed in C Language?
3. What is the Arduino Language?
4. What is the use of delay() statement? What is the unit used for measuring time?
5. Which Arduino Board have you used?
1. pinMode() statement in the sketch describes that we are using the particular pin for Input /
Output.
2. Arduino uses its own language to program Arduino boards,Because its programming
language is easy to understand. But it can also be programmed in C language.
3. The Arduino programming is done in C++ Language.
4. A delay statement is used to halt execution of the task for a specified duration or until a
specified time. the unit used for measuring time is seconds (specifically for Arduino
programming).
5. We have used Arduino UNO R3.
- 11 -
EXPT. No. – 3. Write Program for RGB LED using Arduino.
Theory:
The RGB LED can emit different colors by mixing the 3 basic colors red, green and blue. So it actually consists
of 3 separate LEDs red, green and blue packed in a single case. That’s why it has 4 leads, one lead for each of
the 3 colors and one common cathode or anode depending of the RGB LED type.
Components Required:
You will need the following components −
l 1 × Arduino Uno R3
l 1 × RGB LED
l 3 × 220Ω Resistor
l 1 × Breadboard
l Jump Wires
We can generate a wide range of colors using an RGB LED just by varying the brightness of the individual R, G
and B LEDs. In last Experiment, we have performed an experiment with blinking an LED using Arduino, where
the brightness of LED was controlled directly using the program.
The technique used to control the brightness of an LED is called Pulse Width Modulation or simply PWM.
PWM is a technique where the amount of power delivered to a device can be controlled accurately and
efficiently. PWM technique can be used to control the brightness of an LED, the speed of a motor or the
direction of a servo motor.
There are two important factors to consider when dealing with PWM Technique: Duty Cycle and Frequency.
Duty cycle indicates the duration for which the pulse is HIGH over it period. It is measured in percentage and it
indicates the voltage between OFF and ON levels (usually 0V and 5V).
In the loop function we will make our program which will change the color of the LED each second. In order to
get red light on the LED we will call the setColor() function and set value of 255 for the redValue argument and
0 for the two others. Respectively we can get the two other basic colors, green and blue. For getting other colors
we need to mix the arguments values. So for example if set all 3 LEDS to maximum brightness we will get
White color and we will get a purple color if we set the following values to the arguments: 170 redValue, 0
greenValue and 255 blueValue.
Viva Questions:
1. What values are used for R, G and B components to get White Light?
2. Which statement / function in your code is used to set the required color?
3. What is the pinMode() function?
4. What are functions in Arduino?
5. What are loops?
2. The RGB() function is used to set the required color by passing the red, green, blue
and brightness parameters.
4. Segmenting code into functions allows a programmer to create modular pieces of code
that perform a defined task and then return to the area of code from which the function
was "called". The typical case for creating a function is when one needs to perform
the same action multiple times in a program.
Aim: Study the Temperature sensor & Program for monitoring of temperature using Arduino.
Theory:
Technical Specifications:
l Calibrated directly in ̊ Celsius (Centigrade)
l Linear + 10.0 mV/ ̊C scale factor
l 0.5 accuracy guarantee able (at +25 ̊C)
l Rated for full −55 ̊ to +150 ̊C range
l Suitable for remote applications
l Low cost due to wafer-level trimming
l Operates from 4 to 30 volts
l Less than 60 μA current drain
l Low self-heating, 0.08 ̊C in still air
l Nonlinearity only±1⁄4 ̊C typical
l Low impedance output, 0.1Ωfor 1 mA load
Pin Description:
Pin No Pin Name Description
Input Supply
1 VCC
Input Voltage: 5V (+35 V to -2 V)
Temperature Sensor Analog Output
2 VOUT Output Voltage: (+6V to -1 V)
Output Current: 10 mA
Ground
3 GND
Device ground pin, connected to power supply negative terminal
Components Required:
You will need the following components:
1 × Breadboard
1 × Arduino Uno R3
1 × LM35 sensor
1 × 16×2 LCD Screen
Jump Wires
Procedure:
Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below.
Viva Questions:
1. Define LM35 Temperature Sensor.
2. What is a BreadBoard?
3. Name the pins along with the functions of the sensor used?
4. What are the advantages of the sensor over thermistor?
5. What is the use of analogRead() function and what parameter(s) does it take?
1. LM35 is a precision IC temperature sensor with its output proportional to the temperature.
The sensor circuitry is sealed and therefore it is not subjected to oxidation and other
processes. With LM35, temperature can be measured more accurately than with a
thermistor.
2. A breadboard is a rectangular plastic board with a bunch of tiny holes in it. These holes
let you easily insert electronic components to prototype (meaning to build and test an
early version of) an electronic circuit.
3.
4. The advantage of lm35 over thermistor is it does not require any external calibration.
Also, it operates within the widest temperature range and is more precise compared to
thermistor.
5. It is used to read the value from the specified analog pin.
Syntax: analogRead(pin)
Parameter: (pin): the name of the analog input pin to read from
- 17 -
EXPT. No. – 5. Study and implement MQTT protocol using Arduino.
Theory:
l MQTT(Message Queuing Telemetry Transport) is an ISO standard (ISO/IEC PRF 20922) publish-
subscribe-based messaging protocol. It works on top of the TCP/IP protocol. It is designed for
connections with remote locations where a "small code footprint" is required or the network bandwidth
is limited. The publish-subscribe messaging pattern requires a message broker.
l Andy Stanford-Clark of IBM and Arlen Nipper of Cirrus Link authored the first version of the protocol
in 1999.
l In 2013, IBM submitted MQTT v3.1 to the OASIS specification body with a charter that ensured only
minor changes to the specification could be accepted.
l MQTT-SN is a variation of the main protocol aimed at embedded devices on non-TCP/IP networks,
such as Zigbee.
l Historically, the "MQ" in "MQTT" came from the IBM MQ (then 'MQSeries') message queuing product
line. However, queuing itself is not required to be supported as a standard feature in all situations.
l Alternative protocols include the Advanced Message Queuing Protocol (AMQP), Steaming Text
Oriented Messaging Protocol (STOMP), the IETF Constrained Application Protocol, XMPP, DDS, OPC
UA, and Web Application Messaging Protocol (WAMP).
Example: Let’s say there is a device that has a temperature sensor. Certainly, it wants to send his readings to
the broker. On the other side, a phone/desktop
application wants to receive this temperature
value. Therefore, 2 things will happen:
l The device defines the topic it wants
to publish on, ex: “temp”. Then, it
publishes the message “temperature
value”.
l The phone/desktop application
subscribes to the topic “temp”. Then,
it receives the message that the device
has published, which is the
temperature value.
l Again, the broker role here is to take the message “temperature value” and deliver it to phone/desktop
application.
- 18 -
Components Required:
1. Arduino Board
2. DHT11 Sensor
3. ESP8266
4. NodeMCU
5. Resistor (between 4.7K and 10K)
6. Breadboard
7. female-to-female jumper wires
8. female-to-male jumper wires
9. 3 male-to-male jumper wire
Procedure:
Configuring Adafruit MQTT Broker:
To use the Adafruit MQTT Broker, we need
to first register to the io.adafruit.com. Once
registered, we can generate the credentials
required to connect the devices to the Broker.
Figure below shows the options available on
the MQTT broker once the user creates an
account on the io.adafruit.com.
The menu contains many options of which we
will be looking into Dashboard and Feeds.
l Dashboard is the place where we can
place all the feeds that are created in
one place that are related to a
particular project. There are many
interfaces that can be placed on the
dashboard once a dashboard and feeds
are created.
l Feed is a place where we can create
new feeds that are used to display the data from the IOT devices. The data in the feeds can be either
published or subscribed as per the requirement.
Viva Questions:
1. What is MQTT?
2. Explain the working of MQTT?
3. What is the use of setup() and loop() functions?
4. What is the difference between #include and #define?
5. What is MQTT Broker?
- 20 -