IRRemote on ESP32 m...
 
Notifications
Clear all

IRRemote on ESP32 messing with temp sensor

1 Posts
1 Users
0 Likes
1,167 Views
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
Topic starter  

My project right now is using IRRemote esp8266 library on an ESP32 and a DHT22 temperature sensor. I was originally driving an IR LED directly from the pin and it was working fine but had limited range. I switched to Gikfun Digital 38khz Ir Receiver EK8477 thinking because it took 5 volts in that it do better. It was only marginal. So, I ordered a set of NPN transistors today but realized I have a 2N2222 in my arduino starter kit that I don't use. So I connected it with emitter to ground, base to gpio pin, collector to IR LED then to 3.3v. (I did originally have resistors between gpio/base and one between IR LED/3.3v but pulled them when it didn't work. The IRRemote used it direct for connecting to a node MCU. Turns out I had the IR LED in backwards, oops.)

 

It does work now and very well. But after it sends an IR signal, the temperature returns a higher value for 1 read and then drops back down. I noticed this when it turns off, my code will then immediately turn it back on and then off as soon as it settles. It does it when I send the on command too but it doesn't affect anything.

 

void loop() {

Serial.println("");
readDHT(); //read DHT Values
if (ison == true){
Serial.print("is on");
Serial.print(" Set at: ");
Serial.println(sett);
// If cold, turn off
if (temps <= sett - offsetD){ // If temp read is <= to set temp minus offset (1)
Serial.println("Turning off");
ac.off();
ac.send();
ison = false;
delay(10000);
}}

if (ison == false){
Serial.print("is off");
Serial.print(" Set at: ");
Serial.println(sett);
//If warm, turn on
if (temps >= sett + offset){
Serial.println("Turning on");
ac.on();
ac.send();
ison = true;
}}

delay(10000);

 

I added a delay after turning off and it didn't help. Here is the Temperature read section.

 

void readDHT() {
delay(2000);

float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
temps = (t);
}

 

Any ideas why this would happen? I might power the IR LED from 5v in case the power draw is causing the temperature sensor to not be happy. But I am not experienced enough to do the calculations for the resisters on my own and I have only found examples of 3.3v.

 


   
Quote