// Stepper motor on Wokwi!
#include <Stepper.h>
#include "DHT.h"
#define DHTPIN 2 // Pin donde está conectado el sensor
//#define DHTTYPE DHT11 // Descomentar si se usa el DHT 11
#define DHTTYPE DHT22 // Sensor DHT22
DHT dht(DHTPIN, DHTTYPE);
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
Serial.println("Iniciando...");
dht.begin();
}
void loop() {
delay(2000);
int ph = analogRead(A0);
float h = dht.readHumidity(); //Leemos la Humedad
float t = dht.readTemperature(); //Leemos la temperatura en grados Celsius
float f = dht.readTemperature(true); //Leemos la temperatura en grados Fahrenheit
//--------Enviamos las lecturas por el puerto serial-------------
// step one revolution in one direction:
Serial.print("clockwise");
myStepper.step(stepsPerRevolution);
Serial.println(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.print("counterclockwise");
myStepper.step(-stepsPerRevolution);
Serial.println(-stepsPerRevolution);
delay(500);
Serial.print("Ph ");
Serial.print(ph);
Serial.print("Humedad ");
Serial.print(h);
Serial.print(" %t");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.println(" *F");
}