Ngee Ann Polytechnic
School of Engineering
Internet of Things (IoT) 44IOTG-012628
LAB 3: Sensors, Actuators and Interfaces 221129a
Use some sensors, actuators and their interfaces
Name: ____________________________________________ Lab Grp: ___________ Date: ____________
IMPORTANT:
Show your completed PREPARATION section to your supervisor
Complete the lab 3 quiz & submissions.
OBJECTIVES
Understand different types of sensors and their interfaces
Use libraries and write codes that are responsive to work with the sensors
EQUIPMENT
These are loan out during the lab
I2C Expansion board with OLED, RTC & MPU6050
Ultrasonic sensor (connect to G1 – P15) https://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger/
DHT11 sensor (connect to G2 – P32) https://www.seeedstudio.com/Grove-Temperature-Humidity-
Sensor-DHT11.html
PREPARATION
Apart from the preparation section, you can also complete first parts of the procedure, “Analog Read”,
“Analog Write” and programming problem 1 at home with your kitset. The rest will require lab equipment.
1. Sensors & Actuators
IoT Device Interacting with the Environment
Embedded systems have inputs from the environment and outputs to the environment. At the inputs we
have sensors (also often called transducers). At the outputs we have actuators
Light - Lamp
Switch/Pushbutton - ENVIRONMENT LED
Audio - Displays
Temperature - Switch
Humidity, pressure - Sensors at IoT Actuators Speaker
Proximity, magnetic - inputs Embedded at outputs Motor
Chemical, pH, gas - System Pump
Monitors/read Controls/write
Speed, acceleration - Valve
Distance, etc - etc
Various interfaces
The system monitors/reads the environment information using sensors. It does the necessary processing
and based on the results, the system controls/writes to the actuators to control the environment.
IOTG Lab 3 Oct 2024 Page 1 of 13
Sensors Interrupt Output
Some sensors have interrupt output to interrupt MCU when data is available, an example is MPU6050
which is used in this lab. However, we will not use its interrupt. Our program will only “poll” for data.
2. Simple Digital Sensors
The simplest sensors are ones that provide only a high/low signal to the microcontroller (MCU). Examples:
push button pressed or not pressed
switch close or open
object present or absence
motion detected or not
The output can be active high (high=true, low=false) or active low (low=true, high=false) depending on
the sensor circuit as illustrated in the switches (can be pushbuttons) circuits below.
Vcc Vcc
Active high: MCU
reads HIGH when
Active low: MCU closed
reads LOW when
closed
3. More Complex Digital Sensors
Ultrasonic Distance Sensor
An example of more complex digital sensor is an ultrasonic distance sensor.
Source: https://lastminuteengineers.com/arduino-sr04-ultrasonic-sensor-tutorial/
The Seeed Studio “Grove - Ultrasonic Distance Sensor” that we use in the lab, uses a single pin to output a
TRIGGER pulse to start a measurement, followed by changing the pin to input to measure the return
ECHO pulse width to determine the distance from the object based on the speed of sound.
Output a Change pin Measure input pulse width to
TRIGGER pulse to input determine object distance
MCU digital
input/output ECHO pulse from sensor
pin
10us
Sensor sends 40kHz
Ultrasonic burst
Reference: https://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger/
The ECHO Pulse width = time for burst to travel to the object and back at the speed of sound.
IOTG Lab 3 Oct 2024 Page 2 of 13
As the process above takes time depending on the distance of the object. The worst case is when no
object is in front. It is considered blocking. The library that we will use, uses interrupts at the rising and
falling edges of the echo signal for measurement, thus non-blocking.
The trend for ultrasonic sensors is to use the much simpler and versatile i2c interface covered in a later
section. Example https://wiki.dfrobot.com/URM07_I2C_Ultrasonic_Sensor__SKU_SEN0166_
Question: If the speed of sound is 340m/s and the ECHO pulse is 5ms, estimate the distance of the object.
Remember that 5ms is for the burst to travel to and from the object, i.e. double the actual distance.
____________________________________________________________________________
Other complex digital interface
There are other interfaces that require complex digital signaling. An example is RGB stick which has
libraries available to use them.
https://wiki.seeedstudio.com/Grove-RGB_LED_Stick-10-WS2813_Mini/
https://www.sdiplight.com/what-is-ws2813-led-and-how-to-use-ws2813/
4. Analog Sensors & ADC
An analog sensor circuit converts the physical analog world info (e.g. temperature) to an analog voltage.
The Analog-Digital-Converter (ADC) in the MCU converts the input analog voltage to a binary number for
processing. A 12-bit ADC will give a result in the range of 0 to 4095 (212-1).
Analog Physical
Sensor ADC MCU
World Info
(e.g. 0o to 100o C)
ADC gives a binary number
Analog Voltage (e.g. 0 to 3.3V) (e.g. 12-bits gives 0 to 4095)
A family of temperature sensors (TMP35, 36 & 37) have the following analog output characteristics.
(Source: Analog Devices datasheet)
For the above sensors, the relationships between temperature and output voltage are linear and the
conversion from the reading to temperature is straight-forward. Some analog sensors do not have linear
characteristics and would need more computations.
QUESTION: Refer to the TMP37 sensor characteristics graph.
Estimated temperature when its out voltage is 1.8V, is _______________
IOTG Lab 3 Oct 2024 Page 3 of 13
Write equation to convert reading n (0 for 0V and to 4095 3.3V) to voltage: _________________________
CHALLENGE (not compulsory): Write an equation that would convert the ADC reading (0 for 0V and 4095
for 3.3V) to a temperature for TMP37 using steps below.
Linear equation to convert voltage (assuming is < 2.0V) to temperature: ____________________________
Hint: From the graph above for TMP37, at 2V, temperature is 100°C and 0.5V is 25°C. You have to solve 2
equations to get the constant a and b for T=aV + b where T is temperature and V is voltage.
Equation to convert reading n to temperature: _______________________________________________
Limitations of Analog Sensors
Some key issues of analog sensors usage are
a. Non-linear sensor characteristics, thus computation can be more complex.
b. Accurate of the ADC.
c. Software required to compensate for the non-linearity of the sensor characteristic or/and ADC.
d. Challenges in PCB design. Issues like analog signal PCB traces resistance, grounding and interferences
from the rest of the circuit or environment affecting the integrity of the signal reaching the ADC input.
This is the biggest challenge.
These challenges gave rise to the modern sensors with digital interfaces.
QUESTION: What is the biggest challenge for using analog sensor? _________________________________
_______________________________________________________________________________________
5. Digital Interfaces for Sensors
Modern “sensor digital interfaces” (don’t be confused with the previous simple digital sensors) have all
the challenges previously mentioned taken care of in a single IC or module by the vendor. The sensor
provides a digital interface to communicate with the MCU (the master). The MCU configures the sensor
and obtains readings from it. Serial bus interface is always used, i.e. data is transferred bit by bit serially.
Sensors with Digital
Interface
MCU Master
Serial Digital Interface
Slave E.g. i2c, SPI, 1-wire, UART
Communication between the processor and the sensor can be:
Half-duplex: Only one device (either the master or slave and not both) can send data at any one time.
Full-duplex: Both the master and slave can send data at the same time.
The commonly used digital sensor interfaces used in the industry are:
1-wire
This is a simple low speed half-duplex serial communication interface between the processor and,
normally, a single device through a single wire. We will experiment with the DHT11 temperature and
humidity sensor that uses 1-wire interface
I2C – Inter-Integrated Circuit bus (most popular)
Only 2 signals are used to provide half-duplex serial communication between a master and multiple
slave devices. Typically 100kbps or 400kbps. Most i2c devices supports 400kbps nowadays.
The I2C Expansion board used in this lab has these I2C devices: OLED, MPU6050 and RTC.
IOTG Lab 3 Oct 2024 Page 4 of 13
SPI – Serial Peripheral Interface
Very high speed full-duplex serial communication between a master and multiple slave devices.
Typical can go beyond 10Mbps for interface to e.g. an SD storage card. It requires more connections
than I2C interface.
UART – Universal asynchronous receiver-transmitter
A simple point-to-point peer interface using a full-duplex transmit and a receive pin. The 2 devices
must operate in the same bit rate. GPS (Global Positioning System) and some LoRa (a long range
wireless communication) modules are typically interfaced through UART.
QUESTIONS: Which of the above interfaces are half-duplex? __________________________________
Which sensor used in this lab uses 1-wire interface? ______________________
Which devices used in this lab use I2C interface? ____________________________________________
6. The i2c Interface
I2C bus is a 2-wire bus for efficient inter-IC communication. All i2c devices can simply be connected to the
2-wire bus as below, greatly simplifying circuit interface. Each device has a unique 7-bit i2c address in the
system. In our i2c Expansion board, we have three i2c devices with addresses indicated:
OLED display with SSD1306 driver at 0x3C
PCF8563 Real-time Clock at 0x51
MPU6050 sensor with accelerometer, gyroscope and temperature sensor at 0x68
VD
Processor D
MPU6050 accelerometer, gyroscope sensor
OLED (0x68)
display driver (0x3C)
(Master) R RP
P
SCL
SDA
Temperature sensor Each device has a unique address
Real Time Clock (0x51)
In the circuit above, resistors Rp serve as pull-up resistors as all devices’ pins connected to the two signals
are open-drain type. This allows sharing of the signal by multiple devices. It has these characteristics:
When all connected open-drain outputs are “high”, i.e. all outputs are cut-off, i.e. “no-one” is
controlling the signal and it would be floating with indeterminate logic level. A resistor with one end
connected to the supply is required to ensure that the signal is pulled high under such condition.
If any of the outputs is low, i.e. short to GND, it would cause the signal to go low.
Features of the I2C-bus:
Only two shared bus lines: serial data (SDA) and serial clock (SCL).
A master (the processor) is connected to one or more slave devices through the 2 bus signals
Each slave device has a unique 7-bit address
Data is transferred serially in term of bytes (8-bit each time)
The SCL clock thus the transfer speed, is controlled by the master.
IOTG Lab 3 Oct 2024 Page 5 of 13
Only 1 device can control the SDA data line at any one time.
Data transfer rates:
o Standard mode: up to 100 kbps (kbit/s)
o Fast mode: up to 400kbps
o High-speed mode: up to 3.4 Mbps
Sequence of I2C Data Transfer
The sequence of data transfer is shown below:
Start7-bit addressData…Stop
condition+ 1 bit R/Wbyte(s)condition
From master
For write (to slave) 1 or more bytes of data from master
For read (from slave) 1 or more bytes of data from slave
The master first asserts a “start condition”. It then sends a 7-bit address to select a slave device with 1 bit
indicating a write (0) or read (1) operation, after which for
o write operation, master sends 1 or more bytes of data to the slave
o read operation, slave sends 1 or more bytes of data to the master
The transfer is terminated by the master by asserting a “stop condition”.
For each byte of data received, the device (master or slave depending on write or read) must send an
acknowledgement bit of value 0 (ACK) at the end of every byte received telling the sender that “all is well”.
Questions:
The names of the 2 i2c signals are ______________________________________
To distinguish one device from the other, each device has a unique _________-bit address.
How does a slave know that master wants to write data to it? ______________________________
__________________________________________________________________________________
The standard bit rate for i2c is _________________________________________.
Who controls the SCL? ________________________________________________
Who controls the SDA? ______________________________________________________________.
Who asserts the start and stop condition? ___________________________________________
Every byte transfer requires an acknowledgment. Which device is responsible to assert the ACK bit?
___________________________________________________________________________________
Why pull-up resistors are required for the I2C signals?
__________________________________________________________________________________
I2C API & Library
The standard low level Arduino I2C functions is found in the Wire.h that is well explained here
https://docs.arduino.cc/learn/communication/wire
A lightweight communication library over the Arduino framework library is here
https://github.com/Wh1teRabbitHU/Arduino-I2C
IOTG Lab 3 Oct 2024 Page 6 of 13
7. MPU6050 Sensor
The MPU6050 Sensor in the lab comes in a module form as shown below. It can measure gravitational
force, linear acceleration and gyroscope readings in 3 axes: x, y and z. It also has a temperature sensor
built-in. The 3 axes follow the “right-hand rule”. In the diagram below, the z-axis is pointing out of the
paper indicated by the arrow tip. The mobile phone acceleration xyz axes is also shown for comparison.
z Gravity is perpendicular to x and y., and
opposite to z.
y Readings: X = 0, Y = 0, Z = 1g
T echnology
y
M obile
D evice
. x
z x
g the gravity
z is pointing out of this page
An accelerometer measures gravitational force and the rate of change in velocity, the acceleration. They
are useful in measurement of parameters such as tilt, tilt angle, inclination, rotation, vibration, collision
and gravity. Examples of its applications:
Gaming device
Mobile phones
Robots with balancing capabilities
Human motion or fall detection
Quad copters
Crash detection and airbag deployment in vehicles.
Accelerometer Readings
The MPU6050 can measure acceleration in 3 axes. An accelerometer at rest relative to the earth
experience static acceleration from the gravitational force as illustrated below when the mobile phone is
placed horizontal flat.
The value measured by the accelerometer is usually in term of gravity values i.e. 1g, 2g, -1g, etc. 1g is
9.8m/s2. Referring to the mobile phone diagram above, when the gravity is perpendicular to an axis, the
reading would be 0 as the case for x- and y-axes. If it is directly opposite direction to the axis, the reading
is +1g as the case for z-axis. If it is in the same direction, it would be -1g.
Determine the acceleration experienced in the xyz directions in diagrams below. (z is pointing towards you
indicated by the “arrow tip”). Use +1g or -1g or 0.
z . y
y
10.10
X = __________ X = __________
Y = __________ x am
Thurs, Y = __________
Z = __________ March 14 Z = __________
.
z x 1g
1g
IOTG Lab 3 Oct 2024 Page 7 of 13
The xyz readings of the gravitational acceleration above enable the system to know the orientation of the
device. The readings also allow us to measure acceleration due to change of velocity, e.g. due to a fall.
The i2c address of MPU6050 is 0x68. Within the device, there are many internal registers with their
internal addresses (do not be confused with the device I2C address) for configuration setting and doing
measurement. Some of the internal registers are shown below.
The program must read the INT_STATUS register at address 0x3A and check if bit 0 (RAW_DATA_RDY_INT)
is 1. If it is 1, the accelerometer values from 0x3B onwards are valid. Reading for each axis consists of 2
bytes, a “_H” for high byte, “_L” for low byte.
8. Displays
The I2C Expansion board in the lab comes with an OLED 128x64 monochrome display similar to the one
described in link below. I2C interface is used to configure and control the OLED. It is similar to this device:
https://wiki.seeedstudio.com/Grove-OLED-Display-0.96-SSD1315/
The coordinate for the pixel is 0,0 at the top left. Though we can display graphic images, we will only
display text of a fixed size font where each character takes up 8x6 pixels.
0,0 SSD3106 128 x 64 pixels OLED
Hello World
QUESTION: What is the coordinate of the pixel at the bottom right? ___________________________
We’ll use this library: https://adafruit.github.io/Adafruit_SSD1306/html/class_adafruit___s_s_d1306.html
9. Actuators
Digital-Analog Converter (DAC)
This is the reverse of an ADC. ESP32 has a built in 8-bit DAC. The 8-bit binary is converted to an analog
output which can be used to drive external circuit.
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/dac.html
LED interface
Simple Digital out high/low to on/off can be active high, i.e. high is true or active low, low is true. The
interface below shows an active high and low LED interface circuit.
IOTG Lab 3 Oct 2024 Page 8 of 13
Vcc
Active high: MCU output Current Limiting Current Limiting
HIGH to on LED. Resistor Resistor
Output sources current, Active low: MCU output
flowing out of the pin LOW to on LED.
Output sinks current,
flowing into the pin
PWM for LED or Motor Speed Control
Pulse Width Modulation (PWM) is used to control the duty cycle of a fixed frequency output. The duty
cycle determines the average DC value, which the actuator responds to, e.g. average brightness of the LED
(we cannot observe high frequency blinking), or the motor speed.
We will use the “ESP32 analogWrite” library installed in lab 1, to control the brightness of the LED. In
conformance to standard Arduino Uno function:
void analogWrite( uint8_t pin , uint8_t value );
The value is unsigned 8-bit, thus has a range of 0 representing 0% duty cycle) to 255 (2 8-1) representing
100% duty cycle. If necessary, the library allows you to change the range. The output is illustrated below:
QUESTION:
For the LED circuit in the LED-PB board, to on the LED,
- the output pin has to output LOW/HIGH (cancel one)
- the current would flow OUT/INTO (cancel one) the output pin.
Determine average DC voltage when the output is at
50% duty cycle: _________________________ 75% duty cycle? ______________
To achieve 60% duty cycle at the output, the value to write to the pin is ______________________
IOTG Lab 3 Oct 2024 Page 9 of 13
Solid-State Relay (SSR)
There are Solid-State relays (SSRs) available for AC and DC circuits of different voltage and current ratings.
They have many advantages of SSR over mechanical relay. Refer here:
https://www.arrow.com/en/research-and-events/articles/crydom-solid-state-relays-vs-electromechanical-
relays
The AC light bulb interface used in the lab, uses an AC “zero crossing” SSR rated at 1.2A load as shown
below. The MCU digital output turns the internal diode on/off through high/low voltage and in turn,
switches the AC load on/off respectively. The AC circuit is well isolated from the MCU circuit. Thus, the
circuit is safe as long as the AC portion of the circuit are well sealed.
HIGH AC bulb
to on
Internals of the SSR AQH3213 Interface to MCU and AC load
DANGER: 230VAC is dangerous! If you build any circuit involving 230V AC, you MUST ENSURE that it is
ALWAYS SAFE for yourself and the user! You must let your supervisor check before turning the mains on!
Datasheet: https://sg.element14.com/panasonic-ew/aqh3213j/ssr-600v-1-2a/dp/2095717
CHECKPOINT 1: Show to your supervisor the completed preparation section ________________
PROCEDURE
A. Connections & Download
1. With the power disconnected, connect up the modules to the ESP32 kitset as below:
or DHT20 Temperature & Humidity Sensor (Black)
G0: Rotary Analog Potentiometer
G1: Ultrasonic Distance Sensor
G2: DHT11 Temperature & Humidity Sensor (Blue)
G3: AC Lamp (limited) I2C Expansion Board
G4: I2C Expansion Board OLED RTC
MPU6050
Note that you have to remove the LED-PB board before you can insert the cable for the I2C expander.
After inserting the cable, re-insert the LED-PB board with the 8 pins properly aligned to the socket.
IOTG Lab 3 Oct 2024 Page 10 of 13
2. Download the codes for lab 3 and unzip to e.g. D:\arduino-iot\lab3.
B. Analog Read
3. Sketch analogRead: Run the given analogRead sketch with the Editor and Serial Monitor windows
visible side-by-side. It does analog read at A5 and print the result every 2 seconds. Rotate the rotary
knob to adjust voltage at A5 to see the effect.
What is the maximum value as you adjust the rotary knob? _____________________________
When the voltage at A5 is 0 volt, the reading is 0. When it is 3.3V, the reading is at the maximum.
Explain why that is the maximum value: __________________________________________________
Write a formula to convert the reading to voltage: ___________________________________________
If the reading is 1500, calculate the estimated voltage at A5: __________________________________
Meaning of %4d at the Serial.printf() statement? ___________________________________________
4. Your sketch analogRead2: Save it as analogRead2 sketch and modify the code so that it reports both
the binary reading at A5, and its estimated voltage. Print the voltage (should be a float) using 4
columns with 2 decimal place.
The printing should be something like this: “Analog read at A5 = 802 is 0.65V”
The printf() format specifier should be %________________
5. Rewite analogRead_221104a.ino as analogRead.ino without the use of
#include <npsoe_iot_kit.h>
#include <ev_timertick.h>
But instead use #include <delays.h> to read and print out the analog reading every 2s. You
may refer to Lab 2 regarding the use of #include <delays.h>
C. Analog Write – PWM
6. Sketch analogWrite: Run the given analogWrite sketch with the Editor and Serial Monitor windows
visible side-by-side.
Note that this program assumes that you had installed the “ESP32 AnalogWrite” library by
Abdelouahed or ERROPiX. Install it if you had not done so,
This program does analogWrite() to the Red LED, starting from 0, with increments of 20 at 300 ms
intervals. When after a value of 255, it is reset to 0 and repeat. The 255 limit is due to the default 8 bits
used.
Based on the understanding of the program and the observation at the LED, when is the LED brightest?
When variable “val” is 0 or 255? _________________ which is _____________ % duty cycle.
Why it is brightest with this value? _____________________________________________________
7. PWM waveform at P23: Connect the scope ground to the GND at the I2C Expansion board. Be careful
not to short to other pins there. The I2C Expansion Board must be connected to the kitset as in step 1.
Set the scope trigger at RISING EDGE and trigger mode to NORMAL. Set the vertical scale to 1V/div
and time base to about 250us/div (depending on scope used). Adjust the trigger level if necessary.
IOTG Lab 3 Oct 2024 Page 11 of 13
Pin 23 is
labelled
GND
Try to clip and if necessary hold it while clipped. If can’t, remove the cover of the probe and very
carefully probe (don’t cause short to other pins) at pin 23 of the ESP32 module using one hand and use
the other hand to set the scope to observe the waveform. You should observe pulses.
Is the frequency of the pulses constant? ____________ Is the pulse width constant? ______________
Period of the pulses is _________________ thus the frequency is __________________
In the programming problem 1 near the end of the lab, you will combine the analogRead and
analogWrite sketches to use the analog Rotary to control the brightness of the LED.
8. Rewite analogWrite_221104a.ino as analogWrite.ino without the use of
#include <npsoe_iot_kit.h>
#include <ev_timertick.h>
But instead use #include <delays.h> to vary the brightness intensity of the Red LED. You may
refer to Lab 2 regarding the use of #include <delays.h>
CHECKPOINT 2: Submit your rewritten codes and show your answers to supervisor________________
D. I2C Devices Scan
Before you write codes to interface to an i2c device, you must know the device’s i2c address. This section
uses a program to scan i2c devices found in the bus.
Our I2C Expansion Board has three i2c devices, namely the OLED, PCF8563 RTC and the MPU6050 sensor.
9. Sketch i2cScan: With the I2C Expansion Board connected to Grove I2C (Grove G4), run the given
i2cScan sketch with the Editor and Serial Monitor windows visible side-by-side.
10. Base on your observation and the Preparation section, identify the i2c devices address.
OLED: _____________. PCF8563 RTC: ______________. MPU6050 sensor: ______________
11. Based on your observation and the study of the program. What does the program do?
__________________________________________________________________________________
__________________________________________________________________________________
How does the function scanDev() determine if the device is present (see the comments)?
__________________________________________________________________________________
__________________________________________________________________________________
IOTG Lab 3 Oct 2024 Page 12 of 13
E. MPU6050
The MPU6050 provides 3D accelerometer, 3D gyroscope and temperature readings.
12. We use the Adafruit MPU6050 library in this lab. If necessary, install as below.
Use Sketch > Include Library > Manage Libraries … to search for “Adafruit MPU6050” and install it.
13. Sketch demoMpu: With the I2C Expansion Board connected to Grove I2C (Grove G4), run the given
demoMpu sketch with the Editor and Serial Monitor windows visible side-by-side.
14. Record the Accelerometer readings for various positions of the MPU6050 shown below. 1g is about
9.8m/s2. Round off the recording as either 0g, +1g or -1g. For each of them, the values of 2 of the axes
should be close to 0 as they are perpendicular to gravity, and the other is either +1g or -1g. For all cases
in the diagram below, the 1g gravity is down.
z y
10.10
am
Thurs,
March 14
Horizontal Upside down
.
z x
1g
X = __________ X = __________ X = __________ X = ________ X = ________ X=_________
Y = __________ Y = __________ Y = __________ Y = ________ Y = ________ Y=_________
Z = __________ Z = __________ Z = __________ Z = __________Z = ________ Z=_________
CHECKPOINT 3: Show your answers to the supervisor________________
F. Programming Problem 1
15. Create a new sketch lab3-p1-ledControl to meet these requirements continuously:
a) Rotating the rotary adjusts the Red LED brightness.
b) When the rotary is at the extreme anti-clockwise, the LED should be off.
c) When it is at the extreme clockwise, the LED is fully on.
Use the codes from analogRead and analogWrite sketches as references.
Hint: You have to use Arduino map() function to map the A5 reading to value for analogWrite. Do a
search on how to use the Arduino map()and do some simple experiments to get familiar with it.
CHECKPOINT 4: Show and explain your working program to the supervisor________________
_
IOTG Lab 3 Oct 2024 Page 13 of 13