So I have this issue where whenever I use a servo, my DHT11 sensor starts giving some fail to read messages.
If I remove the servo from the code, the sensor works 100%. But as soon as I attach the servo (without writing a position to it) it will cause these sensor read errors.
I've spent a lot of time experimenting, googling, and trying different stuff out to resolve it, but I just don't seem to get it.
The libraries i use are:
<SimpleDHT.h>
<Servo.h>
And i use a small 9g HEXTRONIC servo.
In my project I also use a 1602 LCD-display (with i2c module), 2 relays and some push buttons.
I use serial.prints in my code. I also use breakpoints in visual studio to follow whats happening.
Some stuff I've tried already:
-It's not because of voltage drops, I use capacitors and I've measured the voltage to float between 5.10 -> 5.15v while the servo is working. I've also tried to power the servo through another power supply.
-I've tried to change the sensor and servo pins on the arduino board.
-I use the DHT11-code from the default-example, with the only difference that I use millis() and not a delay() to control the time between measurements.
-I've tried detaching the servo between movements, but as I mentioned, just attaching it causes sensor failures. And even if I'm not sending any positions to the servo, it still makes small adjustment moves from time to time, so it seems to get signals anyway.
-I've tried to fiddle around with interrupts: for example disabling and enabling it while reading the sensor (caused the program to freeze) or while moving servo (seemed to not change anything). But I've never used interrupts before so I'm not really sure what i'm doing here. I just read somewhere that it might be some clash or whatever so i gave it a try.
-I've tried to alter the code in any way I could imagine would help or change anything.
The failures I get from the sensor are these:
Read DHT11 failed, err=4114
Read DHT11 failed, err=3090
Read DHT11 failed, err=-237
Read DHT11 failed, err=21
I've tried to look at the library to see what it means, but the code there, well it's a bit above my level.
My sketch is pretty big, about 2000 lines, but if anyone think it might help, i can post it.
I been trying so many technical or specific fixes at this point, that I feel a bit too zoomed in at the problem. And Google don't seem to give me much help either, which is suspicious, it's like I don't understand the problem or not googling the right thing. Servos has always been one of my biggest issues with arduinos, they always causes problems for me. But when i google about servo issues, it seems there are not a lot of people having the same issues. So it makes me think I've missed something.
I could imagine the problem being something way more elementary like, "oh, ofc you cant use a servo and the dht11-sensor, they both use 'whatever' which doesn't work"
Ok, anyway, this got a bit long, sorry. Any help would be much appreciated !
greetings from Sweden