Week 8 - Input devices

  1. Assignment
  2. Humidity and temperature sensor
  3. Code
  4. Result

Assignment

The Assignment for this week was the following:

  1. Develop a program that reads data from a sensor and that displays it Uses most of the techniques shown during the lecture.
  2. Connect a sensor or an input device to one of your Fab Lab made microcontroller boards.
  3. Upload the program into one of your Fab Lab made microcontroller boards, and show the data in the serial monitor.

Humidity and temperature sensor

For this Assignment I used a Humidity and temperature sensor. With a help of a library for the arduino IDE you can read and output the values of the sensor. The sensor has three pins.

  1. VCC pin
  2. GND pin
  3. And a OUT pin
You have to connect the VCC to VCC on your board. The same with GND to GND. Connect the out pin to a free digital pin on your board.

Code

To use the sensor you have to download the DHT-sensor library. You can find it here: DHT-sensor-library. You also have to download this library so the DHT-sensor-library will work properly Adafruit_Sensor. The code for this Assignment looks like this:


  #include "DHT.h"

  #define DHT_PIN 10
  #define DHTTYPE DHT11

  DHT dht(DHT_PIN, DHTTYPE);

  void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);
    Serial.println("Humidity and temperature monitor started!");
    dht.begin();
  }

  void loop() {
    // put your main code here, to run repeatedly:
    delay(3000);

    float h = dht.readHumidity();
    float t = dht.readTemperature();

    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" \t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println("");
  }


Result

After installing the libraries and writing the code i uploaded it on my microcontroller board. After uploading the code I started the serial monitor screen so i can see if the code works properly. Below you can see the board connected to my computer through a ftdi-cable.

The output looks like this