So I am using a servo motor and 2 DHT11s in my Uno, when I attach them separately it works well. But when I try to attach both, servo working correctly but DHT11 giving weird number(DHT11 was side by side, one gives 22oC and another gives 30oC sometimes -999).
I am powering both devices by using 5V and GND from arduino to a breadboard and then DHT11 and Servo power pin to the breadboard. All signal pin are direct from devices to arduino.
Am I power both devices wrong? or is there's a way to solve this?
Thanks
EDIT: this is the code
#include <Servo.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 7
#define DHT11_PIN2 6
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
int chk2 = DHT.read11(DHT11_PIN2);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
For the servo, I used GWServo S03N STD.