0% found this document useful (0 votes)
43 views62 pages

Iot Lab Manual 2

Uploaded by

ananth1491149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views62 pages

Iot Lab Manual 2

Uploaded by

ananth1491149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

(AUTONOMOUS)
KANURU, VIJAYAWADA-7

DEPARTMENT OF E.E.E.

IOT APPLICATIONS IN ELECTRICAL ENGINEERING

Prasad V. Potluri Siddhartha Institute of Technology


Affiliated to JNTU Kakinada, Approved by AICTE, New Delhi
Accredited By NBA, NAAC A+, ISO 9001:2015 Certified Institute
(Sponsored by: Siddhartha Academy of General & Technical
Education) Kanuru, Vijayawada -520007.
LIST OF EXPERIMENTS:

EXPT.NO TITLE OF THE EXPERIMENT

EXPTNO - 1 Familiarization withArduino/Raspberry Pi andperform necessary


software installation.
EXPTNO -2 Digital I/O Interface –Multi colour Led, IR Sensor

EXPTNO -3 Digital I/O Interface – IRSensor, Slot Sensor, PIR Sensor

Interface temperature Sensor with Arduino and write program to


print temperature and humidityreadings
EXPTNO -4

EXPTNO -5 Wireless module interface– Bluetooth, Wi-Fi

EXPTNO -6 Wireless module interface Wi-Fi

EXPTNO -7 Design of digitalVoltmeter and Ammeter

EXPTNO -8 Design and Speed Controlof DC motor

EXPTNO -9 Smart Home AndroidApp Development usingAPP Inventor andArduino

EXPTNO -10 Each batch has to develop an IOT Applicationproject


NAME OF THE EXPERIMENT MARKS SIGNATURE
EXPT.
NO
Fig1.1

Fig1.2

Fig1.3
1
EXPERIMENT – 1
Familiarization with Arduino/Raspberry Pi and perform necessary software
installation.
AIM
• Introduction to Arduino and necessary software installation.
• To Interface and control LED.
THEORY:
Introduction to Arduino:

What is Arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and

software. Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twittermessage - and turn it into an output - activating a motor, turning on an LED,
publishing something online. You can tell your board what to do by sending a set of
instructions to the microcontroller on the board. To do so you use the Arduino
programming language (based on Wiring), and the ArduinoSoftware (IDE), based on
Processing.

After learning about the main parts of the Arduino UNO board, we are ready to learn how
to set up the Arduino IDE. Once we learn this, we will be ready to upload our program on
the Arduino board.

In this section, we will learn in easy steps, how to set up the Arduino IDE on our computer
and preparethe board to receive the program via USB cable.

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 fig1.1

In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in
the fig1.2.
Step 2 − Download Arduino IDE Software.
You can get different versions of Arduino IDE from the download page on the Arduino
official website. You must select your software, which is compatible with your operating
system (Windows, IOS, or Linux). After your file download is complete, unzip the file as
shown in the fig1.3.
Step 3 − Power up your board.
The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power
from either, the USB connection to the computer or an external power supply. If you are
using an Arduino Diecimila, you have to make sure that the board is configured to draw
2
Fig1.4

Fig1.5

Fig1.6

3
power from the USB connection. The power source is selected with a jumper, a small piece
of plastic that fits onto two of the three pins between the USB and power jacks. Check that
it is on the two pins closest to the USB port.
Connect the Arduino board to your computer using the USB cable. The green power LED
(labeled PWR) should glow.
Step 4 – Launch Arduino IDE.
After your Arduino IDE software is downloaded, you need to unzip the folder. Inside thefolder,
you can find the application icon with an infinity label (application.exe). Double-click the icon
to start the IDE as shown in fig 1.4

Step 5 – Open your first project.


Once the software starts, you have two options –

• Create a new project.


• Open an existing project example.

• To create a new project, select File → New, as shown in fig 1.5


To open an existing project example, select File → Example → Basics → Blink.
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 as shown in
fig 1.6.

Step 6 – Select your Arduino board.


To avoid any error while uploading your program to the board, you must select thecorrect
Arduinoboard name, which matches with the board connected to your computer
Go to Tools → Board and select your board.
Here, we have selected Arduino Uno board according to our tutorial, but you must selectthe
name matching the board that you are using as shown in fig1.7

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) as
shown in fig1.8. 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.

