Skillnad mellan versioner av "Grove - Temperature & Humidity"

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
 
 
(5 mellanliggande versioner av samma användare visas inte)
Rad 1: Rad 1:
 
+
[[Fil:Grove-temp-humidity.png|200px|thumb|right|Grove - Temperature & Humidity]]
 +
Fungerar inte i minusgrader.
  
 
== Kompatibilitet ==
 
== Kompatibilitet ==
 
* Arduino
 
* Arduino
* Raspberry Pi ==
+
* Raspberry Pi
  
 
== Port ==
 
== Port ==
Rad 9: Rad 10:
  
 
== Bibliotek ==
 
== Bibliotek ==
 +
För Arduino IDE:
 
https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor
 
https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor
  
Rad 94: Rad 96:
  
 
[[Category:Grove]]
 
[[Category:Grove]]
 +
[[Category:Grove-Sensor]]
 +
 
[[Category:Sensor]]
 
[[Category:Sensor]]
 +
[[Category:Kna-Wiki]]
 +
[[Category:Kna-Wiki]]

Nuvarande version från 4 februari 2021 kl. 07.30

Grove - Temperature & Humidity

Fungerar inte i minusgrader.

Kompatibilitet

  • Arduino
  • Raspberry Pi

Port

Digital

Bibliotek

För Arduino IDE: https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor

Exempelkod

Arduino

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() 
{
    Serial.begin(9600); 
    Serial.println("DHTxx test!");

    dht.begin();
}

void loop() 
{
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    float t = dht.readTemperature();

    // check if returns are valid, if they are NaN (not a number) then something went wrong!
    if (isnan(t) || isnan(h)) 
    {
        Serial.println("Failed to read from DHT");
    } 
    else 
    {
        Serial.print("Humidity: "); 
        Serial.print(h);
        Serial.print(" %\t");
        Serial.print("Temperature: "); 
        Serial.print(t);
        Serial.println(" *C");
    }
}

Raspberry Pi

import grovepi
import math
# Connect the Grove Temperature & Humidity Sensor Pro to digital port D4
# This example uses the blue colored sensor.
sensor = 4  # The Sensor goes on digital port 4.

# temp_humidity_sensor_type
# Grove Base Kit comes with the blue sensor.
blue = 0    # The Blue colored sensor.
white = 1   # The White colored sensor.

while True:
    try:
        # This example uses the blue colored sensor.
        # The first parameter is the port, the second parameter is the type of sensor.
        [temp,humidity] = grovepi.dht(sensor,blue)  
        if math.isnan(temp) == False and math.isnan(humidity) == False:
            print("temp = %.02f C humidity =%.02f%%"%(temp, humidity))

    except IOError:
        print ("Error")

Mer information

http://wiki.seeedstudio.com/Grove-TemperatureAndHumidity_Sensor/