0% found this document useful (0 votes)
109 views20 pages

ME 3781 IOT Ex 1,2, 3-1

Uploaded by

rajvijaya268
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)
109 views20 pages

ME 3781 IOT Ex 1,2, 3-1

Uploaded by

rajvijaya268
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/ 20

ME3781 – Mechatronics and IoT Laboratory

List Of Experiments:

Internet Of Things:

1. Familiarization with the concept of IoT and its open-source microcontroller/SBC.


2. Write a program to turn ON/OFF motor using a microcontroller/SBC through the
internet.
3. Write a program to interface sensors to display the data on the screen through
internet.
4. Interface the sensors with the microcontroller/SBC and write a program to turn
ON/OFF Solenoid valve through the internet when sensor data is detected.
5. To interface the sensor with the microcontroller/SBC and write a program to turn
ON/OFF Linear/Rotary Actuator through IoT when sensor data is detected.
6. To interface Bluetooth/Wifi with microcontroller/SBC and write a program to
send sensor data to a Smartphone using Bluetooth/wifi.
Experiment No: Date:

FAMILIARIZATION WITH ARDUINO (MCU) AND PERFORM


NECESSARY SOFTWARE INSTALLATION
AIM:
To get familiarization with Arduino and to perform necessary software installation.

APPARATUS:

1. Arduino Module

2. PC with Open Source Arduino Software

THEORY:

Internet of Things (IOT)


Introduction: IOT stands for “Internet of Things”. The IOT is a name for the vast
collection of “things” that are being networked together in the home and workplace
(up to 20 billion by 2020 according to Gardner, a technology consulting firm).

Characteristics of the IOT


Communications in IoT

Communications are important to IOT projects. In fact, communications are core to the
whole genre. There is a trade-off for IOT devices. The more complex the protocols and
higher the data rates, the more powerful processor needed and the more electrical power
the IOT device will consume.
TCP/IP base communications (think web servers; HTTP-based commutation (like REST
servers); streams of data; UDP) provide the most flexibility and functionality at a cost of
processor and electrical power.
Low-power Bluetooth and Zigbee types of connections allow much lower power for
connections with the corresponding decrease in bandwidth and functionality. IOT
projects can be all over the map with requirements for communication flexibility and
data bandwidth requirements.
Arduino in IoT
In IoT applications the Arduino is used to collect the data from the sensors/devices to
send it to the internet and receives data for purpose of control of actuators.
Arduino Uno
Introduction: The Arduino Uno is an open-source microcontroller board based on
the Microchip ATmega328P microcontroller and developed by Arduino.cc. The
board is equipped with sets of digital and analog input/output (I/O) pins that may be
interfaced to various expansion boards (shields) and other circuits. The board has 14
digital I/O pins (six capable of PWM output), 6 analog I/O pins, and is programmable
with the Arduino IDE (Integrated Development Environment), via a type B USB
cable. It can be powered by the USB cable or by an external 9-volt battery, though it
accepts voltages between 7 and 20 volts. The word "uno" means "one" in Italian and
was chosen to mark the initial release of Arduino Software.

Features of the Arduino

1. 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.
2. The board functions can be controlled by sending a set of instructions to the
microcontroller on the board via Arduino IDE.
3. Arduino IDE uses a simplified version of C++, making it easier to learn to program.

4. Arduino provides a standard form factor that breaks the functions of the micro-
controller into a more accessible package.

Arduino IDE (Integrated Development Environment)

Introduction: The Arduino Software (IDE) is easy-to-use and is based on the


Processing programming environment. The Arduino Integrated Development
Environment (IDE) is a cross-platform application (for Windows, macOS, Linux) that is
written in functions from C and C++. The open-source Arduino Software (IDE) makes it
easy to write code and upload it to the board. This software can be used with any
Arduino board.

The Arduino Software (IDE) – contains:


• • A text editor for writing code

• • A message area

• • A text consoles

• • 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.

Procedure

Step1: Downloading
➢To install the Arduino software, download this page:
http://arduino.cc/en/Main/Software and proceed with the installation by allowing the
driver installation process.
Step 2: Directory Installation

➢ Choose the installation directory.


Step 3: Extraction of Files

➢The process will extract and install all the required files to execute properly the

Arduino Software (IDE)

Step 4: Connecting the board

➢The USB connection with the PC is necessary to program the board and not just to

