0% found this document useful (0 votes)
6 views

def_arduino

Chapter 02 discusses various sensors and devices including the DHT22 temperature and humidity sensor, MPU-6050 accelerometer and gyroscope, electromagnetic relays, and optical encoders. Each device is described in terms of its functionality, specifications, and applications, highlighting their importance in automation and control systems. The chapter provides detailed technical information, including datasheets and pinouts for the sensors, as well as the operational principles of relays and encoders.

Uploaded by

malakmmalaks333
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

def_arduino

Chapter 02 discusses various sensors and devices including the DHT22 temperature and humidity sensor, MPU-6050 accelerometer and gyroscope, electromagnetic relays, and optical encoders. Each device is described in terms of its functionality, specifications, and applications, highlighting their importance in automation and control systems. The chapter provides detailed technical information, including datasheets and pinouts for the sensors, as well as the operational principles of relays and encoders.

Uploaded by

malakmmalaks333
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Chapter 02

1. Temperature Sensor (Digital-output relative humidity & temperature


sensor/module DHT22 (DHT22 also named as AM2302) :
This is the most accurate (while remaining affordable) temperature and
humidity sensor. It offers a detection range between -40°C and +80°C and a humidity
range between 0 and 100%, making it much more versatile than the DHT11. This
sensor pre-installed on a circuit includes a DHT22 sensor (increasingly called
AM2302) pre-configured for digital temperature and humidity. The signal is very
stable over the long term. The extremely short response time, its protection against
interference, its small size, it’s very low consumption and its low cost make this
sensor a reference for home automation or environmental monitoring projects
requiring a very wide measurement range. The serial interface of the DHT22 sensor
uses only 3 cables [(-), (+) and out (signal)] makes the use of this module easy.

1.1.1. Datasheet:
(chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://cdn.sparkfun.co
m/assets/f/7/d/9/c/DHT22.pdf)
Model DHT22

Power supply 3.3-6V DC

Output signal digital signal via single-bus

Sensing element Polymer capacitor

Operating range humidity 0-100%RH ;


temperature -40C°~80 C°

Accuracy humidity +-2%RH (Max +-5%RH);


temperature <+-0.5 C°

Resolution or sensitivity Humidity 0.1%RH;


temperature 0.1 C°
Repeatability Humidity +-1%RH;
temperature +-0.2Celsius

Humidity hysteresis +-0.3%RH

Long-term Stability +-0.5%RH/year

Sensing period Average : 2s


Interchangeability Fully interchangeable

Dimensions small size 14*18*5.5mm; big size


22*28*5mm

1
Chapter 02

1.1.2. Features & Applications:


(chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://cdn.sparkfun.co
m/assets/f/7/d/9/c/DHT22.pdf)
 Full range temperature compensated
 Calibrated digital signal
 Relative humidity and temperature measurement
 Outstanding long-term stability
 Extra components not needed
 Long transmission distance
 Low power consumption
 4 pins packaged and fully interchangeable
1.1.3. Description :
(chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://cdn.sparkfun.co
m/assets/f/7/d/9/c/DHT22.pdf)

DHT22 outputs a calibrated digital signal. It uses a proprietary digital signal


collection technique and humidity sensing technology, ensuring its reliability and
stability. Its sensing elements are connected to an 8-bit single-chip computer. Each
sensor of this model is temperature compensated and calibrated in a precise
calibration chamber and the calibration coefficient is recorded as a program in the
OTP memory, when the sensor detects, it will quote the coefficient from the memory.
Small size, low power consumption and long transmission distance (20m) make
DHT22 suitable for all kinds of harsh applications. Single-row package with four pins,
making the connection very convenient.

1.2. Capteur de vibration (Accéléromètre MPU6050) :


(https://randomnerdtutorials.com/esp32-mpu-6050-accelerometer-gyroscope-
arduino/)
1.2.1. Introducing the MPU-6050 Gyroscope Accelerometer Sensor:

The MPU-6050 is a module with a 3-axis accelerometer and a 3-axis gyroscope;

The gyroscope measures rotational speed (rad/s), which is the change in


angular position over time along the X, Y, and Z axes (roll, pitch, and yaw). This
allows us to determine the orientation of an object. The accelerometer measures
acceleration (rate of change in the object's speed).
It detects static forces such as gravity (9.8 m/s2) or dynamic forces such as vibration
or motion. The MPU-6050 measures acceleration along the X, Y, and Z axes. Ideally,
in a static object, the acceleration along the Z axis is equal to the gravitational force

2
Chapter 02

and it should be zero along the X and Y axes.

1.2.2. MPU-6050Pinout :
Voici le bronchement du module de capteur MPU-6050 :

VCC Power the sensor (3,3V or 5V)

GND Common GND

SCL SCL pin for I2C communication (GPIO 22)

SDA SDA pin for I2C communication (GPIO 21)

XDA Used to interface other I2C sensors with the MPU-6050

XCL Used to interface other I2C sensors with the MPU-6050

AD0 Use this pin to change the I2C address

INT Interrupt pin – can be used to indicate that new measurement data is available.

1.2.3. MPU6050 Features:


(https://components101.com/sensors/mpu6050-module)

 MEMS 3-aixs accelerometer and 3-axis gyroscope values combined


 Power Supply : 3-5V
 Communication : I2C Protocol
 Built-in 16-bit ADC provides high accuracy
 Built-in DMP provides high computational power
 Can be used to interface with other IIC devices like magnetometer
 Configurable IIC Address
 In-built Temperature sensor

3
Chapter 02

1.2.4. Axis Gyroscope :


The MPU6050 consists of a 3-axis Gyroscope with Micro Electro Mechanical System
(MEMS) technology. It is used to detect rotational velocity along the X, Y, Z axes as
shown in the below figure.

1.2.5. Axis Accelerometer :


The MPU6050 consists of a 3-axis Accelerometer with Micro Electro Mechanical
(MEMs) technology. It used to detect the angle of tilt or inclination along the X, Y, and
Z axes as shown in the below figure.

4
Chapter 02

1.2.6. Where to Use MPU6050:


(https://components101.com/sensors/mpu6050-module)

The MPU6050 is a Micro Electro-Mechanical Systems (MEMS) which consists


of a 3-axis Accelerometer and 3-axis Gyroscope inside it. This helps us to measure
acceleration, velocity, orientation, displacement and many other motion related
parameter of a system or object. This module also has a (DMP) Digital Motion
Processor inside it which is powerful enough to perform complex calculation and thus
free up the work for Microcontroller.

1.3. Electromagnetic Relay: https://www.omchsmps.com/electromagnetic-relay/


1.3.1. Definition :

An electromagnetic relay is a switching device that uses a magnet to turn the


switch on or off. They belong to the category of electromechanical devices.
Electromechanical devices use physical contacts
to switch the outputs. Due to the movements
occurring inside the switch, they have a
characteristic ‘ticking’ sound during operation.

Relays are used to control a larger electrical load


using a small input signal. For example, the input
from a small push button can activate a relay and
thereby control a large induction motor; where the
pushbutton alone is not sufficient to turn on/off the
motor directly.

A relay basically consists of a coil and a set of


spring-mounted moving contacts. There are
multiple types of relays based on their construction
and mode of operation. Let’s look at the basic
functionality of an electromagnetic relay.

Figure 0 :

1.3.2. How does the electromagnetic relay :


The primary components of a relay are the solenoid/electromagnet, armature-spring
assembly and the contacts. Let’s discuss their individual tasks, and how they work
together to act as a switch.

5
Chapter 02

Figure 0: how does electromagnetic relay work

The solenoid (also known as the electromagnet) is a copper coil wound around a
ferromagnetic material. This is typically a solid iron core. When a voltage is applied to
the coil, a magnetic field is generated around the coil.The iron core concentrates this
magnetic field to become a magnet until the voltage to the coil is removed.

Solenoids are usually operated using DC current, and are not compatible with AC
sources. However there are AC operated relays also available.AC relays have an
additional component in the electromagnet named ‘shading ring’. This prevents the
electromagnet from demagnetizing whenever the AC supply crosses the zero point.
Therefore, the armature can stay attracted to the electromagnet as long as the coil is
powered on.

The armature-spring assembly is the moving component that is found in a relay. The
armature is positioned such that when the electromagnet is powered on, it can
deflect the armature towards it.

There is a return spring in place to ensure that the armature returns to its initial
position when the coil is not powered on. The armature is conductive as it should
carry the switching current from the common terminal to the output terminals.

The contacts are the next most important and most abused parts in a relay. When
switching a load, the armature moves the contacts between the stationary contacts.
This causes sparks to generate. If the switched load is a highly inductive load such
as a motor, sometimes arcs can also be seen.

Once the coil is energized, the electromagnet activates. This causes the armature to
be attracted towards the electromagnet, which in turn makes the connection between

6
Chapter 02

the common contact and the normally open contact.At the same time, the connection
between normally closed contact and the common contact is severed.

There are several types of electromagnetic relays available. Some of them are used
to control heavy loads while others are used primarily as protection devices.

1.3.3. Electromagnetic Relay Types :

 Attracted Armature type relay :

Figure : Hinged Armature

 Induction Cup type relay :

Figure : induction cup type

7
Chapter 02

1.4. Optical encoder : https://etching-meltec.com/optical-encoder/


1.4.1. Definition:

This type of encoder uses an optical sensor to detect whether light is on or


off. This encoder characterized by its ability to handle high precision and high
magnetic fields.

Optical encoders include reflective, transmissive, and diffraction grating types. Since
ultra-thin stainless-steel plates or glass disks are used as rotating discs, mechanical
vibration and shock may be a problem.
Optical encoders are widely used in office equipment, machine tools and industrial
robots as high-precision position control sensors. In recent years, reflective encoders
have been used in ultra-compact actuators and in cooperative robots that require a
small amount of space.

Figure 03: Optical encoder

1.4.2. Difference from Magnetic Encoders :

There is a type of encoder called a “Magnetic Encoder” that is a counterpart to an


optical encoder. A magnetic encoder is a type of encoder that uses a magnetic
sensor to detect changes in the magnetic field. They are simple, compact, and highly
durable.

8
Chapter 02

The magnetic type combines a magnetic drum and a magneto-electric conversion


element such as a magneto-resistive element, and has a structure that can easily
increase mechanical strength.

On the other hand, its disadvantage is that its resolution and accuracy are lower than
those of optical encoders. This is because the resolution of magnetic encoders
depends on the performance of the signal processing circuit, since the resolution is
determined by the processing capacity of the electrical signal.

Feature/Type Optical Encoders Magnetic Encoders

High resolution ✓

High precision ✓

Environmental resistance ✓

Small size and light weight ✓

Low price ✓

1.4.3. Types of Optical Encoders :

They are classified by:


1.4.3.1. Direction of motion to be measured :
 Optical Linear Encoders:
This type of encoder irradiates light onto a slit pattern that moves along a linear axis,
detects the light that passes through (or is reflected by) the pattern with a sensor,
and outputs it as position information.

9
Chapter 02

Figure 04: Optical Linear Encoder ( Transmissive type)

 Optical Rotary Encoders :


This type of encoder irradiates light onto a rotating slit pattern, detects the light
that passes (or is reflected) by a sensor, and outputs it as position information.

This type of encoder is often used as a sensor in robotics. It reads a disk with evenly
spaced graduations. A code wheel with a rounded linear scale, which is a component
of a linear encoder, is used, and the technology used to manufacture both is similar.

They are used in a wide variety of applications, from inexpensive ones incorporated
into printers to high-precision control and measurement applications.

Figure 05: Optical Rotary Encoder (Reflective type)

1.4.3.2. Signal output method :


 Incremental type :
The rotation angle is measured by
converting the number of detected
pulses. The rotation speed is obtained
from the pulse interval or the number
of pulses in a unit time. In the
incremental type, only the change in
the rotation of the disk is known, and
the number of degrees of change in

10
Chapter 02

the sensor output from the reference position is counted and held in a counter
or memory.
Figure 06: Incremental Encoder Disk

 Absolut type :

This type of encoders output the absolute value of the rotation angle, and the
mechanical position is acquired immediately after power-on. While the incremental
type outputs only incremental values and requires origin alignment, the absolute type
outputs a one-to-one correspondence
between the disk angle of the scale pattern
and the output code, so the absolute angle
can always be known regardless of its power
state.

Thus, the absolute type has the advantage


of eliminating the need for origin alignment,
but the scale pattern is more complex and
the resolution tends to be lower than that of
the incremental type.

Figure 07: Absolut Encoder Disk

Feature /Type Absolut Incremental

High resolution ✓

No homing required ✓

Large feed rate ✓

Noise immunity ✓

11
Chapter 02

Low price ✓

1.4.3.3. Optical path :


Optical encoders can be classified into “transmission type” and “reflection type”
according to the optical path taken by the light-receiving element inside to detect the
light.
 Transmissive type:
The transmission type refers to a method in which a light source and a light-receiving
element are placed face to face through a space, and light is intercepted or
transmitted between them.

The advantages of the transmissive encoder are as follows.

 Easy to improve signal accuracy than


the reflective encoder.
 Easy to improve contamination
resistance.
 Relatively easy to design.
On the other hand, it also has the
following weaknesses:

 Narrow physical movement allowance.


 Limited design flexibility.

Figure 07: Optical linear


encoder (Transmissive type)

 Reflective type :

On the other hand, “Reflective type” refers to a method in which the light source and
the light-receiving element are placed on the same plane, and a component that
switches the reflection/non-reflection of light is placed above the light source and the
light-receiving element.

The advantages of the reflective encoder


are:

12
Chapter 02

 Easy to be manufactured thinner and smaller


 Simple assembly process
However, it has the following weaknesses
 Low contamination resistance
 Low signal accuracy Figure08 :Optical encoder
(Reflective type)

Feature /Type Transmissive Reflective

High signal accuracy


Contamination resistance ✓

Simple structure ✓

Miniaturization ✓

Assembly time ✓

1.4.4. Optical Encoder Structure :

Optical encoder mainly consists of the following three parts :

 Light Source.
 Photodetectors.
 Encoder Scale.
1.4.5. Where are Optical Encoder used :
 Joints of Robot Arm.
 Doors of Elevator.
 Printers.
 Machine tools.
1.4.6. How does an Optical Encoder work:

13
Chapter 02

Figure09: Explanation of How does an Optical Encoder work


In this section, we will explain the principle of optical encoder operation using an
optical transmissive rotary encoder as an example.
This type of encoder mainly consists of
o Light source (on the Infrared LED side).
o Photodetector (on the Photo IC side).
o Encoder disc engraved with bars that serve as scales.
The optical encoder disk, which is used to measure the number of rotations of the
motor, is mounted between the U-shaped parts shown in the illustration. This U-
shaped part is called a “photo interrupter”.
The photo interrupter contains an infrared LED and a photo IC placed between the
discs. When infrared light is irradiated, this mechanical part measures the number of
times the LED light passes through the bar hole of the disc.
The number is converted into an angle to detect the rotation angle and speed of the
disc.

2. Arduino IDE:

14
Chapter 02

The Arduino IDE (Integrated Development Environment) is an open-source


integrated development environment specifically designed for programming
microcontrollers used on Arduino boards. It provides a simplified user interface for
writing, compiling, and uploading code to Arduino boards. The Arduino IDE supports
a C/C++-based programming language, with specific libraries for interacting with
digital and analog inputs/outputs, serial communications, and other hardware
features of Arduino boards. The environment also includes a text editor with syntax
highlighting, a compiler, a debugger (via extensions), and a serial monitor for
communicating with the board. The Arduino IDE is widely used in education, rapid
prototyping, and DIY (Do-It-Yourself) electronics projects.

2.1. Connexion technique entre l'Arduino IDE et l'ESP32 :


The Arduino IDE acts as a development environment for writing, compiling, and
uploading code to the ESP32. The upload process uses a bootloader built into the
ESP32, which allows programming over a USB-to-serial connection. The IDE
generates a binary file from the source code and then sends it to the ESP32 over the
serial port. Once the program is uploaded, the ESP32 runs the code autonomously.
3. ESP32:
3.1. Definition:
ESP32 is a series of system-on-a-chip (SoC) microcontrollers from Espressif
Systems, based on Tensilica's Xtensa LX6 architecture, integrating dual-mode Wi-Fi
and Bluetooth (up to LE 5.0 and 5.11) management, and a DSP. It is an evolution of
ESP8266. The main development tool is ESP-IDF, free software developed by
Espressif, written in C and using the FreeRTOS real-time system. It integrates a large
number of libraries and its ecosystem includes free third-party libraries for different
types of peripherals related to embedded and real-time. The ESP32-C3, WiFi, BLE,
Bluetooth, is a variant, announced and released in November 2020, pin-compatible
with the ESP8266, but using the 32-bit RISC-V architecture rather than Xtensa2.
Development support via the Arduino platform and IDE has been available since the
ESP32 2.0.03 library. More generally, the ESP32-C series is based on RISC-V and
the ESP32-S series on Xtensa LX6.
Its Wi-Fi and Bluetooth support make it a popular system in the Internet of Things
field.
This SoC has been quite successful for a few years now due to its cost, capabilities
and integration into a growing number of systems.

15
Chapter 02

https://fr.wikipedia.org/wiki/ESP32

3.2. Technical characteristics:


The ESP32 includes the following 4 technical features:
• Processors:
• CPU: Xtensa dual-core (or single-core), 32-bit LX microprocessor, running at 160 or
240 MHz and providing up to 600 DMIPS;
• Ultra-low power coprocessor (ULP);
• Memory: 32 MB SRAM;
• Wireless connectivity:
• Wi-Fi: 802.11 b/g/n;
• Bluetooth: v4.2 BR/EDR and BLE up to v5.0 and v5.1;
• Device interfaces: 12-bit segmentation on ADC (SAR ADC) up to 18 channels; 2 ×
8-bit DAC;
• 10 × touch sensors (capacitive sensor GPIO (en));
• 4 × SPI;
• 2 × I²S interfaces;
• 2 × I²C interfaces;
• 3 × UART;

16
Chapter 02

• SD/SDIO/CE-ATA/MMC/eMMC host controller;


• SDIO/SPI socket controller;
• Ethernet MAC interface with dedicated DMA and support for IEEE 1588 precise
time protocol;
• CAN 2.0 data bus;
• Infrared remote controller (TX/RX, up to 8 channels);
• PWM motor; PWM LED (up to 16 channels);
• Hall effect sensor; Ultra-low power analog preamplifier.

3.2.1. ESP32 Memory:


Parameter name Parameter value
SRAM 520kb

ROM(Flash Memoire) 448kb

RTC SRAM 16kb

3.3. Why ESP32 ?


The microcontroller chosen is an ESP32 because:
 High frequency generation is simple
 Bluetooth and WiFi (to communicate with a phone or send data over
the Internet)
 Low power consumption Capacitive touch GPIO (water level
sensors)
 Many pins for many sensors
https://hackaday.io/project/191799-ultratower-2023/log/220846-functional-block-
diagram
3.4. Functions of ESP32:
The ESP32 has many applications in IoT. Here are some of the IoT functions
the chip is used for:
 Networking: The module’s Wi-Fi antenna and dual core allow embedded
devices to connect to routers and transmit data.
 Data processing: Includes processing basic analog and digital sensor inputs
to much more complex calculations with an RTOS or non-OS software
development kit (SDK). A non-OS SDK refers to an SDK that is designed to
run directly on the chip without a full operating system supporting it.

17
Chapter 02

 P2P connectivity: Creates direct communication between different ESPs and


other devices using IoT P2P connectivity.
 Web server: Provides access to pages written in HTML or development
languages.
3.5. Applications of ESP32 :
ESP32 modules are commonly found in the following IoT devices:

• Smart industrial devices, including programmable logic controllers


(PLCs)
• Smart medical devices, including wearable health monitors
• Smart energy devices, including heating, ventilation, and air
conditioning systems and thermostats
• Smart security devices, including surveillance cameras and smart locks

ESP32 for IoT: A Complete Guide

18

You might also like