Step 8 − Upload the program to your board.


Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar.

4
Fig 1.7

Fig 1.8

Fig 1.9

5
Fig1.9 shows:
A − Used to check if there is any compilation error.
B − Used to upload a program to the Arduino board.C − Shortcut used to create a new sketch.
D − Used to directly open one of the example sketch.
E − Used to save your sketch.
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 willsee
the RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar.

BLINK LED PROGRAM:

void setup(){

//Initialize digital pin LED_BUILTIN as an

outputpinMode (LED_BUILTIN,OUTPUT);

}
// The loop function runs over and over again
forever.void loop(){

digitalWrite (LED_BUILTIN,HIGH); //turn LED ON delay(1000);


//Wait for a second digitalWrite(LED_BUILTIN,LOW);
//turnLED OFF delay(1000); //wait for a second

RESULT:

6
Fig2.1

SCHEMATIC DIAGRAM RGB LED:

SCHEMATIC DIAGRAM OF IR SENSOR:

7
EXPERIMENT - 2
Digital I/O Interface –IR Sensor, Multi color Led

AIM: To interface and control RGB LED and a IR sensor with Arduino to detect motion
and display "Stop" or "Go" depending on the output from the sensor.

APPPARATUS REQUIRED:
S.No Name of the equipment Specifications Quantity
1 Arduino UNO 1
2 RGB common cathode LED 1
3 Infrared (IR)Sensor 1
4 Jumper wires required
5 Breadboard 1
6 Computer with Arduino IDE IDE 1.8.14 1
software

THEORY:
The RGB led consists of three different led’s, red, green and blue. Many other colors canbe
obtained by mixing up these colors. The Arduino has aa analog write function which is used
to obtain different colors for Arduino RGB led.
RGB LED Schematic
There are two types of RGB led’s; the common cathode one and the common anode. In the
common cathode RGB led, the cathode of all the led’s is common and a PWM signalsis fed
to the anode of led’s while in the common anode RGB led, the anode of all the led’sis common
and a PWM signals is fed to the cathode of led’s as shown in fig2.1.
IR SENSOR
An Infrared sensor is an electronic module which is used to sense certain physical appearance
of its surroundings by either emitting and/or detecting infrared radiation. IR sensors are also
capable of determining the heat being emitted by an object and detecting motion.
IR SENSOR WORKING:
Here an IR sensor is used for detecting obstacles. IR transmitter transmits IR signal, as that
signal detects any obstacle in its path, the transmitted IR signal reflects back from the obstacle
and receivedby the receiver.

8
9
PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE

PROGRAMME FOR RGB LED:


int red = 2;
int green = 3;
int blue = 4;
void setup() {
// initialize led pins as an output.
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
// the loop function runs over and over again forevervoid loop() {
digitalWrite(red, 1);// turn the RED LED on (HIGH is the voltage level)
digitalWrite(green, 0);
digitalWrite(blue, 0);
delay(1000); // wait for a second
digitalWrite(red,0);
digitalWrite(green, 1);// turn the GREEN LED on (HIGH is the voltage level)
digitalWrite(blue, 0);
delay(1; digitalWrite(d, 0);
digitalWrite(green, 0);
digitalWrite(blue, 1);// turn the BLUE LED on (HIGH is the voltage level)
delay(1000);
}

OBSERVATIONS:

S.No. RGB Color Value LED Color


1.
2.
3.

10
Fig: 2.2

11
PINOUT(fig2.2):
1. VCC: 3.3V-5V power input pin
2. GND: 0V power pin
3. OUT: Digital Output Pin
PROGRAME:
int ir = 2; // connect ir sensor to arduino
pin 2int led = 3; // conect Led to arduino
pin 3 void setup(){
pinMode (ir, INPUT); // sensor pin INPUT
pinMode (led, OUTPUT); // Led pin OUTPUT
}
void loop(){
int statusSensor =
digitalRead(ir); if (statusSensor
== 1){ digitalWrite(led, 0); // LED
LOW
}
else{
digitalWrite(led, 1); // LED High
}
OBSERVATIONS:
S.NO OBSTACL E LED Status

1.

2.

3.

RESULT:

12
SCHEMATIC DIAGRAM PIR SENSOR:

13
EXPERIMENT-3
Digital I/O Interface - PIR Sensor, Slot Sensor
Aim:

• To Interface a PIR with Arduino to detect motion and display "Stop" or "Go"
depending on the output from the sensor.
• To Interface a slot sensor with Arduino to detect object and control LEDbased
on sensor output.
APPPARATUS REQUIRED:

S.No Name of the equipment Specifications Quantit


y
1 Arduino UNO 1
2 PIR Sensor 1
3 Slot Sensor 1
4 Jumper wires required
5 Breadboard 1
6 Computer with Arduino IDE 1.8.14 1
IDE software

Theory:
Passive Infrared (PIR) Sensor
The PIR sensor consists of 4 pins: GND, VCC, OUT, and EN. It can measure movement up
to 30′. Within thedome-shaped lens (used to focus the incoming light onto the detectors), there
are two slots that can detect different levels of infrared (IR) light or radiation. The sensor does
not detect motion when the detectors sensethe same amount of IR. The motion is detected
when the detectors measure two different levels of IR. The levels of IR can vary from object
to object since each one emits different amounts of heat energy.

PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.

14
15
PROGRAM FOR PIR SENSOR:

int LEDpin = 13; //Connect RED LED at 13 pin


int obstaclePin = 2;
int hasObstacle = LOW; // LOW MEANS NO OBSTACLE
void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(obstaclePin, INPUT);
Serial.begin(9600);
}
void loop()
{
hasObstacle = digitalRead(obstaclePin);
if(hasObstacle == HIGH)
{ Serial.println(“Stop”);
digitalWrite(LEDpin,HIGH);
}
Else
{
Serial.println(“Go”);
digitalWrite(LEDpin, LOW);
}
delay(200);
}

OBSERVATIONS:

S.No. RGB Color Value LED Color


1.
2.
3.

16
Fig3.2

SCHEMATIC DIAGRAM OF SLOT SENSOR:

17
LM393 Speed Sensor Module (H206)/SLOT SENSOR
H206 speed sensor module is composed of infrared light sensor and LM393 voltage
comparator IC, so it is named as LM393 speed sensor. The module also includesa grid plate,
which must be mounted on the rotating shaft of the motor. The infrared light sensor is
composed of infrared LED and phototransistor, separated by a small gap. As shown below,
the entire sensor device is placed in a black housing. The grid plate is composed of grooves,
and the plate is arranged between the gaps ofthe infrared light sensors so that the sensor
can sense the gap in the grid plate. Each gap in the grid plate triggers the IR sensor when
passing through the gap; a comparator is then used to convert these triggers into a voltage
signal. The comparator uses ON Semiconductor's LM393 IC as shown in fig3.2. The module
has three pins, two of which are used to power the module, and one output pin is used to
count the number of triggers.

PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.

PROGRAM
int slot Sensor = 2;

int led = 13;


void setup() {
// put your setup code here, to run once:
pinMode(slotSensor, INPUT); pinMode(led, 13);
}
void loop() {
// put your main code here, to run repeatedly:
int value = digitalRead(slotSensor);
if(value == 1){
digitalWrite(led, 1);
}
else{
digitalWrite(led, 0);}}
18
19
OBSERVATION:

S.No OBSTACL E LED


. Status
1.

2.

3.

RESULT:

20
Fig4.1

SCHEMATIC DIAGRAM:

21
EXPERIMENT-4
Interface temperature Sensor with Arduino and write program to print
temperatureand humidity readings

AIM: To observe the Temperature and display in serial monitor.

APPPARATUS REQUIRED:

S.No Name of the equipment Specifications Quantity


1 Arduino UNO 1
2 Temperature Sensor DTH11 1
3 Jumper wires required
4 Breadboard 1
5 Computer with Arduino IDE 1.8.14 1
IDEsoftware

THEORY:
The analog input is a pin with ADC (Analog-to-Digital Converter) function. It
can convert the externally input analog signal into a digital signal that can be recognized
during chip operation, so as to realize the function of reading in the analog value. The
Arduino analog input function has 10-bit precision, that is, it can convert a voltage
signal of 0 to 5V into an integer form of 0 to 1024.

Temperature sensor DTH11:


The digital temperature and humidity sensor DHT11 is a composite sensor that
contains a calibrated digital signal output of temperature and humidity as shown in fig4.1.
The technology of a dedicated digital modules collection and the temperature and
humidity sensing technology are applied to ensure that the product has high reliability
and excellent long- term stability. The sensor includes a resistive sense of wet component
and an NTC temperature measurement device, and is connected with a high- performance
8-bitmicrocontroller.

22
23
PROCEDURE:
• Build the circuit according to the schematic diagram
• Use Arduino Uno on the Arduino Desktop IDE.
• Select board type and port.
• Write and upload the program in the Arduino-IDE.
• Add the required library files.
• Observe the temperature and Humidity values.

PROGRAM:
#include <dht.h>
dht DHT;
#define DHT11_PN 8
void setup()
{
Serial.begin(9600);}

void loop(){
int chk = DHT.read11(DHT11_PIN);

Serial.print("Temperature = ");

Serial.println(DHT.temperature);

Serial.print("Humidity = ");

Serial.println(DHT.humidity);

delay(1000);
}

24
25
OBSERVATIONS:

S.No Temperature Humidity


.
1

RESULT:

26
Fig5.1

SCHEMATIC DIAGRAM:

27
EXPERIMENT – 5
Wireless module interface – Bluetooth.
AIM:

• Transfer data using Bluetooth with Arduino

• Control LED at Receiver through Switch at Transmitter using Wi-Fi module


interface with Arduino

APPPARATUS REQUIRED:

S.No Name of the equipment Specifications Quantity


1 Arduino UNO 1
2 Bluetooth Module HC-05 1
3 Sparkfun push button Switch 1
4 LED 1
5 Resistor 220 Ω
6 Jumper wires required
7 Breadboard 1
8 Computer with Arduino IDE IDE 1.8.14 1
software
9 Mobile phone with wi-fi 1
connectivity

THEORY:
BLUETOOTH MODULE INTERFACE:
BLUETOOTH:
Bluetooth is a one of the wireless technology. HC-05 is a Bluetooth module which can
communicate in two way. It is full-duplex. It be used with most micro controllers. Because it
operates Serial Port Protocol (SSP). The module communicate with the help of
USART(Universal Synchronous/ Asynchronous Receiver/Transmitter) at the baud rate of
9600anditalso support other baud rate. This module can be interfaced with any
microcontroller which supports USART. The HC-05 operates in two modes. One is Data
mode and other is at command mode. When the Enable/Key pin is "LOW" the HC-05 is in
Data Mode. If that pin set as "HIGH" the module is in AT command mode.
FROM Fig5.1
Enable - This pin is used to set the Data Mode or and AT command mode (set high).
VCC - This is connected to +5V power supply.
Ground - Connected to ground of powering system.
Tx (Transmitter) - This pin transmits the received data Serially.
Rx (Receiver) - Used for broadcasting data serially over bluetooth.
State -Used to check if the bluetooth is working properly.
28
29
PROCEDURE:
• Build the circuit according to the schematic diagram.
• Use Arduino Uno on the Arduino Desktop IDE.
• Select board type and port.
• Write and upload the program in the Arduino-IDE.
• Download and install a Bluetooth terminal application on phone and use it to connect
to the HC-05Bluetooth module.
• Data is sent from the Smartphone using the Bluetooth terminal application.

PROGRAM:
#include<softwareSerial.h>
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2, 3);
/* (Rx,Tx) */
void setup()
{
bt.begin(9600);
/* Define baud rate for software serial communication */
Serial.begin(9600);
/* Define baud rate for serial communication */
}
void loop()
{
if(bt.available())
{
/* If data is available on serial port */
Serial.write(bt.read());
/* Print character received on to the serial monitor */
}
}
OBSERVATION:
Input from mobile LED Status
S.No.
1.

2.

RESULT:

30
WI-FI (ESP8266) MODULE: NODEMCU

Fig6.1

Fig6.2

31
EXEPERIMENT-6
Wireless module interface –Wi-Fi

AIM: To control LED at Receiver through Switch at Transmitter using Wi-Fi module
interface with Arduino.
APPPARATUS REQUIRED:

S.No Name of the equipment Specifications Quantity


1 Arduino UNO 1
2 Wi-Fi Module ESP8266 2
3 LED 1
4 Resistor 220 Ω
5 Jumper wires required
6 Breadboard 1
7 Computer with Arduino IDE software IDE 1.8.14 1
8 Mobile phone with wi-fi connectivity 1

THEORY:
Wireless control of wheeled robots using WiFi involves leveraging wireless network
technology to remotely operate and manage robot movements. WiFi connectivity enables real-
time communication between the robot and a control interface, such as a smartphone or
computer, allowing for the transmission of commands and reception of feedback. This setup
typically includes a microcontroller or onboard computer on the robot equipped with a WiFi
module. Commands are sent over the WiFi network, interpreted by the robot's control system,
and executed accordingly, enabling precise navigation and task performance in various
environments. This method benefits from WiFi's broad range, high data transfer rate, and
widespread availability.

PROCEDURE:

1. Build the circuits according to the schematic diagrams


2. Use Arduino Uno on the Arduino Desktop IDE.
3. Select board type and port.
4. Write and upload the programs for led control.

PROGRAM:
#include <ESP8266WiFi.h>
const char* ssid = ""; // Your Wi-Fi Name
const char* password = ""; // Wi-Fi
Passwordint LED = 2; // led connected to
GPIO2 (D4) WiFiServer server(80);
void setup()
32
33
{
Serial.begin(115200); //Default Baudrate
pinMode(LED, OUTPUT); digitalWrite(LED,
LOW); Serial.print("Connecting to the
Newtork"); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin(); // Starts the Server
Serial.println("Server started");
Serial.print("IP Address of network: "); // will IP address on Serial Monitor
Serial.println(WiFi.localIP());
Serial.print("Copy and paste the following URL: https://"); // Will print IP address in URL
format
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop()
{
WiFiClient client = server.available();
if (!client)
{
return;
}
Serial.println("Waiting for new client");
while(!client.available())
{
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int value = LOW;
if(request.indexOf("/LED=ON") != -1)
{
digitalWrite(LED, HIGH); // Turn LED ONvalue
= HIGH;
}
if(request.indexOf("/LED=OFF") != -1)
{
digitalWrite(LED, LOW); // Turn LED OFF
34
35
value = LOW;
}
//*------------------HTML Page Code ------------------------- *//

client.println("HTTP/1.1 200 OK"); //


client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print(" CONTROL LED: ");
if(value == HIGH)
{
client.print("ON");
}
else
{
client.print("OFF");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>ON</button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>OFF</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}

OBSERVATIONS:
Input from mobile LED Status
S.No.
1.

2.

RESULT:

36
ELECTRICAL CIRCUIT DIAGRAM:

DC VOLTMETER:

Electrical Circuit for DC Volt meter

DC AMMETER:

Circuit Diagram for Digital DC ammeter

37
EXPERIMENT – 7
Design of digital Voltmeter and Ammeter

AIM: To design a Digital DC Voltmeter and Ammeter to measure the voltage


and current in DC electrical circuits using Arduino and display the values in
LCD display.

APPARATUS:
S. No Name of the equipment Quantity
1 Arduino Uno 1
2 16 x 2 LCD display 1
3 ACS712 Voltage sensor 1
4 9/12V Battery 1
5 Computer with Arduino IDE software 1
6 jumper cables As required

THEORY:

Designing a digital DC voltmeter and ammeter using Arduino involves using a voltage divider
for voltage measurement and a shunt resistor for current measurement. The Arduino reads
analog signals from these components, converts them to digital values, and processes them to
determine the actual voltage and current. These readings are then displayed on an LCD screen
controlled by the Arduino. The setup requires programming the Arduino to handle analog-to-
digital conversion, calculation of the measurements, and updating the LCD display. This
design provides accurate, real-time monitoring of DC electrical circuit parameters.

PROCEDURE

➢ Procedure for DC Voltmeter:

o Make the connection as per the electrical circuit diagram


o Open the Arduino IDE in computer and write the program.
o Compile the program for any errors and upload it to the Arduino.
o Observe the voltage on LCD display.
o If a potentiometer is used between the battery and sensor to change
the voltage value.
o Observe the changed voltage is updated on LCD display.

38
39
➢ Procedure for DC Ammeter:
o Make the connection as per the electrical circuit diagram
o Open the Arduino IDE in computer and write the program.
o Compile the program for any errors and upload it to the Arduino.
o Observe the current on LCD display.
o If the load is increased by adding a series resistor to LED then
current increases and is updated in LCD display.

ARDUINO CODE:

A) Code for DC Voltmeter:

void setup()

Serial.begin(9600);

void loop() {

int volt = analogRead(A0);// read the input

double voltage = map(volt,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500


and addcorrection

offset

voltage /=100;// divide by 100 to get the decimal

valuesSerial.print("Voltage: ");

Serial.print(voltage);//print the

voltgeSerial.println("V");

delay(500);

40
41
B) Code for DC Voltmeter:

void setup() {

Serial.begin(9600);

}
void loop() {

int volt = analogRead(A0);// read the input

double voltage = map(volt,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500


and addcorrection

offset

voltage /=100;// divide by 100 to get the decimal

valuesSerial.print("Voltage: ");

Serial.print(voltage);//print the

voltgeSerial.println("V");

delay(500);

}
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

modedelay(1);

}
42
43
Serial.println(average);

}
//DC motor direction and speed

controlint in1 = 6;

int in2 = 7;

int enA = 9;

int Speed =

0;int val = 0;

void setup()

Serial.begin(9600);

pinMode(enA,OUTPUT);

pinMode(in1,OUTPUT);

pinMode(in2, OUTPUT);

Serial.begin(9600);

}
//Enter value 0 or 1 to select motor direction, 0 for Backward, 1 for

Forwardvoid loop(){

val = analogRead(A0); // Read potentiometer value to change the

motor speedSpeed = map(val, 0, 1023, 0, 255);

// Anti clockwise

rotation

if(Serial.available() >

44
45
{

char state = Serial.read();

//FORWARD

Rotationif(state ==

‘1’){

analogWrite(enA,

Speed);

digitalWrite(in1, 1);

digitalWrite(in2, 0);

Serial.println(“FORWARD”

);delay(1000);

//BACKWARD Rotation
if(state == ‘0’){

analogWrite(enA,

Speed);

digitalWrite(in1, 0);

digitalWrite(in2, 1);

Serial.println(“BACKWARD”);

delay(1000);

RESULT:

46
Fig8.1

SCHEMATIC DIAGRAM:

47
EXPERIMENT – 8
Design and Speed Control of DC motor

AIM: To control DC Motor Speed and Direction using Arduino.

APPARATUS REQUIRED:

S.No Name of the equipment Specifications Quantity


1 Arduino UNO 1
2 DC Motor 12V High Torque 1
3 L298N Motor driver 1
4 Potentio Meter 10K Ω 1
5 Resistor 220ohms 1
6 Sparkfun push button Switch 1
7 Rechargeable Battery 5V 1
8 Jumper wires required
9 Breadboard 1
10 Computer with Arduino IDE IDE 1.8.14 1
software

THEORY:
The L298N is a dual-channel H-Bridge motor driver capable of driving a 2x
DC motors, making it ideal for building two-wheel robots.

Power Supply: From 'Vs' pin the H-Bridge gets its power for driving the motors which can
be 5 to 35V. 'Vss' is used for driving the logic circuitry which can be 5 to 7V. And they
both sink to a common ground named ‘GND’.

Output Pins: The L298N motor driver’s output channels for the motor A and B are broken
out to the edge of the module with two 3.5mm-pitch screw terminals.

Direction Control Pins: The IN1 and IN2 pins control the direction of the motor A while
IN3 and IN4 control the direction of the motor B.

Speed Control Pins: ENA and ENB are used to turn the motors ON, OFF and control its
speed. The module usually comes with a jumper on these pins. When this jumper is in
place, the motor is enabled and spins at maximum speed. If you want to control the speed of
motors, you need to remove the jumpers and connect themto PWM-enabled pins on
Arduino as shown in fig8.1

48
49
PROCEDURE:
1) Build the circuit according to the schematic diagram.
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.
5) Control the speed and direction of DC motor by varying potentiometer and switch.

PROGRAME:

//DC motor direction and speed control


int in1 = 6;
int in2 = 7;
int enA = 9;
int Speed = 0;
int val = 0;
void setup()
{
Serial.begin(9600);
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
Serial.begin(9600);
}
//Enter value 0 or 1 to select motor direction, 0 for Backward, 1 for Forward
void loop(){
val = analogRead(A0); // Read potentiometer value to change the motor speed
Speed = map(val, 0, 1023, 0, 255);
// Anti clockwise rotation
if(Serial.available() > 0){
char state = Serial.read();

//FORWARD Rotation
if(state == ‘1’){
analogWrite(enA, Speed);
digitalWrite(in1, 1);
digitalWrite(in2, 0);
Serial.println(“FORWARD”);
delay(1000);
}
//BACKWARD Rotation
if(state == ‘0’)
{
50
51
analogWrite(enA, Speed);
digitalWrite(in1, 0);
digitalWrite(in2, 1);
Serial.println(“BACKWARD”);
delay(1000);
}
}
}

OBSERVATIONS:
By varying the potentiometer, speed of the DC motor is controlled and each time
button is pressed, it changes the rotation direction of the motor.

RESULT:

52
Fig9.1

Fig9.2

SCHEMATIC DIAGRAM:

Fig: Wiring of Relay with Node MCU to Control Home Appliance.

53
EXPERIMENT – 9
Smart Home Android App Development using APP Inventor and Arduino

AIM: To develop Home Automation with MIT App Inventor and ESP8266.

APPPARATUS REQUIRED:

S.No Name of the equipment Specifications Quantity


1 Node MCU ESP8266 1
2 RGB common cathode 1
LED/Lamp
3 5V relay 1
4 Jumper wires
5 Breadboard 1
6 Computer with Arduino IDE
IDE 1.8.14 1
software
7 Mobile phone with wi-fi
1
connectivity

THEORY:
Relay Module

A relay is an electrically operated switch. Relays are used for controlling multiple circuits by
one signal. So using relays we can turn the circuit “ON” and “OFF” with electricity. The relay
is controlled by a small current (5V) and can switch “ON” and “OFF” the large current.
Typically, the relay has five terminals as shown in fig9.1

When no voltage is applied to the coil, the COM terminal will be connected to the NC
(Normally Closed) terminal. And when voltage is applied to the coil, anelectromagnetic field
is produced that attracts the armature, and a COM and NO(Normally Open) terminal connection
is made, which allows for very large currents as shown in 9.2.

A small driver circuit with a transistor, diode, and a resistor is used to configure relay. The
transistoris used to amplify the current, the resistor is used to provide BIAS to the transistor,
and ifthe transistor is off, the diode is used to stop the reverse current flow. Here we have used
the 5V relaymodule for demonstration.

54
55
PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.

NodeMCU Relay
Vcc Vcc
GND GND
D4 Input
Pin connection of relay with NodeMCU ESP8266

Now we have to make an Android APP using MIT App Inventor forcontrolling home
appliances.

PROGRAME:

#include <ESP8266WiFi.h>
const char* ssid = "Enter Your WiFi Name ";
const char* password = "Enter Your WiFi Password";WiFiServer
server(80);
void setup() {
Serial.begin(115200); //Default Baud Rate for NodeMCUdelay(10);
pinMode(2, OUTPUT); // Connect Relay to NodeMCU's D4 PindigitalWrite(2, 0);
// Connect to WiFi network
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid); WiFi.begin(ssid,
password);
while (WiFi.status() != WL_CONNECTED) {delay(500);
Serial.print(".");
}
Serial.println(""); Serial.println("WiFi
connected");
// Start the server server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected WiFiClient
client = server.available();if (!client) {
56
57
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){ delay(1);
}
String req = client.readStringUntil('\r');Serial.println(req);
client.flush();int val;
if (req.indexOf("/gpio/0") != -1)val = 0;
else if (req.indexOf("/gpio/1") != -1)val = 1;
else {
Serial.println("invalid request");client.stop();
return;
}
// Set GPIO2 according to the requestdigitalWrite(2, val);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type:
text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low"; s +=
"</html>

RESULT:

58
59

You might also like