power it up. The Uno and Mega automatically draw power from either the USB or an
external power supply. Connect the board to the computer using the USB cable. The
green power LED (labelled PWR) should go on.

Step 5: Working on the new project

➢ Open the Arduino IDE software on your computer. Coding in the Arduino language

will control your circuit.

➢ Open a new sketch File by clicking on New.


Step 6: Working on an existing project
➢To open an existing project example, select File → Example → Basics → Blink.

Step 7: Select your Arduino board.


➢ To avoid any error while uploading your program to the board, you must select the

correct Arduino board name, which matches with the board connected to your computer.

➢ Go to Tools → Board and select your board.


Step 8: 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
Step 9: Upload the program to your board.
➢ 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.

RESULT:
Experiment No: Date:

Write a program To make an LED blink on an Arduino Uno

AIM

To make an LED blink on for 1 second using an Arduino Uno, you can follow these
steps:

Materials Needed:

1. Arduino Uno board.


2. LED.
3. Resistor (220 ohms recommended).
4. Breadboard (optional).
5. Jumper wires.

Procedure:

1. Connect the LED and Resistor:


o Insert the LED into the breadboard (if using one). The longer leg of the
LED is the positive leg (anode) and the shorter leg is the negative leg
(cathode).
o Connect a 220-ohm resistor to the anode of the LED. This resistor limits the
current to prevent damaging the LED.
o Connect the other end of the resistor to digital pin 7 on the Arduino Uno
using a jumper wire.
o Connect the cathode (short leg) of the LED to the ground (GND) pin on the
Arduino Uno using another jumper wire.
Write the Code:

 Open the Arduino IDE on your computer.


 Write the following code

void setup()

pinMode(7, OUTPUT); // Set pin 7 as an output

void loop()

digitalWrite(7, HIGH); // Turn the LED on

delay(1000); // Wait for 1 second (1000 milliseconds)

digitalWrite(7, LOW); // Turn the LED off

delay(1000); // Wait for 1 second

This C++ code is written for an Arduino microcontroller. It continuously blinks an LED
connected to pin 7 on and off with a delay of one second.

 Upload the Code to the Arduino:


o Connect the Arduino Uno to your computer using a USB cable.
o Select the correct board (Arduino Uno) and port from the Tools menu in the
Arduino IDE.
o Click the upload button (right-arrow icon) to upload the code to the
Arduino.
 Observe the LED:
o After uploading the code, the LED should start blinking on and off with 1-
second intervals.

This setup and code will result in the LED connected to pin 7 of the Arduino Uno
turning on for 1 second and then turning off for 1 second repeatedly.

Result

As a result, the LED connected to pin 7 will blink on and off with 1-second intervals.
Experiment No: Date:

Ex 2 Write a program to turn ON/OFF motor using a microcontroller/SBC


through the internet.

Aim: Write a program and conduct experiment to turn ON/OFF motor using a ESP 32
through the blynk

Hardware Requirements:

 ESP32 development board (e.g., ESP32 DevKit C)


 Motor (DC or stepper)
 Motor driver (e.g., L298N for DC motor, A4988 for stepper motor)
 Power supply (5V for ESP32, appropriate voltage for motor and driver)
 Jumper wires
 Breadboard (optional)

Software Requirements:

 Arduino IDE
 Blynk app (iOS or Android)
 Blynk library for Arduino

Procedure

Circuit Setup:

1. Connect the ESP32:


o Connect the ESP32 to your computer using a USB cable.
o Connect the 3.3V and GND pins of the ESP32 to the power supply.
o Connect the ESP32's GPIO pins to the motor driver's control pins.
2. Connect the Motor Driver:
o Connect the motor driver's power supply pins to the appropriate voltage source.
o Connect the motor driver's motor output pins to the motor.
o Connect the motor driver's control pins to the ESP32's GPIO pins.

Blynk App Setup:

1. Create a Blynk Account:


o Sign up for a free Blynk account.
2. Create a New Project:
o Log in to your Blynk account and create a new project.
o Choose "ESP32" as the device type.
o Note down the generated Auth Token.
3. Design the App Interface:
o Add a Button widget to your app's interface.
o Assign a Virtual Pin (e.g., V0) to the Button widget.
Experiment:

1. Upload the Code:


