#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 3, 8, 12, 13);
LiquidCrystal_I2C lcd_1(0x27, 16, 2);
LiquidCrystal_I2C lcd_2(0x28, 16, 2);
LiquidCrystal_I2C lcd_3(0x29, 16, 2);
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char haxaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {11, 10, 9};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad customKeypad = Keypad( makeKeymap(haxaKeys), rowPins, colPins, ROWS, COLS);
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
lcd_1.init();
lcd_2.init();
lcd_3.init();
lcd_1.backlight();
lcd_2.backlight();
lcd_3.backlight();
lcd_1.print("Temperature");
lcd_2.print("Humidity");
lcd_3.print("Step Engine");
dht.begin();
}
void loop() {
int sensor = analogRead(A0);
int motorSpeed = map(sensor, 0, 1023, 5, 200);
myStepper.setSpeed(motorSpeed);
myStepper.step(stepsPerRevolution/100);
char customKey = customKeypad.getKey();
if (customKey) {
switch(customKey) {
case 'A':
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Temperature:");
lcd_1.setCursor(0, 1);
lcd_1.print(String(getTemperature()) + " C");
break;
case 'B':
lcd_2.clear();
lcd_2.setCursor(0, 0);
lcd_2.print("Humidity:");
lcd_2.setCursor(0, 1);
lcd_2.print(String(getHumidity()) + " %");
break;
case 'C':
lcd_3.clear();
lcd_3.setCursor(0, 0);
lcd_3.print("Step Engine:");
lcd_3.setCursor(0, 1);
lcd_3.print(String(motorSpeed) + " rpm");
break;
}
}
}
float getTemperature() {
return dht.readTemperature();
}
float getHumidity() {
return dht.readHumidity();
}