MECHATRONICS AND IoT LABORATORY MANUAL
MECHATRONICS AND IoT LABORATORY MANUAL
LABORATORY RECORD
NAME : ______________________________________________________
CLASS : ______________________________________________________
BRANCH : ______________________________________________________
SUBJECT:______________________________________________________
1
2
ME3781-MECHATRONICS AND IoT LABORATORY
LTPC
0042
COURSE OBJECTIVES
1. To study the concept of mechatronics to design, modelling and analysis of basic electrical
hydraulic systems.
2. To provide the hands on-training in the control of linear and rotary actuators.
3. To study the concepts and fundamentals of IoT, sensors, actuators and IoT boards
1. Demonstrate the functioning of mechatronics systems with various pneumatic, hydraulic and
electrical systems.
2. Demonstrate the microcontroller and PLC as controllers in automation systems by executing
proper interfacing of I/O devices and programming
3. Demonstrate of IoT based Home automation, CNC router, Robotic arm.
3
4
INDEX
MECHATRONICS LABORATORY
Signature
Page Marks of
S.No Date Name of the Experiment
No. Awarded Staff
in charge
10
5
INTERNET OF THINGS LABORATORY
Signature
Page Marks of
S.No Date Name of the Experiment
No. Awarded Staff
in charge
6
MECHATRONICS LABORATORY
7
DIAGRAM
lua
Copy code
+-------------------------+
| Linear Displacement |
| Sensor |
| |
| (e.g., Potentiometer) |
+-------------------------+
↑
|
| Output Signal (V)
|
+--------------+
| Digital |
| Voltmeter |
+--------------+
+-------------------------+
| Rotary Encoder |
| (e.g., Optical) |
| |
+-------------------------+
↑
|
| Output Signal (Pulses)
|
+--------------+
| Digital |
| Voltmeter |
+--------------+
8
EX. NO.: 1
DATE:
AIM
To measure the linear and angular position, direction, and speed of a moving object using suitable
transducers and perform the necessary calculations.
APPARATUS REQUIRED
PROCEDURE
1. Set up the linear displacement sensor along the path of a moving object (e.g., a carriage or slider
along a track).
2. Connect the output of the sensor to a voltmeter or data acquisition system.
3. Measure the initial position (X₁) and final position (X₂) of the object using the sensor.
4. Move the object to a different position along the track, noting the changes in the sensor output as the
object moves.
5. Record the corresponding voltage or output signal values for different positions.
6. Calculate the linear displacement by measuring the change in position.
9
CALCULATIONS
Let the displacement sensor output (V) be proportional to the position (X). If the sensor's calibration gives a
relationship like:
V=kXV = kXV=kX
where VVV is the output voltage and XXX is the position in meters, then the linear position is:
X=VkX = \frac{V}{k}X=kV
For a rotary encoder, the angular position θ (in degrees or radians) can be calculated from the encoder’s
output signal, which is usually given in pulses. If the encoder has NNN pulses per revolution (PPR), the
angular position can be calculated as:
where:
The angular velocity is the rate of change of angular displacement. If the time taken to rotate by an angle
θ\thetaθ is ttt, the angular speed (ω) is:
ω=θt\omega = \frac{\theta}{t}ω=tθ
where:
If you are measuring linear motion, the linear speed is given by:
where:
10
SAMPLE CALCULATIONS
1. Linear Position:
2. Angular Position:
3. Angular Speed:
• If the time taken to rotate the disk through 90° is 2 seconds, the angular speed ω\omegaω is:
4. Linear Speed:
• Assume the object moves 5 meters in 10 seconds. The linear speed vvv is:
v=ΔXΔt=5 m10 s=0.5 m/sv = \frac{\Delta X}{\Delta t} = \frac{5 \, \text{m}}{10 \, \text{s}} = 0.5 \,
\text{m/s}v=ΔtΔX=10s5m=0.5m/s
RESULT
• The linear displacement XXX was found to be 2 meters for a voltage of 4V.
• The angular position θ\thetaθ was calculated to be 90° for 250 pulses.
• The angular speed ω\omegaω was calculated to be 45°/s.
• The linear speed vvv was calculated to be 0.5 m/s.
11
DIAGRAM:
css
Copy code
[Pressure Source] --> [Pressure Transducer] --> [Data Acquisition] -->
[Display/Readout]
css
Copy code
[Temperature Source] --> [Temperature Transducer] --> [Data Acquisition] -->
[Display/Readout]
css
Copy code
[Applied Load] --> [Force Transducer] --> [Data Acquisition] -->
[Display/Readout]
12
EX. NO.: 2
DATE:
AIM
To measure the pressure, temperature, and force using respective transducers and perform related
calculations.
APPARATUS REQUIRED
PROCEDURE
1. Pressure Measurement:
o Connect the pressure transducer to a known pressure source (e.g., a pressure pump).
o Power the transducer and connect it to a data acquisition system or a voltmeter to measure the
output.
o Gradually increase the pressure and note the corresponding output voltage from the
transducer.
o Record the pressure and corresponding output for several pressure levels.
2. Temperature Measurement:
o Connect the temperature transducer (e.g., thermistor or RTD) to a suitable power source and
voltmeter.
o Use a controlled heat source (e.g., water bath or an oven) to vary the temperature.
o Measure the output voltage or resistance of the transducer at different temperature points and
record the values.
3. Force Measurement:
o Connect the force transducer (load cell) to the applied load.
o Power the transducer and connect it to the data acquisition system or voltmeter.
o Apply known forces (e.g., different weights) to the force transducer.
o Measure and record the corresponding output from the transducer.
4. Calibrate the Transducers:
o If necessary, perform calibration using known reference values for pressure, temperature, and
force to ensure accurate measurements.
13
CALCULATIONS
1. Pressure Calculation:
The output voltage from the pressure transducer is related to the pressure by the following equation:
where:
The output voltage (or resistance) from the temperature transducer can be used to calculate the
temperature:
where:
o TTT = Temperature in °C
o RmeasuredR_{\text{measured}}Rmeasured = Measured resistance (or output voltage) from
the temperature transducer (Ω or V)
o RrefR_{\text{ref}}Rref = Reference resistance (or voltage) at a known temperature (Ω or V)
o BBB = Temperature coefficient (from the transducer's datasheet)
o TrefT_{\text{ref}}Tref = Reference temperature (in °C)
3. Force Calculation:
The force measured by the load cell can be calculated using the following formula:
where:
14
SAMPLE CALCULATION
1. Pressure Calculation: Assume the pressure transducer has a sensitivity of 0.005 V/Pa and a zero
output of 0.2 V. If the measured output voltage is 2.0 V for a given pressure, the pressure can be
calculated as:
3. Force Calculation: For a load cell with sensitivity CCC of 0.02 V/N and a zero output of 0.5 V, if
the measured output voltage is 2.0 V under load, the force is calculated as:
RESULT
• Pressure Measurement:
o The measured pressures at different voltages are as follows:
▪ At V=2.0 VV = 2.0 \, \text{V}V=2.0V, Pressure = 360 Pa
▪ At V=3.0 VV = 3.0 \, \text{V}V=3.0V, Pressure = 540 Pa
• Temperature Measurement:
o The measured temperatures at different resistance values are as follows:
▪ At R=1100 ΩR = 1100 \, \OmegaR=1100Ω, Temperature = 25.025°C
▪ At R=1200 ΩR = 1200 \, \OmegaR=1200Ω, Temperature = 30.05°C
• Force Measurement:
o The measured forces at different voltages are as follows:
▪ At V=2.0 VV = 2.0 \, \text{V}V=2.0V, Force = 75 N
▪ At V=2.5 VV = 2.5 \, \text{V}V=2.5V, Force = 100 N
15
DIAGRAMS
1. DC Servomotor Control:
o Block Diagram for Speed Control:
css
Copy code
[Power Supply] --> [H-Bridge] --> [DC Servomotor] --> [Tachometer]
^ |
|----------------------|
2. AC Servomotor Control:
o Block Diagram for Speed Control:
css
Copy code
[AC Power Supply] --> [Frequency Controller] --> [AC Servomotor] -->
[Tachometer]
css
Copy code
[VFD] --> [Induction Motor] --> [Tachometer]
^ |
|-------------------------|
16
EX. NO.: 3
DATE:
AIM
To control the speed and direction of DC servomotor, AC servomotor, and induction motors using various
techniques.
APPARATUS REQUIRED
PROCEDURE
17
CALCULATIONS
where:
where:
where:
SAMPLE CALCULATION
1. DC Servomotor: If the armature voltage is 10V, and the motor constant kkk is 100 RPM/V, the
speed of the motor will be:
2. AC Servomotor: For an AC motor with a supply frequency f=50 Hzf = 50 \, \text{Hz}f=50Hz and
P=4P = 4P=4 poles:
3. Induction Motor: If the synchronous speed is 1500 RPM, and the slip sss is 0.02 (2%), the actual
speed will be:
18
RESULT
1. DC Servomotor:
o The speed of the DC servomotor was observed to increase with an increase in armature
voltage.
o Direction of rotation was reversed by changing the polarity.
2. AC Servomotor:
o The motor speed increased with the increase in supply frequency.
o The direction of the AC motor changed with phase reversal.
3. Induction Motor:
o The motor speed increased with the increase in supply frequency.
o The direction of the motor reversed when the phase sequence was altered.
19
20
EX. NO.: 4
DATE:
AIM
To write an assembly language program to add, subtract and multiply the given
data stored at two consecutive locations using 8051microcontroller.
21
22
MULTIPLICATION OF TWO 8 BIT NUMBERS
ALGORITHM
23
ADDITION OF TWO 8 BIT NUMBERS
OBSERVATION
Input:
4500: [Addend]
4501: [Augend]
Output:
4502: [Sum]
4503: [Carry]
INPUT:
4500: [MINUEND]
4501: [SUBTRAHEND]
OUTPUT:
4502: [DIFFERENCE]
4503: [SIGN BIT]
Input:
4500:[1stdata]
4501: [2nddata]
Output:
4502: [Lower byte of product]
4503: [Higher byte of product]
24
SUBTRACTION OF TWO 8 BIT NUMBERS
25
26
MULTIPLICATION OF TWO 8 BITNUMBERS
RESULT
Thus the addition, subtraction and multiplication of two numbers were
performed using the 8051 microcontroller.
27
DIAGRAM:
lua
Copy code
+5V -----> 8051 Microcontroller
|
P1 ----> L298 Motor Driver
|
----> DC Motor <----
|
Ground
lua
Copy code
+5V -----> 8051 Microcontroller
|
P1 ----> ULN2003 Driver
|
----> Stepper Motor <----
|
Ground
28
EX. NO.: 5
DATE:
AIM
• To interface and control a DC motor and a stepper motor using the 8051 microcontroller or a
PLC (Programmable Logic Controller).
• To develop the appropriate control programs for both motors and observe their operation.
APPARATUS REQUIRED
For PLC:
asm
Copy code
; DC Motor Control Program using 8051 Microcontroller
ORG 0H
; Initialize Ports
MOV P1, #00H ; Set Port 1 as output (Motor Driver)
MOV P2, #00H ; Set Port 2 as input (Control switch)
START:
MOV A, P2 ; Read input from control switch
JB ACC.0, FORWARD ; If switch bit 0 is 1, rotate motor forward
JB ACC.1, REVERSE ; If switch bit 1 is 1, rotate motor reverse
SJMP START ; Repeat until a switch is pressed
29
30
FORWARD:
MOV P1, #01H ; Send signal to motor driver for forward motion
SJMP START
REVERSE:
MOV P1, #02H ; Send signal to motor driver for reverse motion
SJMP START
END
asm
Copy code
; Stepper Motor Control Program using 8051 Microcontroller
ORG 0H
; Initialize Ports
MOV P1, #00H ; Set Port 1 as output (Stepper Motor driver)
START:
MOV A, P2 ; Read input for control sequence
JB ACC.0, STEP1 ; If switch bit 0 is 1, rotate motor in steps
SJMP START
STEP1:
MOV P1, #01H ; Activate coil 1 of stepper motor
CALL DELAY
MOV P1, #02H ; Activate coil 2 of stepper motor
CALL DELAY
MOV P1, #04H ; Activate coil 3 of stepper motor
CALL DELAY
MOV P1, #08H ; Activate coil 4 of stepper motor
CALL DELAY
SJMP START
DELAY:
MOV R0, #255
DELAY_LOOP:
MOV R1, #255
DELAY_LOOP2:
NOP
NOP
NOP
NOP
DJNZ R1, DELAY_LOOP2
DJNZ R0, DELAY_LOOP
RET
END
PROCEDURE
RESULT
• DC Motor Control: The DC motor responds to the input from the switches, rotating either forward
or backward based on the control signal sent by the microcontroller.
• Stepper Motor Control: The stepper motor rotates one step at a time when control pulses are sent
from the 8051. The program successfully sends the correct sequence of signals to drive the motor in
a specific direction.
33
CIRCUIT DIAGRAM
In this circuit:
34
EX. NO.: 6
DATE:
AIM
To program and interface a Traffic Light Control System using 8051 microcontroller with Assembly
language to manage traffic flow using Red, Yellow, and Green LEDs.
APPARATUS REQUIRED
PROCEDURE
MAIN:
SETB P2.0 ; Turn ON Red LED (P2.0)
CLR P2.1 ; Turn OFF Yellow LED
CLR P2.2 ; Turn OFF Green LED
ACALL DELAY ; Call delay subroutine (Red ON for a while)
8. Result
The traffic light control system was successfully programmed and interfaced with the 8051
microcontroller. The LEDs (Red, Yellow, and Green) responded in the expected sequence to simulate a
traffic control system.
37
DIAGRAM
38
EX. NO.: 7
DATE:
AIM
To study and implement the sequencing of hydraulic and pneumatic circuits using appropriate control
valves and actuators, demonstrating how sequential operations can be achieved in fluid power systems.
APPARATUS REQUIRED
PROCEDURE
RESULT
• Hydraulic Circuit:
o The sequence of cylinder operations was successfully achieved using directional control
valves.
o Adjusting the flow control valves influenced the speed of extension and retraction.
o The system demonstrated a stable and smooth sequential operation.
• Pneumatic Circuit:
o The pneumatic cylinders operated in a predefined sequence as controlled by the DCVs.
o The system allowed for easy adjustments in sequence timing using flow control valves.
o The operation was smooth with no significant air leakage observed.
41
DIAGRAM
42
EX. NO.: 8
DATE:
AIM
To simulate and analyse the sequencing of Hydraulic, Pneumatic, and Electro-pneumatic circuits using
simulation software.
APPARATUS REQUIRED
PROCEDURE
43
44
2. Implement Sequential Control:
o Use manual or automated control elements (like sensors or timers) to create a sequence.
o For example, Cylinder A extends, followed by Cylinder B after a delay.
3. Run the Simulation:
o Start the simulation to observe the sequence.
o Adjust flow control valves and timers to achieve the desired timing.
RESULT
45
DIAGRAM
46
EX. NO.: 9
DATE:
AIM
APPARATUS REQUIRED
• PLC (Programmable Logic Controller) with appropriate I/O modules (e.g., Siemens, Allen
Bradley, Delta)
• Electro-pneumatic Components:
o Double-acting pneumatic cylinders
o Solenoid-operated directional control valves (5/2 or 4/2 DCV)
o Air compressor with FRL unit (Filter, Regulator, Lubricator)
o Pneumatic hoses and connectors
• Electro-hydraulic Components:
o Hydraulic power pack (pump, reservoir, pressure relief valve)
o Double-acting hydraulic cylinders
o Solenoid-operated directional control valves
o Hydraulic hoses and fittings
• Electrical Components:
o Power supply (24V DC)
o Limit switches and proximity sensors
o Push buttons and indicator lamps
o Relay board (if needed for interfacing)
o Connecting wires and cables
• Software:
o PLC Programming Software (e.g., TIA Portal, RSLogix 5000, WPLSoft)
o Ladder Logic, Function Block Diagram (FBD), or Structured Text (ST) programming
PROCEDURE
1. Hardware Setup:
o Connect the PLC to the power supply (ensure correct voltage levels).
o Wire the solenoid-operated control valves to the digital output ports of the PLC.
o Connect the cylinder limit switches or sensors to the digital input ports of the PLC.
o If using an electro-hydraulic setup, connect the hydraulic power pack to the solenoid valves
and hydraulic cylinders.
2. Pneumatic/Hydraulic Connections:
o For electro-pneumatic:
▪ Connect the air compressor to the FRL unit.
▪ Attach the pneumatic cylinders to the solenoid valves using hoses.
o For electro-hydraulic:
▪ Connect the hydraulic power pack to the cylinders via hydraulic hoses.
▪ Ensure all connections are secure and free of leaks.
47
48
▪
3. PLC Programming:
o Open the PLC programming software on your computer.
o Create a new project and configure the PLC hardware settings.
o Develop a Ladder Logic (or any preferred) program to control the sequence of operations.
▪ Define inputs (limit switches, sensors, push buttons) and outputs (solenoids).
▪ Implement control logic to achieve a specific sequence (e.g., Cylinder A extends, then
Cylinder B extends, followed by retraction).
plaintext
Copy code
| Start PB (I0.0) |---[ ]----------------(Set Q0.0 - Cylinder A Forward)
| Cylinder A Ext. LS |---[ ]---------------(Set Q0.1 - Cylinder B Forward)
| Cylinder B Ext. LS |---[ ]---------------(Reset Q0.0, Reset Q0.1 - Retract)
• Explanation:
o When the Start button is pressed, Cylinder A extends (activating solenoid Q0.0).
o When Cylinder A reaches full extension, Cylinder B extends (activating solenoid Q0.1).
o When Cylinder B reaches full extension, both cylinders retract.
RESULT
49
50
EX. NO.: 10
DATE:
AIM
To design and implement a vision-based system for acquiring and processing images to perform automated
inspection and classification. The goal is to understand how computer vision techniques can be used for
quality control, object recognition, and sorting in industrial applications.
APPARATUS REQUIRED
• Hardware Components:
o Digital Camera or USB Webcam
o Lighting setup (LED lights or ring light) for consistent illumination
o Mounting stand or tripod for the camera
o Computer with sufficient processing power (preferably with a GPU)
o Calibration chart or object (e.g., checkerboard pattern) for camera calibration
• Software Tools:
o Image acquisition software (e.g., OpenCV, MATLAB, or NI Vision)
o Image processing software (e.g., Python with OpenCV library, MATLAB Image Processing
Toolbox)
o Integrated Development Environment (IDE) like PyCharm, Jupyter Notebook, or MATLAB
o Python libraries: opencv-python, numpy, scikit-learn, tensorflow (if using deep
learning models)
• Test Objects:
o A set of objects or items for inspection (e.g., manufactured parts, fruits, packages)
o Defective and non-defective samples for classification
Procedure
A. Image Acquisition
B. Image Processing
51
52
python
Copy code
import cv2
image = cv2.imread('test_image.jpg')
cv2.imshow('Captured Image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
python
Copy code
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edges = cv2.Canny(blurred, 50, 150)
cv2.imshow('Edges', edges)
python
Copy code
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
cv2.drawContours(image, [cnt], 0, (0, 255, 0), 2)
cv2.imshow('Contours', image)
4. Classification:
o Implement classification using Machine Learning or Deep Learning algorithms.
o Split the dataset into training and testing sets.
o Use algorithms like Support Vector Machine (SVM), K-Nearest Neighbors (KNN), or a
Convolutional Neural Network (CNN) for classification.
python
Copy code
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X_train, X_test, y_train, y_test = train_test_split(features, labels,
test_size=0.2)
model = SVC()
model.fit(X_train, y_train)
accuracy = model.score(X_test, y_test)
print(f'Classification Accuracy: {accuracy * 100:.2f}%')
python
Copy code
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Apply processing steps here
cv2.imshow('Live Feed', frame)
53
54
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
RESULT
• The vision-based system was able to successfully capture and process images for automated
inspection.
• The classification algorithm achieved an accuracy of X% (depending on the dataset and model
used).
• The system demonstrated robust performance in detecting defects or sorting objects based on
predefined criteria.
• Adjustments to lighting and camera calibration significantly improved the system’s accuracy.
55
56
INTERNET OF THINGS LABORATORY
57
DIAGRAM
plaintext
Copy code
+-------------------+
| DHT Sensor |
| (DHT11/DHT22) |
| |
+--------+----------+
|
| +---------------+
+----| ESP32/Arduino |
| |
| Wi-Fi |
+---------------+
|
| (Sends Data)
|
+---------------+
| Cloud |
| Platform |
+---------------+
58
EX. NO.: 1
DATE:
AIM
To create a simple IoT-based temperature monitoring system that sends temperature data to the cloud
for remote monitoring.
APPARATUS REQUIRED
PROCEDURE
1. Circuit Setup:
▪
VCC to 3.3V/5V
▪
GND to Ground
▪
Data pin to a digital pin (e.g., GPIO 4)
2. Programming:
➢ Use the Arduino IDE to upload a program that reads data from the DHT sensor and sends it
to the cloud.
➢ Example Code Snippet (for ESP32):
cpp
Copy code
#include <DHT.h>
#include <WiFi.h>
#include <HTTPClient.h>
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
59
60
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
HTTPClient http;
http.begin(server);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "field1=" + String(t);
http.POST(httpRequestData);
http.end();
3. Cloud Configuration:
o Sign up for a cloud service like Thingspeak.
o Create a new channel to receive temperature data.
o Obtain the API key and update it in the code.
4. Testing:
o Upload the code to the microcontroller.
o Monitor the serial output for connection status and data transmission.
o Check the cloud platform for incoming data.
OUTPUT
3. Expected Results:
• The web page will display the current temperature and humidity readings from the DHT11 sensor.
For example:
makefile
Copy code
Sensor Data
Temperature: 25.0 °C
Humidity: 60.0 %
RESULT
Thus a simple IoT-based temperature monitoring system was created and it sends temperature data
to the cloud for remote monitoring.
61
DIAGRAM
plaintext
Copy code
+---------------------+
| Motor |
+----------+----------+
|
| +----------------+
+---| Relay Module |
+----------------+
| |
+-----+ +-----+
| |
+----+-----+ +-----+----+
| Microcontroller | | Power |
| (ESP32/RPi) | | Supply |
+------------------+ +----------+
|
|
+---------------------+
| Internet |
+---------------------+
|
+-----+-----+
| Cloud/ |
| Mobile App|
+------------+
62
EX. NO.: 2
DATE:
AIM
To create a system that allows you to turn a motor ON or OFF using a microcontroller (like an ESP32 or
Raspberry Pi) through an internet connection.
APPARATUS REQUIRED
PROGRAM
1. Set Up Blynk:
o Create a Blynk account and set up a new project.
o Add a Button widget to control the motor.
o Get the Auth Token for your project.
2. Wiring:
o Connect the relay module to an output pin on the ESP32 (e.g., GPIO 23).
o Connect the motor to the relay according to the relay module's instructions.
3. Arduino Code:
cpp
Copy code
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h>
void setup() {
Serial.begin(115200);
Blynk.begin(auth, "your_SSID", "your_PASSWORD");
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Initially turn OFF
}
BLYNK_WRITE(V0) { // Button on V0
int motorState = param.asInt(); // Get value from the button
if (motorState == 1) {
digitalWrite(relayPin, HIGH); // Turn ON the motor
Serial.println("Motor ON");
63
CALCULATION
64
} else {
digitalWrite(relayPin, LOW); // Turn OFF the motor
Serial.println("Motor OFF");
}
}
void loop() {
Blynk.run(); // Keep Blynk running
}
OUTPUT
3. Expected Results:
• The web interface will display two buttons: "Turn ON" and "Turn OFF".
• When you click "Turn ON", the relay activates, and the motor will start running.
• When you click "Turn OFF", the relay deactivates, and the motor will stop.
RESULT
Thus the result of a system that allows you to turn a motor ON or OFF using a microcontroller
(like an ESP32 or Raspberry Pi) through an internet connection.
65
DIAGRAM
plaintext
Copy code
+-------------------+
| DHT Sensor |
| (DHT11/DHT22) |
+---------+---------+
|
|
+-----+------+
| Microcontroller |
| (ESP32) |
+-----+------+
|
|
+-------------------+
| Internet |
+-------------------+
|
+-------------------+
| Cloud Platform |
| (ThingSpeak/IO) |
+-------------------+
66
EX. NO.: 3
DATE:
AIM
To interface a temperature and humidity sensor (DHT11/DHT22) with a microcontroller (like ESP32 or
Raspberry Pi) and display the sensor data on a web-based dashboard.
APPARATUS REQUIRED
PROGRAM
1. Wiring:
o Connect the DHT sensor:
▪ VCC to 3.3V
▪ GND to Ground
▪ Data pin to a digital pin (e.g., GPIO 4)
2. Setup ThingSpeak:
o Create an account on ThingSpeak.
o Create a new channel to store temperature and humidity data.
o Note down the Write API Key for your channel.
3. Arduino Code:
cpp
Copy code
#include <DHT.h>
#include <WiFi.h>
#include <HTTPClient.h>
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
67
CALCULATION
arduino
Copy code
http://api.thingspeak.com/update?api_key=YOUR_API_KEY&field1=temperature&fi
eld2=humidity
68
Serial.println("Connected to WiFi");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
OUTPUT
makefile
Copy code
Sensor Data
Temperature: 25.0 °C
Humidity: 60.0 %
RESULT
Thus the result of a temperature and humidity sensor (DHT11/DHT22) with a microcontroller (like
ESP32 or Raspberry Pi) was interfaced, and the sensor data on a web-based dashboard were displayed.
69
DIAGRAM
plaintext
Copy code
+---------------------+
| Soil Moisture |
| Sensor |
+----------+----------+
|
|
+------+------+
| ESP32 |
| (Microcontroller) |
+------+------+
|
+---------------------+
| Relay Module |
+----------+----------+
|
|
+-----+-----+
| Solenoid |
| Valve |
+-----------+
|
+-------------+
| Power Supply |
+-------------+
70
EX. NO.: 4
DATE:
AIM
To interface a sensor (like a moisture sensor) with a microcontroller (ESP32) to control a solenoid valve
over the internet based on the sensor data.
APPARATUS REQUIRED
1. Microcontroller: ESP32
2. Sensor: Soil Moisture Sensor
3. Solenoid Valve: Typically 12V
4. Relay Module: To control the solenoid valve
5. Power Supply: For the solenoid valve
6. Breadboard and Jumper Wires
7. Wi-Fi Connection
8. Cloud Platform: Blynk or ThingSpeak for remote control
PROGRAM
1. Wiring:
o Connect the soil moisture sensor:
▪ VCC to 3.3V
▪ GND to Ground
▪ Signal pin to an analog pin (e.g., GPIO 34)
o Connect the relay module:
▪ IN pin to a digital pin on ESP32 (e.g., GPIO 23)
▪ Connect the solenoid valve according to the relay specifications.
2. Setup Blynk:
o Create a Blynk account and set up a new project.
o Add a Button widget to control the solenoid valve.
o Get the Auth Token for your project.
3. Arduino Code:
cpp
Copy code
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h>
// Define pins
const int moisturePin = 34; // Analog pin for soil moisture sensor
const int relayPin = 23; // Pin for relay control
void setup() {
Serial.begin(115200);
71
CALCULATION
72
Blynk.begin(auth, "your_SSID", "your_PASSWORD");
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Initially turn OFF solenoid
}
BLYNK_WRITE(V0) { // Button on V0
int motorState = param.asInt(); // Get value from the button
if (motorState == 1) {
digitalWrite(relayPin, HIGH); // Turn ON solenoid valve
Serial.println("Solenoid ON");
} else {
digitalWrite(relayPin, LOW); // Turn OFF solenoid valve
Serial.println("Solenoid OFF");
}
}
void loop() {
Blynk.run(); // Keep Blynk running
OUTPUT
yaml
Copy code
Soil Moisture Data
Soil Moisture Value: 450
Solenoid Valve: ON
RESULT
Thus a sensor (like a moisture sensor) was interfaced with a microcontroller (ESP32) to control a
solenoid valve over the internet based on the sensor data.
73
DIAGRAM
plaintext
Copy code
+-------------------+
| Temperature |
| Sensor |
| (DHT11/DHT22) |
+---------+---------+
|
|
+-----+------+
| ESP32 |
| (Microcontroller) |
+-----+------+
|
+---------------------+
| Relay Module |
+----------+----------+
|
|
+-----+-----+
| Linear/ |
| Rotary Actuator |
+-----------+
|
+-------------+
| Power Supply |
+-------------+
74
EX. NO.: 5
DATE:
AIM
To interface a sensor (e.g., a temperature sensor) with a microcontroller (ESP32) to control a linear or
rotary actuator over the internet based on the sensor data.
APPARATUS REQUIRED
1. Microcontroller: ESP32
2. Sensor: Temperature Sensor (e.g., DHT11 or DHT22)
3. Actuator: Linear or Rotary Actuator
4. Relay Module: To control the actuator
5. Power Supply: For the actuator
6. Breadboard and Jumper Wires
7. Wi-Fi Connection
8. Cloud Platform: Blynk or ThingSpeak for remote control
PROGRAM
1. Wiring:
o Connect the DHT sensor:
▪ VCC to 3.3V
▪ GND to Ground
▪ Data pin to an analog pin (e.g., GPIO 4)
o Connect the relay module to control the actuator:
▪ IN pin to a digital pin on ESP32 (e.g., GPIO 23)
2. Setup Blynk:
o Create a Blynk account and set up a new project.
o Add a Button widget to control the actuator.
o Get the Auth Token for your project.
3. Arduino Code:
cpp
Copy code
#define BLYNK_PRINT Serial
#include <DHT.h>
#include <BlynkSimpleEsp32.h>
// Define pins
const int sensorPin = 4; // Pin for DHT sensor
const int relayPin = 23; // Pin for relay control
75
CALCULATION
• Temperature Threshold:
o In the above program, the actuator turns ON when the temperature exceeds 30°C. This value
can be adjusted based on the specific application requirements.
• Relay Specifications:
o Ensure the relay is rated for the voltage and current required by the actuator. For example, if
the actuator requires 12V and draws 1A, use a relay rated for at least 10A and suitable for the
voltage.
76
void setup() {
Serial.begin(115200);
Blynk.begin(auth, "your_SSID", "your_PASSWORD");
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Initially turn OFF actuator
dht.begin();
}
BLYNK_WRITE(V0) { // Button on V0
int actuatorState = param.asInt(); // Get value from the button
if (actuatorState == 1) {
digitalWrite(relayPin, HIGH); // Turn ON actuator
Serial.println("Actuator ON");
} else {
digitalWrite(relayPin, LOW); // Turn OFF actuator
Serial.println("Actuator OFF");
}
}
void loop() {
Blynk.run(); // Keep Blynk running
// Read temperature
float t = dht.readTemperature();
Serial.print("Temperature: ");
Serial.println(t);
OUTPUT
vbnet
Copy code
Distance Measurement
Distance: 5.0 cm
Actuator: ON
77
78
RESULT
Thus a sensor (e.g., a temperature sensor) was interfaced with a microcontroller (ESP32) to control a
linear or rotary actuator over the internet based on the sensor data.
79
DIAGRAM
plaintext
Copy code
+-------------------+
| Temperature |
| Sensor |
| (DHT11/DHT22) |
+---------+---------+
|
|
+-----+------+
| ESP32 |
| (Microcontroller) |
+-----+------+
|
+------+------+
| Bluetooth / |
| Wi-Fi |
+------+------+
|
+-----------------+
| Smartphone |
| (App for Data) |
+-----------------+
80
EX. NO.: 6
DATE:
AIM
To interface a temperature and humidity sensor (e.g., DHT11) with a microcontroller (ESP32) and send
the sensor data to a smartphone using Bluetooth or Wi-Fi.
APPARATUS REQUIRED
PROGRAM
1. Wiring:
o Connect the DHT sensor:
▪ VCC to 3.3V
▪ GND to Ground
▪ Data pin to a digital pin (e.g., GPIO 4)
2. Arduino Code (for Bluetooth):
cpp
Copy code
#include <DHT.h>
#include <BluetoothSerial.h>
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32_Sensor"); // Bluetooth device name
dht.begin();
Serial.println("Bluetooth Device is Ready to Pair");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
81
CALCULATION
arduino
Copy code
http://api.thingspeak.com/update?api_key=YOUR_API_KEY&field1=temperature&fi
eld2=humidity
82
// Send data over Bluetooth
String data = "Temperature: " + String(t) + " °C, Humidity: " + String(h) + "
%";
SerialBT.println(data);
Serial.println(data);
cpp
Copy code
#include <DHT.h>
#include <WiFi.h>
#include <HTTPClient.h>
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" °C, Humidity: ");
Serial.print(h);
Serial.println(" %");
83
84
delay(5000); // Send data every 5 seconds
}
OUTPUT
• Upload the appropriate code (Wi-Fi or Bluetooth) to the ESP32 using the Arduino IDE.
• Open the Serial Monitor to view any debug messages.
• For Wi-Fi:
o Download the Blynk app and create a new project.
o Add two Value Display widgets to show temperature and humidity.
o Input the virtual pins (V0 for temperature and V1 for humidity).
o The app will display the sensor data in real-time.
• For Bluetooth:
o Use any Bluetooth terminal app on your smartphone (e.g., Bluetooth Terminal).
o Pair with "ESP32_Sensor".
o Open the connection to see the temperature and humidity data sent from the ESP32.
3. Expected Results:
yaml
Copy code
Temperature: 25.0 °C, Humidity: 60.0 %
RESULT
Thus a temperature and humidity sensor (e.g., DHT11) was interfaced with a microcontroller (ESP32)
and send the sensor data to a smartphone using Bluetooth or Wi-Fi.
85