IoT Manual-1
IoT Manual-1
CERTIFICATE
This is to certify that Mr / Miss ________________________________of Third
Year Electrical Engineering branch, Roll No. ______has performed practical work
satisfactorily in the Subject IoT and Its Applications in Electrical Engineering
Laboratory (PEEE5052L), in the premises of the Department of Electrical
Engineering during the academic year 20 - 20
Date: / / 20
Place: Shirpur
Table of Contents
Exp.
Title P. No. Date Sign
No.
Perform any 10 experiments from the following list of experiments
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 1
Aim: Study and Install IDE of Arduino and different types of Arduino.
Theory:
Arduino is a prototype platform (open-source) based on an easy-to-use hardware and software. It
consists of a circuit board, which can be programed (referred to as a microcontroller) and a ready-
made software called Arduino IDE (Integrated Development Environment), which is used to write
and upload the computer code to the physical board.
The key features are:
• Arduino boards are able to read analog or digital input signals from different sensors and turn it
into an output such as activating a motor, turning LED on/off, connect to the cloud and many
other actions.
• You can control your board functions by sending a set of instructions to the microcontroller on
the board via Arduino IDE (referred to as uploading software).
• Unlike most previous programmable circuit boards, Arduino does not need an extra piece of
hardware (called a programmer) in order to load a new code onto the board. You can simply
use a USB cable.
• Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to
program.
• Finally, Arduino provides a standard form factor that breaks the functions of the
microcontroller into a more accessible package.
Board Types
Various kinds of Arduino boards are available depending on different microcontrollers used.
However, all Arduino boards have one thing in common: they are programed through the Arduino
IDE.
The differences are based on the number of inputs and outputs (the number of sensors, LEDs, and
buttons you can use on a single board), speed, operating voltage, form factor etc. Some boards are
designed to be embedded and have no programming interface (hardware), which you would need
to buy separately. Some can run directly from a 3.7V battery, others need at least 5V.
Here is a list of different Arduino boards available.
USB via
Arduino Uno R3 5V 16MHz 14 6 6 1
ATMega16U2
FTDI-Compatible
Arduino mini 05 5V 16MHz 14 8 6 1
Header
FTDI-Compatible
Arduino Ethernet 5V 16MHz 14 6 6 1
Header
FTDI-Compatible
Arduino Fio 3.3V 8MHz 14 8 6 1
Header
ARDUINO – INSTALLATION
Step 1: First you must have your Arduino board (you can choose your favorite board) and a USB
cable. In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560, or
Diecimila, you will need a standard USB cable (A plug to B plug), the kind you would connect to a
USB printer as shown in the following image.
In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in the
following image.
Here, we are selecting just one of the examples with the name Blink. It turns the LED on and off
with some time delay. You can select any other example from the list.
Here, we have selected Arduino Uno board according to our tutorial, but you must select the name
matching the board that you are using.
Step 7 − Select your serial port.
Select the serial device of the Arduino board. Go to Tools → Serial Port menu. This is likely to be
COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out,
you can disconnect your Arduino board and re-open the menu, the entry that disappears should be
of the Arduino board. Reconnect the board and select that serial port.
F − Serial monitor used to receive serial data from the board and send the serial data to the board.
Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see the
RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done uploading"
will appear in the status bar.
Arduino UNO R3
Arduino Uno is the most popular and widely used development board. It is powered by
an ATMega328P microcontroller. It is the most popular choice among the community because
it’s, cheap, easy to learn and use, and also a variety of premade modules are available for this which
makes it easier for developing new projects or prototypes. It consists of 14Digital I/O out of which
IoT and Its Applications in Electrical Engineering Laboratory Page 12
RCPIT, Shirpur Department of Electrical Engineering
6 pins are 8bit PWM pins, 6 pins are10-bit Analog inputs, and basic communication ports like SPI,
I2C, and UART.
Now, there are many different types of Arduino UNO boards available across the global market,
but most of these boards are the clone or copy version of the original UNO board that you see
above. Hence the color or the appearance of the board might be different than what is shown above.
Arduino Nano
Arduino Nano is a small breadboard-friendly version of Arduino UNO. It has more or less
functionality of the Arduino UNO but in a small form factor. The only major differences from UNO
are the lack of a DC power jack, the usage of a Mini USB port instead of a USB B port, and the
USB-TTL converter chip. Nano uses an FT232, a dedicated USB-UART bridge chip from FTDI
instead of an ATMega16U2. It is also a very popular choice among the developers just like UNO
because of its small size and cheap price.
Pro mini is actually a cut-down version of Nano. It has most of the functionalities similar to
Arduino Nano but it lacks the onboard USB -TTL bridge and the USB port. Instead, it has a header,
in which the UART pins are brought out. We can use these pins to program the Pro mini using an
external USB-UART module. This board is specially meant for applications where the space is
limited. Pro mini is available in two versions, 3.3V, and 5v versions. In the 3.3V version, the CPU
speed is limited to 8MHz because of certain limitations of ATMega328 for better stability.
Arduino Leonardo
Arduino Leonardo is powered by an ATmega32U4 chip rather than the ATMega328P chip
which is used in all the previously mentioned boards. It has more IO pins (20) and more
PWM (7) and analog input (12) pins. One other major difference is that the ATMega32U4
has built-in USB communication eliminating the need for a second processor or a
dedicated USB to UART bridge chip. This allows the board to connect to a computer as a
Human Interface Device (HID) or as a Virtual (CDC) serial / COM port. We use
this Virtual COM port along with the bootloader to program the Leonardo.
Arduino Micro
Just like Arduino Nano is a UNO in a small form factor, Arduino Micro is actually a Leonardo in a
small form-factor breadboard-friendly sized board. Its functionalities are the same as the Arduino
Leonardo. The only difference is the lack of a DC input jack. Similarly, Arduino Micro can also act
as an HID or Virtual COM port device.
Arduino Nano Every is a new generation board in a small form factor. As we already
discussed Arduino Nano is the preferred board for many projects requiring a small and
cheap solution. We could call the Arduino Nano Every, an upgraded Arduino Nano with
lot more features. Nano Every is powered by a more powerful processor ATMega4809. It
has 50% more program memory and a 200% bigger RAM which will enable us to muse this
board for bigger programs. The castellated holes allow us to use the Nano Every on a PCB
without the need for the header pins.
Arduino Mega 2560 is the biggest of all the boards we have discussed so far. It is designed
for applications where a lot of I/O or peripherals are needed. It is powered by a bigger and
more capable processor the ATMega2560. This board has the greatest number of I/O than
most other boards, 54 I/O pins (of which 15 can be used as PWM outputs), 16 analog inputs,
and 4 UARTs. It has more flash storage and SRAM than most other basic Arduino boards. It
is most popular with the opensource CNC and 3D printer community as well as the
opensource PLC community.
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 2
• 1 × Breadboard
• 1 × Arduino Uno
• 1 × LED
• 1 × 330Ω Resistor
• 2 × Jumper
Implementation:
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. Establishing this important baseline will give you a solid foundation as we work towards
experiments that are more complex.
Procedure
1. Make a connection as per above diagram.
2. Write the program in Arduino IDE.
3. Upload your code in Arduino board.
Program:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/
// the setup function runs once when you press reset or power the board
IoT and Its Applications in Electrical Engineering Laboratory Page 18
RCPIT, Shirpur Department of Electrical Engineering
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 3
Procedure:
1. Make a connection as per above diagram.
2. Write the program in Arduino IDE.
3. Download and install DHT library.
4. Upload your code in Arduino board.
Program:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup(){
Serial.begin(9600);
}//end "setup()"
void loop(){
//Start of Program
DHT.read11(dht_apin);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);//Wait 5 seconds before accessing sensor again.
//Fastest should be once every two seconds.
Output:
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 4
Implementation:
DC Voltmeter
DC Ammeter
PROCEDURE
A) Procedure for DC Voltmeter:
1. Make the connection as per the electrical circuit diagram
2. Open the Arduino IDE in computer and write the program.
3. Compile the program for any errors and upload it to the Arduino.
4. Observe the voltage on Serial monitor.
5. If a potentiometer is used between the battery and sensor to change the voltage value.
6. Observe the changed voltage is updated on Serial Monitor.
void setup() {
Serial.begin(9600);
}
void loop() {
float average = 0;
for(int i = 0; i< 1000; i++)
{
average = average + (.0264 * analogRead(A0) -13.51) / 1000;
//5A mode, if 20A or 30A mode, need to modify this formula to
//(.19 * analogRead(A0) -25) for 20A mode and
//(.044 * analogRead(A0) -3.78) for 30A mode
delay(1); }
Serial.println(average);
}
Output:
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 5
Implementation:
AC Voltmeter
AC Ammeter
PROCEDURE
A) Procedure for AC Voltmeter:
1) Make the connection as per the electrical circuit diagram
2) Open the Arduino IDE in computer and write the program.
3) Compile the program for any errors and upload it to the Arduino.
4) Observe the voltage on Serial monitor.
5) Observe the changed voltage is updated on Serial Monitor.
B) Procedure for DC Ammeter:
1) Make the connection as per the electrical circuit diagram
2) Open the Arduino IDE in computer and write the program.
3) Compile the program for any errors and upload it to the Arduino.
4) Observe the current on LCD display.
5) If the load is increased by adding a series resistor to LED then current increases and is
updated in LCD display.
Code:
AC Voltmeter
double sensorValue1 = 0;
double sensorValue2 = 0;
int crosscount = 0;
int climb_flag = 0;
int val[100];
int max_v = 0;
double VmaxD = 0;
double VeffD = 0;
double Veff = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
for ( int i = 0; i < 100; i++ ) {
sensorValue1 = analogRead(A0);
if (analogRead(A0) > 511) {
val[i] = sensorValue1;
}
else {
val[i] = 0;
}
delay(1);
}
IoT and Its Applications in Electrical Engineering Laboratory Page 31
RCPIT, Shirpur Department of Electrical Engineering
max_v = 0;
for ( int i = 0; i < 100; i++ )
{
if ( val[i] > max_v )
{
max_v = val[i];
}
val[i] = 0;
}
if (max_v != 0) {
VmaxD = max_v;
VeffD = VmaxD / sqrt(2);
Veff = (((VeffD - 420.76) / -90.24) * -210.2) + 210.2;
}
else {
Veff = 0;
}
Serial.print("Voltage: ");
Serial.println(Veff);
VmaxD = 0;
delay(100);
}
AC Voltmeter
double sensorValue1 = 0;
double sensorValue2 = 0;
int crosscount = 0;
int climb_flag = 0;
int val[100];
int max_v = 0;
double VmaxD = 0;
double VeffD = 0;
double Veff = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
delay(1);
}
max_v = 0;
for ( int i = 0; i < 100; i++ )
{
if ( val[i] > max_v )
{
max_v = val[i];
}
val[i] = 0;
}
if (max_v != 0) {
VmaxD = max_v;
VeffD = VmaxD / sqrt(2);
Veff = (((VeffD - 420.76) / -90.24) * -210.2) + 210.2;
}
else {
Veff = 0;
}
Serial.print("Voltage: ");
Serial.println(Veff);
VmaxD = 0;
delay(100);
}
Output
Conclusion
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 6
PROCEDURE
1. Make the connection as per the electrical circuit diagram
2. Open the Arduino IDE in computer and write the program.
3. Compile the program for any errors and upload it to the Arduino.
4. Observe the Power, Energy consumed by the load on LCD display
Code:
#include int currentPin = 1;
double kilos = 0;
int peakPower = 0;
LiquidCrystallcd(8, 9, 4, 5, 6, 7);
void setup()
{
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Running");
}
void loop()
{
int current = 0;
int maxCurrent = 0;
int minCurrent = 1000;
for (int i=0 ;i<=200 ; i++) //Monitors and logs the current input for 200 cycles to determine max
and min current
{
current = analogRead(currentPin); //Reads current input and records maximum and minimum
current
if(current >= maxCurrent)
maxCurrent = current;
else if(current <= minCurrent)
minCurrent = current;
}
if (maxCurrent<= 517)
{
maxCurrent = 516;
}
double RMSCurrent = ((maxCurrent - 516)*0.707)/11.8337; //Calculates RMS current based on
maximum value
int RMSPower = 220*RMSCurrent; //Calculates RMS Power Assuming Voltage 220VAC, change
to 110VAC accordingly
if (RMSPower>peakPower)
{
peakPower = RMSPower;
IoT and Its Applications in Electrical Engineering Laboratory Page 36
RCPIT, Shirpur Department of Electrical Engineering
}
kilos = kilos + (RMSPower * (2.05/60/60/1000)); //Calculate kilowatt hours used
delay (2000);
lcd.clear();
lcd.setCursor(0,0); // Displays all current data
lcd.print(RMSCurrent);
lcd.print("A");
lcd.setCursor(10,0);
lcd.print(RMSPower);
lcd.print("W");
lcd.setCursor(0,1);
lcd.print(kilos);
lcd.print("kWh");
lcd.setCursor(10,1);
lcd.print(peakPower);
lcd.print("W");
}
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 7
Procedure:
1. Make the connection as per the circuit diagram
2. Open the Arduino IDE in computer and write the program.
3. Compile the program for any errors and upload it to the Arduino.
4. Observe the status of traffic light.
Code:
// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
int DELAY_GREEN = 5000;
int DELAY_YELLOW = 2000;
int DELAY_RED = 5000;
// basic functions
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);
}
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}
void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 8
Code:
#include <Servo.h> // servo library
Servo s1;
int val = 0 ;
int va2 = 0 ;
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT); // IR sensor 1
pinMode(3,INPUT); // IR sensor 2
s1.attach(9); // Servo Connect 9 pin
s1.write(0);
}
void loop()
{
val = digitalRead(2); // IR sensor 1 output pin connected
va2 = digitalRead(3); // IR sensor 2 output pin connected
Serial.println(val); // see the value in serial monitor in Arduino IDE
Serial.println(va2); // see the value in serial monitor in Arduino IDE
delay(10); // Time Delay
if(val == 1 )
{
s1.write(0); // SERVO 0 DEGREE
}
if(va2 == 1 )
{
s1.write(90); // SERVO 90 DEGREE
}
}
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 9
Procedure:
1. Make the connection as per the circuit diagram
2. Open the Arduino IDE in computer and write the program.
3. Compile the program for any errors and upload it to the Arduino.
4. Use push button for direction control of motor and use pot for speed control of the motor.
Code:
// Arduino DC motor speed and direction control
#define button 8
#define pot 0
IoT and Its Applications in Electrical Engineering Laboratory Page 45
RCPIT, Shirpur Department of Electrical Engineering
#define pwm1 9
#define pwm2 10
boolean motor_dir = 0;
int motor_speed;
void setup() {
pinMode(button, INPUT_PULLUP);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
}
void loop() {
motor_speed = analogRead(pot) / 4;
if(motor_dir)
analogWrite(pwm1, motor_speed);
else
analogWrite(pwm2, motor_speed);
if(!digitalRead(button)){ // If direction button is pressed
while(!digitalRead(button)); // Wait until direction button released
motor_dir = !motor_dir; // Toggle direction variable
if(motor_dir)
digitalWrite(pwm2, 0);
else
digitalWrite(pwm1, 0);
}
}
Conclusion:
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
Laboratory Report
Experiment No: ____
__
Evaluations
_______________________
Sign of Practical Teacher
Experiment 10
Aim: Reading sensor data and sending it to cloud platform for temperature and
humidity sensor.
Component:
• 1 x NodeMCU
• 1 x DHT11 Temperature and Humidity sensor
• 3 x Jumper Male to female
Implementation:
Procedure:
1. Go to https://thingspeak.com/ and create an account if you do not have one. Login to your
account.
2. Create a new channel by clicking on the button.Enter basic details of the channel.
Then Scroll down and save the channel.
3. Channel Id is the identity of your channel. Note down this. Then go to API keys copy and paste
this key to a separate notepad file will need it later.
Code:
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or
api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(10000);
}
Result:
Conclusion:
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________