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/11/21 21:33] ktokarzen: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:
Line 64: Line 64:
 <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);  DallasTemperature tempSensor(&oneWire); 
-                               //connect oneWire to DallasTemperature library+                             //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
 } }
  
Line 84: Line 84:
 { {
   tempSensor.requestTemperatures();                tempSensor.requestTemperatures();             
-                               //command to read temperatures+                             //command to read temperatures
   tempCelsius = tempSensor.getTempCByIndex(0);     tempCelsius = tempSensor.getTempCByIndex(0);  
-                               //read temperature (in Celsius)+                             //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 96: Line 96:
  
 </code> </code>
 +
 +<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 == == Humidity Sensor ==
Line 107: 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 131: Line 133:
 } }
 </code>  </code> 
 +
 +<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 == == Sound Sensor ==
Line 184: 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 230: Line 234:
 <code c> <code c>
 #include <HardwareSerial.h> #include <HardwareSerial.h>
-#include >Arduino.h>+#include <Arduino.h>
  
 // Define the serial port for the PMS5003 sensor // Define the serial port for the PMS5003 sensor
Line 244: Line 248:
   Serial.begin(9600);    Serial.begin(9600); 
      
-  pinMode(SET_PIN, OUTPUT);     //controls sensor's low power mode (LOW) -> controls fan down+  pinMode(SET_PIN, OUTPUT);     //controls sensor's low power mode  
 +                                //(LOW) -> turns fan down
   pinMode(RESET_PIN, OUTPUT);   //controls sensor's reset (LOW)   pinMode(RESET_PIN, OUTPUT);   //controls sensor's reset (LOW)
   digitalWrite(SET_PIN, HIGH);  //enable both   digitalWrite(SET_PIN, HIGH);  //enable both
Line 299: 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.1700602428.txt.gz · Last modified: 2023/11/21 21:33 by ktokarz
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