← Back to list

Input Devices

April 15, 2024

Input Devices

Challenge


Group Assignment:

This week the assignment was fruitful as it helped me to understand the difference between analog and digital signals, the assignment give the chance to use both with the MCU I have previously build and how my MCU interacts with both sensors (I think all MCU’s will do the same as this is fixed among all MCU’s).

I understand now that analog sensors have many values between the GND and the VCC values where each have a specific value to the physical quantity that stimulate the sensor.

On the other hand the digital sensor consist of {two values} Low and High and each sensor have its own algorithm or way to represent the values through a library previously built.

For more information about the assignment please refer to this LINK.


Individual Assignment:

DHT 22

For this assignment I will be measuring {Temperature and Humidity} using DHT22 or AM2302 [Digital Sensor] Please find the Datasheet through this LINK.

DHT22 is a Digital sensor that measure temperature and humidity, For measuring temperature the sensor has thermister and for the humidity it has a capacitive humidity sensor. this sensor has a good precision (+- 0.5) but with a slow sampling rate (0.5 hz = 2 second ).

Great documentation about the difference between analog and digital LINK

I Will be using the same board I have previously fabricated Which already have the DHT22 connected.

Below I will Just show the code and the output values as the sensor is already attached to the board.

HS

DHT Library

DHT sensor defined

Setup Loop Done

Variables ready

Check function

Serial print

Upload Done


#include <DHT.h>

#define PIN 8 // Where the DHT data pin is connected
#define TYPE DHT22 // DHT sensor Type.

DHT zaid(PIN,TYPE); // Constructor


void setup() {
  // put your setup code here, to run once:

Serial.begin(9600); // Serial link with bud rate defined.
zaid.begin(); // DHT sensor with zaid name started.

}

void loop() {
  // put your main code here, to run repeatedly:
delay(3000); // Take data every 3 seconds.

float T = zaid.readTemperature();// Read the temperature in celsius.
float TF = zaid.readTemperature(true);// Read Temperature in Fahrenheit 
float H = zaid.readHumidity(); // Read Humidity.

// This sensor is know for failure let us create a check if reads failed.

if(isnan(T)||isnan(TF)||isnan(H)){
  Serial.println("Faild to read");
  return;
}

Serial.print("Humidity: ");
Serial.print(H);
Serial.print("% Temperature: ");
Serial.print(T);
Serial.print("°C ");
Serial.print(TF);
Serial.println("°F");
}

Note : This sensor needs 250 ms to give a considered data so its better to give time between readings.