====== Environment Sensors ====== {{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\ == Temperature Sensor == A temperature sensor is a device used to determine the temperature of the surrounding environment. Most temperature sensors work on the principle that the material's resistance changes depending on its temperature. The most common temperature sensors are: * **thermocouple** – consists of two junctions of dissimilar metals, * **thermistor** – includes the temperature-dependent resistor, * **resistive temperature detector** – is made of a pure metal coil. The main difference between sensors is the measured temperature range, precision and response time. Temperature sensor usually outputs the analogue value, but some existing sensors have a digital interface ((http://www.electronics-tutorials.ws/io/io_3.html)). The thermistor can have a positive (PTC) or negative (NTC) thermal coefficient. For PTC, resistance rises with rising temperature, while resistance decreases in higher temperatures for NTC. An analogue thermistor must calculate the value read if the result should be presented in known units. Digital temperature sensors usually express the result in Celsius degrees or other units. Temperature sensors are most commonly used in environmental monitoring devices and thermoelectric switches. In IoT applications, the sensor can be used for greenhouse temperature monitoring, warehouse temperature monitoring to avoid freezing, fire suppression systems and tracking the temperature of the soil, water and plants. The sample temperature sensor is present in figure {{ref>tempsensor_1}} and connection schematic in {{ref>tempsensor_2}}.
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:thermistor.jpg?100 | Thermistor}} A thermistor
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_thermistor.png?200 | Arduino and thermistor circuit}} Arduino and thermistor circuit
An example code: //Thermistor sensor output is connected to the analogue A0 pin int thermoPin = 0; //The analogue reading from the thermistor output int thermoReading; void setup(void) { //Begin serial communication Serial.begin(9600); //Initialize the thermistor analogue pin as an input pinMode(thermoPin, INPUT); } void loop(void) { //Read the analogue value of the thermistor sensor thermoReading = analogRead(thermoPin); Serial.print("Thermistor reading = "); //Print out Serial.println(thermoReading); delay(10); } == Digital Temperature Sensor == Digital temperature sensors automatically convert the temperature reading into some known unit, e.g. Celsius, Fahrenheit or Kelvin Degrees. Digital thermometers use one of the popular communication links. An example of a digital thermometer is DS18B20 by Dallas Semiconductors (figures {{ref>ds18b20_1}} and {{ref>ds18b20_2}}). It uses a 1-Wire communication protocol; a sample schematic is present in the figure {{ref>ds18b20_3}}.
{{ :en:iot-open:hardware2:20230925_114533.jpg?100 | DS18B20 temperature sensor}} DS18B20 temperature sensor
{{ :en:iot-open:hardware2:20230925_114703.jpg?200 | DS18B20 temperature sensor, waterproof version}} DS18B20 temperature sensor, waterproof version
{{ :en:iot-open:hardware2:ds18b20_one_wire_schematics.png?300 | DS18B20 circuit (One Wire on pin 13)}} DS18B20 circuit (One Wire on pin 13)
#include //library for 1-Wire protocol #include //library for DS18B20 digital thermometer const int SENSOR_PIN = 13; //DS18B20 pin OneWire oneWire(SENSOR_PIN); //oneWire class DallasTemperature tempSensor(&oneWire); //connect oneWire to DallasTemperature library float tempCelsius; //temperature in Celsius degrees void setup() { Serial.begin(9600); //initialize serial port tempSensor.begin(); //initialize DS18B20 } void loop() { tempSensor.requestTemperatures(); //command to read temperatures tempCelsius = tempSensor.getTempCByIndex(0); //read temperature (in Celsius) Serial.print("Temp: "); Serial.print(tempCelsius); //print the temperature Serial.println(" C"); delay(1000); } Digital temperature sensors using 1-Wire are handy when communication speed is not crucial. 1-Wire offers longer distance and less cabling compared, e.g. to I2C and SPI. == Humidity Sensor == A humidity sensor (hygrometer) is a sensor that detects the amount of water or water vapour in the environment. The most common principle of air humidity sensors is the change of capacitance or resistance of materials that absorb moisture from the atmosphere. Soil humidity sensors measure the resistance between the two electrodes. Soluble salts and water amounts influence the resistance between electrodes in the soil. The output of a humidity sensor is an analogue signal value or digital value sent with some popular protocols ((https://www.engineersgarage.com/articles/humidity-sensor)). A DHT11 (temperature+humidity) sensor is present in figure {{ref>humiditysensor1}} and its connection to the microcontroller in {{ref>humiditysensor2}}.\\ IoT applications include monitoring humidors, greenhouse humidity, agriculture, art galleries and museum environments.
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:humidity_sensor_c.jpg?100 | Temperature and humidity sensor module}} Temperature and humidity sensor module
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_humidity.png?230 | Arduino Uno and humidity sensor schematics}} Arduino Uno and humidity sensor schematics
An example code ((http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/)): #include dht DHT; #define DHT_PIN 7 void setup(){ Serial.begin(9600); } void loop() { int chk = DHT.read11(DHT_PIN); Serial.print("Humidity = "); Serial.println(DHT.humidity); delay(1000); } DHT sensors use their own One Wire communication standard that is incompatible with standard 1-Wire, even if it uses a similar connection schema. == Sound Sensor == A sound sensor is a sensor that detects vibrations in a gas, liquid or solid environment. At first, the sound wave pressure makes mechanical vibrations, which transfer to changes in capacitance, electromagnetic induction, light modulation or piezoelectric generation to create an electric signal. The electrical signal is then amplified to the required output levels. Sound sensors can record sound and detect noise and its level.\\ Sound sensors are used in drone detection, gunshot alert, seismic detection and vault safety alarms.\\ Sample digital sound sensor is present in figure {{ref>soundsensor1}} and its application with Arduino in figure {{ref>soundsensor2}}.
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sound_sensor_c.jpg?100 | Digital sound detector sensor module}} Digital sound detector sensor module
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_sound.png?200 | Arduino Uno and sound sensor schematics}} Arduino Uno and sound sensor schematics
An example code: //Sound sensor output is connected to the digital 7 pin int soundPin = 7; //Stores sound sensor detection readings int soundReading = HIGH; void setup(void) { //Begin serial communication Serial.begin(9600); //Initialize the sound detector module pin as an input pinMode(soundPin, INPUT); } void loop(void) { //Read the digital value to determine whether the sound has been detected soundReading = digitalRead(soundPin); if (soundPin==LOW) { //When sound detector detected the sound Serial.println("Sound detected!"); //Print out } else { //When the sound is not detected Serial.println("Sound not detected!"); //Print out } delay(10); } == Chemical and Gas Sensor == Gas sensors are a group that can detect and measure the concentration of certain gasses in the air. The working principle of electrochemical sensors is to absorb the gas and create current from an electrochemical reaction. For process acceleration, a heating element can be used. For each type of gas, different kind of sensor needs to be used. Multiple types of gas sensors can also be combined in a single device. The single gas sensor output is an analogue signal, but devices with various sensors have a digital interface. The smoke or air pollution sensors usually use LED or laser that emits light and a detector normally shaded from the light. If there are particles of smoke or polluted air inside the sensor, the light is reflected by them, which can be observed by the detector.\\ Gas sensors are used for safety devices, air quality control, and manufacturing equipment. IoT applications include air quality control management in smart buildings and smart cities or toxic gas detection in sewers and underground mines.\\MQ-7 Carbon Monoxide detector is present in figure {{ref>gassensor1}} and its connection using analogue signal in figure {{ref>gassensor2}}.
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:gas_senor_c.jpg?100 | MQ-7 gas sensor}} MQ-7 gas sensor
{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_gas.png?230 | Arduino Uno and MQ2 gas sensor schematics}} Arduino Uno and MQ2 gas sensor schematics
An example code: int gasPin = A0; //Gas sensor output is connected to the analog A0 pin int gasReading; //Stores gas sensor detection reading void setup(void) { Serial.begin(9600); //Begin serial communication pinMode(gasPin, INPUT); //Initialize the gas detector pin as an input } void loop(void) { gasReading = analogRead(gasPin); //Read the analog value of the gas sensor Serial.print("Gas detector value: "); //Print out Serial.println(gasReading); delay(10); //Short delay } == Smoke and Air Pollution Sensors == The smoke sensors usually emit LED light, and a detector is typically shaded from the light. If there are particles of smoke present inside the sensor, the light is reflected by them, which can be observed by the detector.\\ Smoke detectors are used in fire alarm systems.\\ The air pollution sensors usually use a laser directed onto the detector. Between the laser and detector, the thin stream of air flows and pollution particles create shades on the detector. Thus, the detector can distinguish the sizes of particles and count the number of them.\\ Air pollution sensors are used in air purifiers and air quality measurement stations to monitor current air conditions, mainly in cities. Because the air pollution sensor generates more data, the serial connection is often used for reading measurement results. An example of an air pollution sensor that can count particles of PM1.0, PM2.5, and PM10 is PMS5003. PMS series sensors are controlled with a serial port and additional signalling GPIOs with 3.3V logic, but they require 5V to power on an internal fan that ensures correct airflow. A PMS5003 sensor is present in figures {{ref>airpolution1}} and {{ref>airpolution1_2}}, and its connection in figure {{ref>airpolution2}}.
{{ :en:iot-open:hardware2:20231003_084525.jpg?300 | PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - airduct fan side}} PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - airduct fan side
{{ :en:iot-open:hardware2:20231003_084542.jpg?300 | PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - connector side}} PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - connector side
{{ :en:iot-open:hardware2:pms5003.png?400 | PMS5003 connection circuit for ESP32 }} PMS5003 connection circuit for ESP32
An example code that uses the PMS5003 sensor: #include #include // Define the serial port for the PMS5003 sensor HardwareSerial pmsSerial(1); #define SET_PIN 22; #define RESET_PIN 4; #define RXD_PIN 16; //to TXD of the sensor #define TDX_PIN 17; //to RXD of the sensor bool verifyChecksum(uint8_t *data, int len); void setup() { Serial.begin(9600); pinMode(SET_PIN, OUTPUT); //controls sensor's low power mode //(LOW) -> turns fan down pinMode(RESET_PIN, OUTPUT); //controls sensor's reset (LOW) digitalWrite(SET_PIN, HIGH); //enable both digitalWrite(RESET_PIN, HIGH); pmsSerial.begin(9600, SERIAL_8N1, RXD_PIN, TXD_PIN); } void loop() { if (pmsSerial.available()) { if (pmsSerial.peek() == 0x42) { if (pmsSerial.available() >= 32) { uint8_t buffer[32]; pmsSerial.readBytes(buffer, 32); if (verifyChecksum(buffer, 30)) { uint16_t pm25 = makeWord(buffer[10], buffer[11]); uint16_t pm10 = makeWord(buffer[12], buffer[13]); Serial.print("PM2.5: "); Serial.print(pm25); Serial.print(" ug/m3\t"); Serial.print("PM10: "); Serial.print(pm10); Serial.println(" ug/m3"); } } } } } // Function to verify the checksum bool verifyChecksum(uint8_t *data, int len) { uint16_t checksum = 0; for (int i = 0; i < len - 2; i++) { checksum += data[i]; } return (checksum == makeWord(data[len - 2], data[len - 1])); } == Air Pressure Sensor == Air pressure sensors can measure the absolute pressure in the surrounding environment. Some popular sensors use a piezo-resistive sensing element, which is then connected to the amplifier and analogue digital converter. Frint-end uses the logic to interface the microcontroller. Usually, barometric sensor readings depend on the temperature, so they include the temperature sensor for temperature compensation of the pressure. Popular examples of barometric sensors are BME280 and BMP280. Both include barometric sensors and temperature sensors built in for compensation and possible measurement, while BME280 also consists of a humidity sensor. Communication with these sensors is done with an I2C or SPI bus. Barometric sensors are commonly used in home automation appliances for heating, venting, air conditioning (HVAC), airflow measurement and weather stations. Because air pressure varies with altitude, they are often used in altimeters. Sample connection schematic is present in figure {{ref>sensor_bme280_2}} and the module itself in figure {{ref>sensor_bme280}}.
{{ :en:iot-open:hardware2:20230925_115510_-_kopia.jpg?200 | BME 280 air pressure sensor board}} BME 280 air pressure sensor board
{{ :en:iot-open:hardware2:bme280_schematics.png?230 | BME 280 connection circuit (I2C)}} BME 280 connection circuit (I2C)
Opposite to the BMP280 (pressure only sensor), BME280 module boards usually do not contain voltage regulators and need to be powered with 3.3V (and so must be the signal logic). An example code of BME280 use is below: #include #include #include #define BME_ADDRESS 0x76 Adafruit_BME280 bme; // I2C void setup() { Serial.begin(9600); bool status; Wire.begin(5,4); //SDA=GPIO5, SCL=GPIO4) status = bme.begin(BME_ADDRESS); if (!status) { Serial.println("Could not contact BME sensor"); while (1); } delay(1000); } void loop() { Serial.print("Temperature="); Serial.print(bme.readTemperature()); Serial.println("*C"); Serial.print("Air pressure="); Serial.print(bme.readPressure() / 100.0F); Serial.println("hPa"); Serial.print("Humidity="); Serial.print(bme.readHumidity()); Serial.println("%rh"); Serial.println(); delay(1000); }