# Lecture 4 - Sensors and Peripherals

Jan. 24, 2018

### Lecture 4 - Sensors and Peripherals

1. Sensors and Peripherals
2. Outline Sensors ◦ Button ◦ Potentiometer ◦ Light Sensor ◦ Temperature Sensor ◦ Distance ◦ Gas Sensor ◦ Digital Sensors Peripherals ◦ LED ◦ 7 Segment ◦ 74595 ◦ LCD Questions 2
3. Sensors 3 Image from http://energia.nu/rapid-prototyping-made-easy-with-the-grove-base-boosterpack-starter-kit-from-seeedstudio/
4. Types 4 Analog ◦ Two pins ◦ There pins ◦ Use pin functions Digital ◦ Use some digital protocol ◦ Use libraries Two pins Three pins
5. Measuring Analog Voltage divider We measure the voltage in Vout We have errors ◦ Read many values and average them 5 Image from https://learn.sparkfun.com/tutorials/voltage-dividers/applications
6. Button “Analog Sensor” Resistance ◦ Infinite if released ◦ 0 if pressed 6
7. Button Debounce When the button is pressed ◦ Signal is bouncing ◦ Fast reading results in 0s and 1s Solutions ◦ Read more values and average them ◦ Use a trigger 7 Image from http://www.engscope.com/pic-example-codes/basic-io-button-debounce/
8. Potentiometer Variable resistance Connect the ◦ middle pin ◦ One Side pin 8
9. Potentiometer is a voltage divider Variable resistance Connect the three pins ◦ One side pin to Vcc ◦ The middle pin the analog ◦ One Side pin to the ground 9
10. Light Sensor Photo Resistor ◦ 2 pins ◦ R inverse proportional with the light Sensor ◦ Photo Resistor ◦ Voltage divider ◦ Three pins 10 Image from https://inventrom.wordpress.com/2014/11/27/the-thing-in-internet-of-things/
11. Photo Resistor 11 Image from https://inventrom.wordpress.com/2014/11/27/the-thing-in-internet-of-things/
12. Temperature Sensor Thermistor ◦ Resistance Parameters ◦ R25 resistance - 25 degrees ◦ B – constant 12 measuredV = pin 5 1023 TR = 5 measuredV R ratio = 1 B ln( TR 25R ) Temperature = 1 1 298 +ratio
13. Temperature Sensor LM35 Temperature Sensor 13 measuredV = pin 5 1023 Temperature = mesuredV *100
14. Gas Sensor Gas Sensor ◦ Heats up ◦ Three pins ◦ Vcc ◦ Signal ◦ Ground 14
15. Distance Sensor SRF04 ◦ Ultrasonic ◦ Sends a pulse ◦ Real time system ◦ Works on microcontrollers 15 Image from http://www.robot-electronics.co.uk/htm/srf04tech.htm
16. Distance Sensor Infrared ◦ Analog ◦ Measure voltage 16
17. Digital Sensors Use protocols ◦ SPI ◦ I2C 17
18. SPI Master / Slave ◦ One Master ◦ Several slaves ◦ Master always initiates communication Wires ◦ MOSI – Master Out Slave In ◦ MISO – Master In Slave Out ◦ SCLK – SPI Clock ◦ SSn – Slave Select Speeds 18
19. SPI 19 Image from http://dlnware.com/theory/SPI-Transfer-Modes
20. I2C Master / Slave ◦ One or more masters ◦ Several slaves ◦ Master always initiates communication ◦ Each device has an address Wires ◦ SDA – Serial Data Line ◦ SCL – Serial Clock Line Speeds ◦ Standard 100 Kbit ◦ Up to 3.4 Mbit 20