This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:hardware2:sensors_distance [2023/11/14 16:45] – pczekalski | en:iot-open:hardware2:sensors_distance [2024/05/27 15:02] (current) – ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Proximity and Distance Sensors ====== | ||
| + | {{: | ||
| + | == Infrared Sensor == | ||
| + | An infrared (IR) proximity sensor detects objects and measures distance without physical contact. IR sensor consists of an infrared emitter, a receiving sensor or array of sensors and a signal processing logic. The output of a sensor differs depending on the type – simple proximity detection sensor outputs //HIGH// or //LOW// level when an object is in its sensing range, but sensors which can measure distance output an analogue signal or use some communication protocol, like I2C to send sensor measuring results. | ||
| + | IR sensors are used in robotics to detect obstacles located a few millimetres to several meters from the sensor and in mobile phones to help detect accidental screen touching.\\Sample IR sensor device is present in figure {{ref> | ||
| + | |||
| + | <figure proxim1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure proxim2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | An example code: | ||
| + | <code c> | ||
| + | int irPin = A0; //Define an analogue A0 pin for IR sensor | ||
| + | int irReading; | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | //Begin serial communication | ||
| + | Serial.begin(9600); | ||
| + | // | ||
| + | pinMode(irPin, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | //Read the value of the IR sensor | ||
| + | irReading = analogRead(irPin); | ||
| + | //Print out the value of the IR sensor reading to the serial monitor | ||
| + | Serial.println(irReading); | ||
| + | delay(10); //Short delay | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | == Ultrasonic Sensor == | ||
| + | The ultrasonic sensor measures the distance to objects by emitting a short ultrasound sound pulse and measuring its returning time. The sensor consists of an ultrasonic emitter and receiver; sometimes, they are combined into a single device for emitting and receiving. Ultrasonic sensors can measure greater distances and cost less than infrared sensors but are more imprecise and interfere with each other' | ||
| + | Examples of IoT applications are robotic obstacle detection and room layout scanning. | ||
| + | |||
| + | <figure ultrasonic1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure ultrasonic2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | An example code: | ||
| + | <code c> | ||
| + | int trigPin = 2; //Define a trigger pin D2 | ||
| + | int echoPin = 4; //Define an echo pin D4 | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(9600); | ||
| + | pinMode(trigPin, | ||
| + | pinMode(echoPin, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | digitalWrite(trigPin, | ||
| + | delayMicroseconds(2); | ||
| + | | ||
| + | //Set the trigPin on HIGH state for 10 μs | ||
| + | digitalWrite(trigPin, | ||
| + | delayMicroseconds(10); | ||
| + | digitalWrite(trigPin, | ||
| + | | ||
| + | //Read the echoPin, return the sound wave travel time in microseconds | ||
| + | duration = pulseIn(echoPin, | ||
| + | // | ||
| + | distance = duration*0.034/ | ||
| + | | ||
| + | //Printing the distance on the Serial Monitor | ||
| + | Serial.print(" | ||
| + | Serial.println(distance); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | == Motion Detector == | ||
| + | The motion detector is a sensor that detects moving objects, primarily people. Motion detectors use different technologies, | ||
| + | Motion sensors are used in security alarm systems, automated lights and door control. As an example in IoT, the PIR motion sensor can detect motion in security systems in a house or any building.\\Sample PIR sensor is present in {{ref> | ||
| + | |||
| + | <figure motion1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure motion2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | An example code: | ||
| + | <code c> | ||
| + | |||
| + | //Passive Infrared (PIR) sensor output is connected to the digital 2 pin | ||
| + | int pirPin = 2; | ||
| + | //The digital reading from the PIR output | ||
| + | int pirReading; | ||
| + | |||
| + | void setup(void) { | ||
| + | //Begin serial communication | ||
| + | Serial.begin(9600); | ||
| + | // | ||
| + | pinMode(pirPin, | ||
| + | } | ||
| + | |||
| + | void loop(void) { | ||
| + | //Read the digital value of the PIR motion sensor | ||
| + | pirReading = digitalRead(pirPin); | ||
| + | //Print out | ||
| + | Serial.print(" | ||
| + | Serial.println(pirReading); | ||
| + | |||
| + | if(pirReading == HIGH) { //Motion was detected | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | delay(10); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | == Fluid Level Sensor == | ||
| + | A level sensor detects the level of fluid or fluidised solid. Level sensors can be divided into two groups: | ||
| + | * **continuous level sensors** that can detect the exact position of the fluid. Proximity sensors, like ultrasonic or infrared, are usually used for level detection. Capacitive sensors can also be used by recording the changing capacitance value depending on the fluid level. The output can be either analogue or digital value; | ||
| + | * **point-level sensors** can detect whether a fluid is above or below the sensor. A membrane with air pressure or changes in conductivity or capacitance can be used for level detection as a floating or mechanical switch. The output is usually a digital value that indicates //HIGH// or //LOW// value.\\ | ||
| + | Fluid level sensors can be used for smart waste management, measuring tank levels, diesel fuel gauging, liquid assets inventory, chemical manufacturing, | ||
| + | Sample level sensor is present in figure {{ref> | ||
| + | |||
| + | <figure levelsensor1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure levelsensor2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | An example code: | ||
| + | <code c> | ||
| + | int levelPin = 6; //Liquid level sensor output is connected to the digital 6 pin | ||
| + | int levelReading; | ||
| + | |||
| + | void setup(void) { | ||
| + | Serial.begin(9600); | ||
| + | pinMode(levelPin, | ||
| + | } | ||
| + | |||
| + | void loop(void) { | ||
| + | levelReading = digitalRead(levelPin); | ||
| + | Serial.print(" | ||
| + | Serial.println(levelReading); | ||
| + | delay(10); //Short delay | ||
| + | } | ||
| + | </ | ||