Solution:
It started working after chaniging #define DHTPIN 1 to #define DHTPIN 2.
Original post:
Hi,
I’ve come upon a weird problem. I’m trying to switch the relay on if the temperature reaches 29C or higher. I have a sketch that works perfectly on Arduino UNO board, but doesn’t work on ATTiny85:
https://codebender.cc/sketch:263837
#include <DHT.h>
#define RPIN 0 //Relay Pin
#define DHTPIN 1 //DHT11 Pin
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
pinMode(RPIN, OUTPUT);
digitalWrite(RPIN, HIGH);
delay(1000);
digitalWrite(RPIN, LOW);
delay(1000);
dht.begin();
}
void loop()
{
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f))
{
return;
}
if ((int)t >= 29)
{
digitalWrite(RPIN, HIGH);
}
else
{
digitalWrite(RPIN, LOW);
}
}
When I run it from ATTiny85, the RPIN just stays in HIGH state indefinitely. When I flash simple ‘Blink’ code everything works normal (tested with a LED and a relay module) .The bootloader/fuses are burned, so that is not delay problem.
Please help