#include <LiquidCrystal.h> // include the library for the LCD
#include <DHT.h> // include the library for the DHT11 temperature sensor
#include <Stepper.h> // include the library for the stepper motor
// set up the LCD's number of columns and rows:
const int numRows = 2;
const int numCols = 16;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// set up the DHT11 temperature sensor
#define DHTTYPE DHT11 // specify the type of DHT sensor
#define DHTPIN A0 // specify the pin the DHT sensor is connected to
DHT dht(DHTPIN, DHTTYPE); // create a DHT instance
// set up the stepper motor
const int stepsPerRevolution = 200; // specify the number of steps per revolution
Stepper stepper(stepsPerRevolution, 0, 1, 2, 3); // create a Stepper instance and specify the pins the motor is connected to
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(" Sicaklik Olcer");
delay(1000);
lcd.clear();
Serial.begin(9600);
delay(100);
// initialize the DHT11 sensor
dht.begin();
// set the speed of the stepper motor in steps per second
stepper.setSpeed(600);
}
void loop() {
// read the input from the LCD button shield
int buttonInput = readButtonInput();
// read the temperature and humidity from the DHT11 sensor
float temp = dht.readTemperature(); // read the temperature in Celsius
float humi = dht.readHumidity(); // read the humidity in percent
lcd.setCursor(9,2);
lcd.setCursor(0,0);
lcd.print("Sicaklik:");
lcd.setCursor(9,0);
lcd.print(temp);
lcd.setCursor(12,0);
lcd.print("'C");
lcd.setCursor(0,2);
lcd.print("Nem:");
lcd.setCursor(5,2);
lcd.print(humi);
lcd.setCursor(8,2);
lcd.print("%");
delay (100);
// compare the temperature from the sensor with the input from the button shield
if (temp > buttonInput) {
// run the stepper motor if the temperature is higher
stepper.step(stepsPerRevolution); // rotate the motor one revolution
} else {
// do something else if the temperature is not higher
}
}
// function to read the input from the LCD button shield
int readButtonInput() {
// read the input from the button shield
int buttonInput = analogRead(A1);
// map the input to a value between 0 and 100
buttonInput = map(buttonInput, 0, 1023, 0, 100);
// return the mapped value
return buttonInput;
}