//https://forum.arduino.cc/t/static-unsigned-long-problems/1250532/1
#include <Servo.h>
#include <SimpleDHT.h>
#include "dht_nonblocking.h"
#define DHT_SENSOR_TYPE DHT_TYPE_22
static const int DHT_SENSOR_PIN = 3;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
Servo myservo;
/*
Initialize the serial port.
*/
//---------------------------------------------------------------------
void setup( ) {
Serial.begin( 9600);
myservo.attach(5);
myservo.write(90);// move servos to center position -> 90°
}
/*
Poll for a measurement, keeping the state machine alive. Returns
true if a measurement is available.
*/
//---------------------------------------------------------------------
static bool measure_environment( float *temperature, float *humidity ) {
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. change the 1000 */
if ( millis( ) - measurement_timestamp > 1000ul ) {
if ( dht_sensor.measure( temperature, humidity ) == true ) {
measurement_timestamp = millis( );
return ( true );
}
}
return ( false );
}
//---------------------------------------------------------------------
/*
Main program loop.
*/
void loop( )
{
float temperature;
float humidity;
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if ( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature, 1 );
Serial.print( " deg. C, H = " );
Serial.print( humidity, 1 );
Serial.println( "%" );
}
/*change the 25*/
if (temperature > 25 ) {
myservo.write(30);
}
else if (humidity > 80) {
myservo.write(30);
}
else {
myservo.write(90);
}
}