How to use sensors with Arduino
Summary
TLDRThis tutorial guides viewers on connecting and plotting data from four sensors using an Arduino. It covers the DHT-11 for temperature and humidity, HC-SR04 for range, HC-SR501 for motion detection, and the GY521 for orientation assessment. The script details the process of wiring, using third-party libraries for sensor data interpretation, and visualizing data with a serial plotter. It also touches on adding additional sensors and emphasizes the ease of setup for most Arduino sensor breakouts.
Takeaways
- 🔌 Connect and plot data from four sensors: DHT-11, HC-SR04, HC-SR501, and GY-521.
- 🔧 Start by powering the breadboard with the Arduino's 5V supply before connecting the DHT-11 sensor.
- 📚 Use a third-party DHT sensor library to simplify reading temperature and humidity data.
- 💻 Open a serial port and set the baud rate to 9600 bits per second to send sensor data from the Arduino to your desktop.
- 📊 Use the Arduino Serial Plotter to graph the data from the sensors.
- 📏 Connect the HC-SR04 ultrasonic range sensor using the same method as the DHT-11 and install its library for range measurements.
- 👁️🗨️ Wire the HC-SR501 motion detector similarly and use digitalRead to detect motion without needing a library.
- 🔄 Connect the GY-521 sensor using I2C communication, and install the MPU6050 library to read orientation data.
- 🔄 Use the getAngle commands to compute the GY-521's orientation, and test by rotating the sensor.
- 📺 For more Arduino tutorials, subscribe to the Curio Res channel.
Q & A
What are the four sensors mentioned in the tutorial?
-The four sensors mentioned are DHT-11 for measuring temperature and humidity, HC-SR04 for measuring range, HC-SR501 for detecting motion, and GY-521 for assessing orientation.
How should the DHT-11 sensor be connected to the breadboard?
-The DHT-11 sensor should be connected with the positive terminal to the 5-volt rail, the negative to ground, and the OUT or S pin to any of the Arduino digital pins.
Why is it not necessary to write code to interpret sensor readings from scratch?
-It is not necessary because third-party libraries are available that can be used to interpret sensor readings, simplifying the coding process.
What is the purpose of a third-party library in this context?
-A third-party library provides pre-written code that can be used to interact with specific sensors, making it easier to read and interpret data from those sensors.
How can one find and install a library for the DHT sensor?
-One can search for a DHT sensor library in the Arduino Library Manager, click 'More Info' to visit the repository, and then install the library from there.
What is the baud rate set for serial communication in the tutorial?
-The baud rate is set to 9600 bits per second for serial communication.
What command is used to start the DHT sensor in the code?
-The command used to start the DHT sensor is 'dht.begin()'.
Why is it important to wait for a tenth of a second in the loop function?
-Waiting for a tenth of a second ensures that sensor readings are taken and communicated at regular intervals.
How can one view the output of the HC-SR04 ultrasonic sensor?
-One can view the output of the HC-SR04 sensor using the Serial Plotter in the Arduino IDE.
What is the default unit of measurement for the HC-SR04 sensor's range?
-The default unit of measurement for the HC-SR04 sensor's range is in centimeters.
How does the HC-SR501 motion detector work?
-The HC-SR501 motion detector sends a 1 to the pin when motion is detected and a 0 when no motion is detected. It has a built-in delay that can be adjusted with screws on the sensor.
What communication protocol does the GY-521 sensor use?
-The GY-521 sensor uses I2C (Inter-Integrated Circuit) communication protocol.
What library is recommended for reading from the MPU-6050 sensor?
-The Talkin' MPU 6050 library is recommended for reading from the MPU-6050 sensor.
How can the sensor's orientation be estimated using the MPU-6050?
-The sensor's orientation can be estimated using the accelerometer and gyroscope readings from the MPU-6050, specifically by using the 'get angle' commands.
Outlines
🔧 Setting Up Sensors for Data Collection with Arduino
This paragraph provides a step-by-step guide to connecting and programming four different sensors with an Arduino. It covers using a DHT-11 sensor for temperature and humidity, an HC-SR04 for range detection, an HC-SR501 for motion detection, and a GY-521 for orientation assessment. The instructions start with wiring the DHT-11 sensor, including powering the breadboard rails with the Arduino's 5-volt supply. Users are advised to use a third-party library for interpreting sensor readings, and the process of installing and using the DHT sensor library is described in detail. Instructions also include setting up a serial port to send sensor data to a PC, using the Serial Plotter for data visualization, and coding practices for taking and printing sensor readings. Finally, users are guided on how to install and use libraries for other sensors like the HC-SR04 and the GY-521, along with advice on testing and verifying sensor readings.
📏 Fine-Tuning Sensor Outputs and Learning More
This paragraph focuses on refining sensor output and understanding the specifics of each sensor's library commands. It emphasizes the importance of checking examples in the library documentation to ensure proper usage. The GY-521 sensor, which includes both an accelerometer and a gyroscope, is highlighted for its capability to estimate orientation. Users are encouraged to test the GY-521 by rotating it in different directions to see how the orientation data changes. The paragraph concludes with a prompt to subscribe to the Curio Res channel for further learning about Arduino and related projects.
Mindmap
Keywords
💡DHT-11
💡HC-SR04
💡HC-SR501
💡GY-521
💡Arduino
💡Serial Plotter
💡Library
💡Breadboard
💡Baud Rate
💡I2C Communication
Highlights
Learn to connect and plot data from four sensors using Arduino.
Use a DHT-11 to measure temperature and humidity.
Utilize an HC-SR04 sensor for measuring range.
Incorporate an HC-SR501 motion detector for detecting motion.
Assess orientation using a GY-521 sensor, which includes an accelerometer and gyroscope.
Power the breadboard rails with the Arduino 5V supply before connecting sensors.
Search and install third-party libraries, like the DHT sensor library, from the Arduino Library Manager.
Include library headers and define sensor pins in the code to use the DHT sensor.
Use Serial.print and Serial.printline to send sensor data to the Arduino's serial port.
Set the baud rate to 9600 bits per second to match the data rate for serial communication.
Graph sensor data using the Arduino Serial Plotter.
Add additional sensors, like the HC-SR04 ultrasonic range detector, using similar wiring setups.
The GY-521 sensor communicates using I2C protocol, requiring specific wiring and library commands.
Adjust the delay of the HC-SR501 motion detector using the screws on the side of the sensor.
Test the GY-521 sensor by rotating it in different directions to assess orientation readings.
Transcripts
in this tutorial you'll learn to connect
and plot data from four
sensors you'll use a dht-11 to measure
temperature and humidity
and hc sr04 to measure range and hc
sr-501 to detect motion and a gy521 to
assess
orientation get started by hooking a
dht11
into the breadboard before wiring the
sensor power the breadboard rails with
the arduino 5 volt supply
when you connect the sensor be sure to
check the labels
connect the positive terminal to the 5
volt rail the negative to ground
and the out or s pin to any of the
arduino digital pins
writing code to interpret sensor
readings from scratch isn't necessary
you can use a third party library
instead search the library manager for a
dht
sensor library before selecting a
library click
more info to visit the repository where
the library is stored
once there look for examples these will
show you how to use the library examples
can also help you to identify if a
library is right for your current skill
level
this one looks good go ahead and install
the dht sensor library
first include the library headers so you
can use the library's classes and
functions
use a macro to define the sensor pen and
an instance of the dht class from the
dht library
in order to send sensor information from
the arduino to your desktop
you need to open a serial port and set
the data rate
set the baud rate to 9 600 bits per
second
start the sensor with a call to
dht.begin
you can graph data received from the
arduino on your pc using the serial
plotter
the serial.print and serial.printline
commands write text and numeric data to
the serial port as ascii text
the first line printed to the serial
port determines the legend on the plot
so let's add some descriptive names
using serial.print line
in the loop function start by waiting
for a tenth of a second
this ensures that sensor readings are
taken and communicated at regular
intervals
then take temperature and humidity
readings from the dht object
now that the readings have been taken
print them to the serial line
you'll also need to print a white space
character finish by printing a new line
character so that each set of readings
appears on a new line
now upload the code to the arduino and
open the serial monitor
set the baud rate to 9600 to match the
data rate set in the code
check that your legend is printed on the
first line and each sensor reading shows
in a new line below
now that your data is streaming close
the serial monitor and open the serial
plotter to graph the data
verify your sensor readings with a test
most arduino sensor breakouts have a
similar setup so adding additional
sensors is easy
let's add an hc sr04 ultrasonic range
detector
orient the sensor so that it is free
from obstructions
connecting the hc sr04 is just like
connecting the dht-11
the hc sr04 trigger and echo pins are
wired to digital pins on the arduino
install the ultrasonic library for the
hc-sr04
like the dht library the ultrasonic
library requires you to include a header
and define an instance of the ultrasonic
class
take a reading by calling the read
function from the ultrasonic class and
write the result to the serial line
open the serial plotter to view the
output of the ultrasonic sensor
the default measurements from this
library are in centimeters
how accurate are the hc sr04 range
measurements
wire the hc sr501 motion detector using
the same pattern you used to wire the
dht-11
the motion detector is so simple it
doesn't need a library
simply define the pin set it to input
mode and call the digital read function
when motion is detected the sensor will
send a 1 to the pin otherwise it will
send 0.
add an entry to the legend and print to
the serial line to complete the sensor's
code
the sr501 has a built-in delay between
motion detections
you can adjust the delay using the
screws on the side of the sensor
the fourth sensor is the gy521 breakout
this sensor uses i squared c
communication
so wire the serial data and serial clock
pins to the same pins on the arduino
these pins are labeled sda and scl on
both devices
you'll also need to wire the sensor to
the power rails
install the talkin mpu 6050 library and
follow the standard steps to read from
the sensor
the exact commands required depend on
the library so always check the examples
to learn which commands are necessary
the mpu-6050 has an accelerometer
and a gyroscope together these readings
can be used to estimate orientation
use the get angle commands to compute
the sensor's orientation
test the sensor by rotating it in
various directions
if you're interested in learning more
about arduino subscribe to the curio res
channel
تصفح المزيد من مقاطع الفيديو ذات الصلة
INTEGRATION OF SENSOR AND ACTUATORS WITH ARDUINO-I
IMPLEMENTATION OF IOT WITH RASPBERRY PI-I
Let's build a room sensor - Part 1 - Temperature, Humidity, and Bluetooth
Monitoring Suhu Dan Kelembaban Menggunakan ESP32 + DHT22 Dengan Protokol MQTT
How ultrasonic sensor works ? || Working of ultrasonic sensor HC SR-04
New Blynk IOT Smart Plant Monitoring System
5.0 / 5 (0 votes)