1 of 21

Arduino Sensors!

Jessica

2 of 21

Nametag and Chess Piece Submission

FORM

3 of 21

Today’s agenda

  • HC-SR04: Ultrasonic Sensor
  • MQ 135: Air Quality Sensor
  • AM2320: Temperature Humidity Sensor

4 of 21

What are sensors?

  • Electrical devices that responds to certain types of inputs from the environment
  • Input can be light, heat, motion, moisture, pressure

5 of 21

Ultrasonic Sensor

  • Use ultrasound at 40000 Hz to measure distances and detect obstacles
  • Consist of a transmitter (Trig) that emits ultrasonic waves and a receiver (Echo) that detects the reflected waves
  • Commonly used for distance sensing, object detection, and robot navigation

6 of 21

Ultrasonic Sensor

  • Let’s first look at the main specifications
    • What do you think is important?

7 of 21

Ultrasonic Sensor

  • VCC: Short for Voltage Common Collector, is usually connected to 3V3 or 5V of the Nano
  • GND: Ground
  • Trig: It sends the ultrasound wave from the transmitter, connect to any digital pins
  • Echo: Listens for the reflected signal from the Trig pin, connect to any digital pins

8 of 21

Ultrasonic Sensor

How to find distance?

  • To generate a signal, set Trig on HIGH for 10 microsec
  • we receive a reflected pulse, the Echo pin will become LOW sooner than those 38ms

Distance:

  • = (Speed of sound x Time) / 2
    • Remember: time is in microsec

9 of 21

Useful Code for Ultrasonic

pulseIn(anypin, HIGH or LOW): Reads a pulse (either HIGH or LOW) on a pin, returns it in microseconds

delayMicroseconds(#of Sec): delay in microseconds

10 of 21

Ultrasonic Sensor DIY

Fill in the skeleton code

11 of 21

Ultrasonic DIY 2

Imagine if someone breaks into your house in the middle of the night, how would you know?

Make an ultrasonic burglar detecting device that will alarm you and light up a Red LED

12 of 21

MQ 135 Gas Sensor

  • Can detect air quality or different gases in air
  • Suitable for detecting of NH3,NOx, alcohol, Benzene, smoke, CO2…etc

13 of 21

MQ 135 Gas Sensor

A0: Analog output, connect to any analog pin

D0: Digital output, will be high when threshold output is reached. Control the threshold with pot

Vcc: 5V

GND: Ground

14 of 21

Precaution: MQ 135

  • You are suppose to preheat it for 12-24 hours, but since we don’t have the time in this workshop. You would have to do this at home if you want better results
  • The sensor gets HOT!!!
    • So be careful when handling it
  • Preheating: connect you sensor’s Vcc with (+) & GND on (-) the power module. and let it run for half a day.

15 of 21

MQ 135 Gas Sensor: DIY

Using your knowledge from the previous lectures

Write a simple code that would read the analog outputs from the A0 pin

16 of 21

MQ 135 Gas Sensor: DIY 2

What if there is a natural gas leak at your home? You wouldn’t even know because gas is invisible to the eye.

Make a gas detection device that would light up red, yellow, and green. Each color depicting how hazardous the gas levels are. Red as extremely dangerous, Yellow as mild, and Green as good air.

17 of 21

Temperature Humidity Sensor

  • Digital temperature & humidity sensor
  • Uses I2C
    • We will talk more about communication protocols such as SPI and I2C in the next workshop!

18 of 21

Temperature Humidity Sensor

Starting from the left the pins are:

  • VDD - this is power in, can be 3-5VDC
  • SDA - I2C data in/out, requires a pullup of 2-10K to VDD
  • GND - this is signal/power ground
  • SCL - I2C clock in, requires a pullup of 2-10K to VDD

19 of 21

SDA SCL pins on NANO

Connect SDA SCL pins to these nano

pins

20 of 21

Libraries + Temp & Humidity Sensors

  • Typically this is how you would interface with your sensors
  • Have complicated calculations easily accessible in different functions
  • All you do is call them
  • Library
    1. Search “AM232X” in Library manager
    2. OR Include the zip file in Add ZIP Library

21 of 21

Temp & Humidity Sensors: DIY

Call the functions in the library to display temperature and humidity

Code Link