This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:hardware2:sensors_environment [2023/10/03 07:19] – pczekalski | en:iot-open:hardware2:sensors_environment [2024/05/27 12:07] (current) – ktokarz | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Environment Sensors ==== | + | ====== Environment Sensors |
- | + | {{: | |
- | ===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' | 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' | ||
* **thermocouple** – consists of two junctions of dissimilar metals, | * **thermocouple** – consists of two junctions of dissimilar metals, | ||
Line 44: | Line 44: | ||
</ | </ | ||
- | ===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> | 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> | ||
Line 63: | Line 63: | ||
<code c> | <code c> | ||
- | #include < | + | #include < |
- | #include < | + | #include < |
- | const int SENSOR_PIN = 13; | + | const int SENSOR_PIN = 13; |
- | OneWire oneWire(SENSOR_PIN); | + | OneWire oneWire(SENSOR_PIN); |
- | DallasTemperature tempSensor(& | + | DallasTemperature tempSensor(& |
+ | //connect oneWire to DallasTemperature library | ||
- | float tempCelsius; | + | float tempCelsius; |
void setup() | void setup() | ||
+ | |||
{ | { | ||
- | Serial.begin(9600); | + | Serial.begin(9600); |
- | tempSensor.begin(); | + | tempSensor.begin(); |
} | } | ||
void loop() | void loop() | ||
{ | { | ||
- | tempSensor.requestTemperatures(); | + | tempSensor.requestTemperatures(); |
- | tempCelsius = tempSensor.getTempCByIndex(0); | + | //command to read temperatures |
+ | tempCelsius = tempSensor.getTempCByIndex(0); | ||
+ | //read temperature (in Celsius) | ||
Serial.print(" | Serial.print(" | ||
- | Serial.print(tempCelsius); | + | Serial.print(tempCelsius); |
Serial.println(" | Serial.println(" | ||
Line 93: | Line 97: | ||
</ | </ | ||
- | ===Humidity Sensor=== | + | < |
+ | |||
+ | == 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:// | 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:// | ||
IoT applications include monitoring humidors, greenhouse humidity, agriculture, | IoT applications include monitoring humidors, greenhouse humidity, agriculture, | ||
Line 103: | Line 109: | ||
<figure humiditysensor2> | <figure humiditysensor2> | ||
- | {{ : | + | {{ : |
< | < | ||
</ | </ | ||
Line 128: | Line 134: | ||
</ | </ | ||
- | ===Sound Sensor=== | + | <note important> |
+ | |||
+ | == 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, | 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, | ||
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 |
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: | ||
</ | </ | ||
- | + | == 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, | 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, | ||
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> | ||
- | {{ : | + | {{ : |
< | < | ||
</ | </ | ||
Line 203: | Line 210: | ||
</ | </ | ||
- | ===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 | + | 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 |
- | + | ||
- | <todo @pczekalski> | + | |
- | **PMS5003 photo** | + | |
<figure airpolution1> | <figure airpolution1> | ||
- | {{:img |title}} | + | {{ :en: |
- | < | + | < |
+ | </ | ||
+ | |||
+ | <figure airpolution1_2> | ||
+ | {{ : | ||
+ | < | ||
</ | </ | ||
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' | + | #include < |
- | #define PMS_TXD 17 // To sensor' | + | # |
- | #define PMS_RESET // To sensor' | + | |
- | #define PMS_SET // To sensor' | + | |
- | #define length 31 // | + | |
- | //(does not include | + | |
- | unsigned char buffer[length]; | + | |
- | int PM_1_0=0; | + | // Define |
- | int PM_2_5=0; //variale | + | HardwareSerial pmsSerial(1); |
- | int PM_10=0; | + | #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() { |
- | | + | Serial.begin(9600); |
+ | | ||
+ | pinMode(SET_PIN, OUTPUT); | ||
+ | //(LOW) -> turns fan down | ||
+ | pinMode(RESET_PIN, OUTPUT); //controls sensor' | ||
+ | digitalWrite(SET_PIN, | ||
+ | digitalWrite(RESET_PIN, | ||
| | ||
+ | pmsSerial.begin(9600, | ||
} | } | ||
- | void loop() | + | void loop() { |
- | { | + | if (pmsSerial.available()) { |
- | if(Serial.find(0x42)) //detecting 0x42 means start of data frame from sensor | + | |
- | | + | |
- | | + | uint8_t |
- | if(buffer[0] | + | pmsSerial.readBytes(buffer, |
- | | + | |
- | | + | |
- | | + | |
- | | + | uint16_t pm25 = makeWord(buffer[10], buffer[11]); |
- | + | | |
- | Serial.print(" | + | |
- | Serial.print(PM_1_0); | + | Serial.print(" |
- | Serial.println(" ug/ | + | Serial.print(pm25); |
- | + | Serial.print(" ug/m3\t"); | |
- | | + | Serial.print(" |
- | Serial.print(PM_2_5); | + | Serial.print(pm10); |
- | Serial.println(" | + | Serial.println(" |
- | + | } | |
- | | + | |
- | | + | } |
- | | + | } |
- | | + | } |
+ | |||
+ | // Function to verify the checksum | ||
+ | bool verifyChecksum(uint8_t *data, int len) { | ||
+ | uint16_t checksum = 0; | ||
+ | | ||
+ | | ||
} | } | ||
+ | return (checksum == makeWord(data[len - 2], data[len - 1])); | ||
} | } | ||
</ | </ | ||
- | ===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, | 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, | ||
- | Popular examples of barometric sensors are BME280 and BMP280. Both include barometric sensors and temperature sensors built in for compensation and possible measurement, | + | Popular examples of barometric sensors are BME280 and BMP280. Both include barometric sensors and temperature sensors built in for compensation and possible measurement, |
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> | ||
- | {{ : | + | {{ : |
< | < | ||
</ | </ |