Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:hardware2:sensors_environment [2023/10/03 07:19] pczekalskien:iot-open:hardware2:sensors_environment [2024/05/27 12:07] (current) ktokarz
Line 1: Line 1:
-==== Environment Sensors ==== +====== 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===+== 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: 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,   * **thermocouple** – consists of two junctions of dissimilar metals,
Line 44: Line 44:
 </code> </code>
  
-===Digital Temperature Sensor===+== 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}}. 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}}.
  
Line 63: Line 63:
  
 <code c> <code c>
-#include <OneWire.h>           // library for 1-Wire protocol +#include <OneWire.h>           //library for 1-Wire protocol 
-#include <DallasTemperature.h> //library for Dallas DS18B20 digital thermometer+#include <DallasTemperature.h> //library for DS18B20 digital thermometer
  
-const int SENSOR_PIN = 13;     //DS18B20 pin+const int SENSOR_PIN = 13;   //DS18B20 pin
  
-OneWire oneWire(SENSOR_PIN);   //oneWire class +OneWire oneWire(SENSOR_PIN); //oneWire class 
-DallasTemperature tempSensor(&oneWire); // connect oneWire to DallasTemperature library+DallasTemperature tempSensor(&oneWire);  
 +                             //connect oneWire to DallasTemperature library
  
-float tempCelsius;       // temperature in Celsius degrees+float tempCelsius;           //temperature in Celsius degrees
  
 void setup() void setup()
 +         
 { {
-  Serial.begin(9600);    //initialize serial port +  Serial.begin(9600);        //initialize serial port 
-  tempSensor.begin();    //initialize DS18B20+  tempSensor.begin();        //initialize DS18B20
 } }
  
 void loop() void loop()
 { {
-  tempSensor.requestTemperatures();             //command to read temperatures +  tempSensor.requestTemperatures();              
-  tempCelsius = tempSensor.getTempCByIndex(0);  //read temperature (in Celsius)+                             //command to read temperatures 
 +  tempCelsius = tempSensor.getTempCByIndex(0);   
 +                             //read temperature (in Celsius)
  
   Serial.print("Temp: ");   Serial.print("Temp: ");
-  Serial.print(tempCelsius);    // print the temperature+  Serial.print(tempCelsius); //print the temperature
   Serial.println(" C");   Serial.println(" C");
  
Line 93: Line 97:
 </code> </code>
  
-===Humidity Sensor===+<note>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.</note> 
 + 
 +== 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}}.\\ 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. IoT applications include monitoring humidors, greenhouse humidity, agriculture, art galleries and museum environments.
Line 103: Line 109:
  
 <figure humiditysensor2> <figure humiditysensor2>
-{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_humidity.png?200 | Arduino Uno and humidity sensor schematics}}+{{ :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}}
 <caption>Arduino Uno and humidity sensor schematics</caption> <caption>Arduino Uno and humidity sensor schematics</caption>
 </figure> </figure>
Line 128: Line 134:
 </code>  </code> 
  
-===Sound Sensor===+<note important>DHT sensors use their own One Wire communication standard that is incompatible with standard 1-Wire, even if it uses a similar connection schema.</note> 
 + 
 +== 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.\\ 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.\\ Sound sensors are used in drone detection, gunshot alert, seismic detection and vault safety alarms.\\
