0% found this document useful (0 votes)
21 views12 pages

CSCI373 - Week - 05 - Temperature - Humidity

Uploaded by

husseinalayan18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views12 pages

CSCI373 - Week - 05 - Temperature - Humidity

Uploaded by

husseinalayan18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CSCI373

Robotics Design & Coding


Week 05
Serial Monitor, Analog/Digital
Temperature & Humidity
The Serial Monitor
Arduino IDE
The Serial Monitor (Arduino New Version)
void setup(){
Serial.begin(9600);
}

void loop(){
Serial.print("Hi ");
Serial.println("CSCI373 Students ..");
delay(1000);
}
The Serial Monitor (Arduino Old Version)
Analog vs. Digital Signals
Digital signals:
digitalWrite(pin, HIGH);
digitalWrite(pin, LOW);
Pins: All

Analog signals:
Can vary with an indefinite number of steps between high and low.
analogWrite(pin, 0);
analogWrite(pin, 50);
analogWrite(pin, 100);
analogWrite(pin, 150);
analogWrite(pin, 255);

Analog Pins (Input and output): 3, 5, 6, 9, 10, 11


Analog Pins (Input): A0, A1, A2, A3,A4, A5
Add new library:
Sketch → Include Library → Add .Zip Library
Access the new library files:
File → Examples

The libraries files


are stored into:

C → Users → MyUser
→ Documents →
Arduino → libraries
Thermometer and Humidity Sensor (DHT11)
DHT11 is a digital sensor for sensing temperature and humidity.
Thermometer and Humidity Sensor (DHT11)
REQUIRES the following Arduino libraries:
DHT Sensor Library:
https://github.com/adafruit/DHT-sensor-library
Adafruit Unified Sensor Lib:
https://github.com/adafruit/Adafruit_Sensor
#include "DHT.h"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("Temperature & Humidity test..");
dht.begin();
}
Thermometer and Humidity Sensor (DHT11)
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();

// Check if any reads failed and exit early.


if (isnan(h) || isnan(t)) {
Serial.println("Failed to read !");
return;
}
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" °C, Humidity: ");
Serial.print(h);
Serial.println(" %"); delay(2000);
}
Practice
❑The green LED should be
turned on.
❑The blue LED should fade if the
temperature is ≤ 16.
❑The red LED should blink if the
temperature is > 16.
❑The system should print the
temperature in the serial
monitor.

You might also like