#include "DHT.h"
#include <LiquidCrystal.h>
#include <Servo.h>
#include <Stepper.h>
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
Servo myservo; // create servo object to control a servo
Servo myservo1; // create servo object to control a servo
int pos = 0; // variable to store the servo position
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 0, 1, 4, 6);
void setup() {
Serial.begin(115200);
Serial.println(F("Auduino Uno Demo for Group L01-B04"));
dht.begin();
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("Group L01-B04");
myservo.attach(3); // attaches the servo on pin 3 to the servo object
myservo1.attach(5); // attaches the servo on pin 3 to the servo object
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
//Serial.begin(9600);
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
lcd.clear();
lcd.setCursor(0, 0); //(column 0-15, line 0-1)
lcd.print("Temperature:");
lcd.print(temperature);
lcd.setCursor(0, 1); //(column 0-15, line 0-1)
lcd.print("Humidity:");
lcd.print(humidity);
if (temperature>=40) { // >= more , == equal, <= less
Serial.println(F("Alert! Hot"));
tone(13, 262, 250); // Plays 262Hz tone for 0.250 seconds
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (temperature<=10) { // >= more , == equal, <= less
Serial.println(F("Alert! Cold"));
tone(13, 1262, 250); // Plays 262Hz tone for 0.250 seconds
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (temperature>=50) { // >= more , == equal, <= less
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
// Wait a few seconds between measurements.
delay(2000);
}