Line 158: Line 166:
    
 void loop(void) { void loop(void) {
-  //Read the digital value whether the sound has been detected+  //Read the digital value to determine whether the sound has been detected
   soundReading = digitalRead(soundPin);    soundReading = digitalRead(soundPin); 
   if (soundPin==LOW) { //When sound detector detected the sound   if (soundPin==LOW) { //When sound detector detected the sound
Line 169: Line 177:
 </code> </code>
  
- +== Chemical and Gas Sensor ==
-===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. 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.\\ 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.\\
Line 181: Line 188:
  
 <figure gassensor2> <figure gassensor2>
-{{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_gas.png?200 | Arduino Uno and MQ2 gas sensor schematics}}+{{ :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}}
 <caption>Arduino Uno and MQ2 gas sensor schematics</caption> <caption>Arduino Uno and MQ2 gas sensor schematics</caption>
 </figure> </figure>
Line 203: Line 210:
 </code> </code>
  
-===Smoke and Air Pollution Sensors===+== 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.\\ 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.\\ 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.\\ 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 do require 5V to power on an internal fan that ensures correct airflow. A PMS5003 sensor is present in figure {{ref>airpolution1}} and its connection in figure {{ref>airpolution2}}. +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}}.
- +
-<todo @pczekalski>PMS5003 photo</todo> +
-**PMS5003 photo**+
  
 <figure airpolution1> <figure airpolution1>
-{{:img |title}} +{{ :en:iot-open:hardware2:20231003_084525.jpg?300 PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - airduct fan side}} 
-<caption>PMS5003 laser sensor for PM1.0, PM2.5 and PM10</caption>+<caption>PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - airduct fan side</caption> 
 +</figure> 
 + 
 +<figure airpolution1_2> 
 +{{ :en:iot-open:hardware2:20231003_084542.jpg?300 | PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - connector side}} 
 +<caption>PMS5003 laser sensor for PM1.0, PM2.5 and PM10 - connector side</caption>
 </figure> </figure>
  
Line 224: Line 233:
 An example code that uses the PMS5003 sensor: An example code that uses the PMS5003 sensor:
 <code c> <code c>
-#define PMS_RXD 16 // To sensor's TXD +#include <HardwareSerial.h> 
-#define PMS_TXD 17 // To sensor's RXD +#include <Arduino.h>
-#define PMS_RESET // To sensor's RESET (pull to LOW to reset sensor) +
-#define PMS_SET // To sensor's SET (enable = HIGH) +
-#define length 31   //Size of the data frame from the sensor  +
-                    //(does not include the start indicator - 0x42) +
-unsigned char buffer[length];+
  
-int PM_1_0=0;    //variale to hold PM1.0 value of the air sensor +// Define the serial port for the PMS5003 sensor 
-int PM_2_5=0   //variale to hold PM2.5 value of the air sensor +HardwareSerial pmsSerial(1); 
-int PM_10=0    //variale to hold PM10 value of the air sensor+#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
  
-void setup() +bool verifyChecksum(uint8_t *data, int len); 
-+ 
-  Serial.begin(115200); +void setup() { 
-  Serial1.begin(9600SERIAL_8N1, PMS_RXDPMS_TXD);   +  Serial.begin(9600);  
 +   
 +  pinMode(SET_PINOUTPUT);     //controls sensor's low power mode  
 +                                //(LOW) -> turns fan down 
 +  pinMode(RESET_PINOUTPUT);   //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() +void loop() { 
-+  if (pmsSerial.available()) { 
-  if(Serial.find(0x42)) //detecting 0x42 means start of data frame from sensor +    if (pmsSerial.peek() == 0x42) { 
-      +      if (pmsSerial.available() >= 32) { 
-    Serial.readBytes(buffer,length)+        uint8_t buffer[32]; 
-    if(buffer[0] == 0x4d) +        pmsSerial.readBytes(buffer, 32); 
-      +         
-      PM_1_0=((buffer[3]<<8buffer[4])//count PM1.0 value of the air detector module +         
-      PM_2_5=((buffer[5]<<8) + buffer[6]); //count PM2.5 value of the air detector module +        if (verifyChecksum(buffer, 30)) { 
-      PM_10 =((buffer[7]<<8) + buffer[8]); //count PM10 value of the air detector module  +          uint16_t pm25 = makeWord(buffer[10]buffer[11]); 
-       +          uint16_t pm10 makeWord(buffer[12]buffer[13]); 
-      Serial.print("PM1.0: ");   +           
-      Serial.print(PM_1_0); +          Serial.print("PM2.5: "); 
-      Serial.println(" ug/m3");             +          Serial.print(pm25); 
-     +          Serial.print(" ug/m3\t"); 
-      Serial.print("PM2.5: ");   +          Serial.print("PM10: "); 
-      Serial.print(PM_2_5); +          Serial.print(pm10); 
-      Serial.println(" ug/m3");      +          Serial.println(" ug/m3"); 
-       +        } 
-      Serial.print("PM10:  ");   +      
-      Serial.print(PM_10); +    } 
-      Serial.println(" ug/m3")   +  } 
-    +
 + 
 +// Function to verify the checksum 
 +bool verifyChecksum(uint8_t *data, int len
 +  uint16_t checksum = 0
 +  for (int i = 0i < len - 2; i++) { 
 +    checksum += data[i];
   }   }
 +  return (checksum == makeWord(data[len - 2], data[len - 1]));
 } }
 </code> </code>
  
-===Air Pressure Sensor===+== 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.  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 includes a humidity sensor. +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.  Communication with these sensors is done with an I2C or SPI bus. 
  
Line 283: Line 304:
  
 <figure sensor_bme280_2> <figure sensor_bme280_2>
-{{ :en:iot-open:hardware2:bme280_schematics.png?200 | BME 280 connection circuit (I2C)}}+{{ :en:iot-open:hardware2:bme280_schematics.png?230 | BME 280 connection circuit (I2C)}}
 <caption>BME 280 connection circuit (I2C)</caption> <caption>BME 280 connection circuit (I2C)</caption>
 </figure> </figure>
en/iot-open/hardware2/sensors_environment.1696317555.txt.gz · Last modified: 2023/10/03 07:19 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0