o Upload the Arduino code to your ESP32 board.
2. Run the Blynk App:
o Open the Blynk app on your phone.
o Select your project.
3. Control the Motor:
o Tap the Button widget in the Blynk app to turn the motor ON or OFF.
o Observe the motor's response.

Result
The program executed as intended on the IoT platform
#include <ESP32WiFi.h>
#include <BlynkSimpleEsp32.h>

// Replace with your WiFi credentials and Blynk Auth Token


char auth[] = "Your_Auth_Token";
char ssid[] = "Your_WiFi_SSID";
char pass[] = "Your_WiFi_Password";

// Define the GPIO pin connected to the motor driver's control pin
const int motorPin = 2;

void setup() {
Serial.begin(115200);
Blynk.begin(auth,
nk.begin(auth, ssid, pass);
pinMode(motorPin, OUTPUT);
}

void loop() {
Blynk.run();

// Read the button's state from the Blynk app


int buttonState = Blynk.virtualRead(V0);

// Control the motor based on the button state


if (buttonState == 1) {
digitalWrite(motorPin, HIGH); // Turn on the motor
} else {
digitalWrite(motorPin, LOW); // Turn off the motor
}
}
Experiment No: Date:

EX 3. Write a program to interface sensors to display the data on the


screen through internet.

Aim : To develop IoT Based Temperature Monitoring System Using ESP32 With
Blynk App

Components Needed

1 ESP32 Board 1
2 DHT11 Sensor 1
3 Connecting wires LS
4 Connecting cables

Procedure

Procedure:

1. Hardware Setup:

 Connect the DHT11 sensor to the ESP32 board as follows:


o +V: Connect the positive pin of the DHT11 to the 3.3V pin of the ESP32.
o Data: Connect the data pin of the DHT11 to the D2 pin of the ESP32.
o -V: Connect the negative pin of the DHT11 to the GND pin of the ESP32.

2. Blynk Cloud Setup:

 Create a New Template:


o Log in to your Blynk Cloud account.
o Go to the "Templates" page and create a new template.
o Select "ESP32" as the board and "Wi-Fi" as the connection type.
o Click "Done."
 Create Data Streams:
o Go to the "Data Streams" page and create two new data streams:
 Temperature: Virtual Pin V0, Data Type: Double, Unit: Celsius,
Max Value: 100
 Humidity: Virtual Pin V1, Data Type: Double, Max Value: 100
 Design the Dashboard:
o Go to the "Web Dashboard" page.
o Add two gauge widgets from the "Widget Box": one for temperature and
one for humidity.
o Configure the settings for each gauge, including the name and the
associated data stream.

3. Device Setup:

 Create a New Device:


o Go to the "Devices" page and create a new device based on the temperature
and humidity template.
 Copy Authentication Information:
o Copy the generated authentication token, Wi-Fi credentials, and other
necessary information.
 Program the ESP32:
o Paste the copied information into your ESP32 code.
o Upload the code to the ESP32 board.

4. Android App Setup:

 Download and Install the Blynk App:


o Download the Blynk app from the Google Play Store and install it on your
Android phone.
 Add the Template to the App:
o Open the Blynk app and log in to your account.
o Add the temperature and humidity template to your dashboard.
 Customize the Dashboard:
o Add two gauge widgets to display the temperature and humidity values.

Now, the real-time temperature and humidity data from the DHT11 sensor will be
displayed on both the Blynk web dashboard and your Android phone.

Result
The program executed as intended on the IoT platform
For reference https://www.youtube.com/watch?v=gjYcLOoiH6c
PROGRAM

#define BLYNK_TEMPLATE_ID "TMPLIAjddf20T5"


#define BLYNK_DEVICE_NAME "Temperature and Humidity Monitor"
#define BLYNK_AUTH_TOKEN "122RywymdfdddgGfMd1jkZ0STNhRQecR12ayq"

#define BLYNK_PRINT Serial


#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp32.h>

#include <DHT.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = ""; // type your wifi name


char pass[] = ""; // type your wifi password

BlynkTimer timer;

#define DHTPIN 27 //Connect Out pin to D2 in NODE MCU


#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
Serial.print("Temperature : ");
Serial.print(t);
Serial.print(" Humidity : ");
Serial.println(h);
}
void setup()
{

Serial.begin(115200);

Blynk.begin(auth, ssid, pass);


dht.begin();
timer.setInterval(100L, sendSensor);

void loop()
{
Blynk.run();
timer.run();
}

You might also like