Hi
i am building an egg incubator
i am encountering a problem when:
When the servo motor is on i do not get readings from my dht22 temp & hum sensor.
Once the servo stops i get readings normaly.
I browsed in here for a bit and found out that i need a separate power supply for the servo, most people suggest a 4x AA battery holder while others say that this is more than enough and it will burn the servo. So my question is is it safe to use the 4x AA battery holder?
Below is my code (i have all the parts finished but i add little by little t my main code and test)
//Libraries
#include <Wire.h>
//This library allows you to communicate with I2C/TWI devices.
#include <LiquidCrystal_I2C.h>
//This library allows you to communicate with your LiquidCrystalDevice
#include <dht.h>
//This library allows you to communicate with your DHT22 sensor
#include <Servo.h>
//This library allows you to communicate with your servo motor
//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value
int degrees;//Stores the value of degrees
//Constants
#define DHTPIN 2 //The pin 2 is used for DHT22
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define DHTTYPE DHT22 //The type of DHT sensor we are using
dht DHT; //Initialize the DHT sensor
Servo SERVO;
#define RELAYPIN 10 //The pin 10 is used for the Relay
#define SERVOMOTOR 11 //The pin 11 is used for the servo motor
void setup() {
Serial.begin(9600); //Allows us to vie our temp and hum values from the serial Monitor
lcd.begin(16, 2); // This function initiates our lcd 16 is the number of columns and 2 is the number of rows.
lcd.init(); //This function initializes the interface to the LCD
lcd.clear(); // This function clears the LCD screen and positions the cursor in the upper-left corner
lcd.backlight(); //This function turns on the LCD backlight
pinMode(RELAYPIN, OUTPUT); //Declaring the relay pin as an output
pinMode(SERVOMOTOR, OUTPUT); //Declaring the servomotor pin as an output
SERVO.attach(11);
}
void loop() {
byte CelsiusSymbol[] = {
0b11100,
0b10100,
0b11100,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
int chk = DHT.read22(DHTPIN);
//Read data and store it to variables hum and temp
hum = DHT.humidity;
temp = DHT.temperature;
//Print temp and humidity values to LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print('c');
lcd.createChar(0, CelsiusSymbol ); // create a new custom character
lcd.setCursor(11, 0); // move cursor to (11, 0)
lcd.write((byte)0); // print the custom char at (11, 0)
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(hum);
lcd.print("%");
delay(2000); //Delay 2 sec between temperature/humidity check.
if (millis()/1000 < 60) {
for (degrees = 90; degrees <= 135; degrees += 9) {
SERVO.write(degrees);
delay(2000);
}
delay(8000);
for (degrees = 135; degrees >= 90; degrees -= 9) {
SERVO.write(degrees);
delay(2000);
}
for (degrees = 90; degrees >= 45; degrees -= 9) {
SERVO.write(degrees);
delay(2000);
}
delay(8000);
for (degrees = 45; degrees <= 90; degrees += 9) {
SERVO.write(degrees);
delay(2000);
}
} else {
SERVO.write(90);
}
//Real times for egg incubator above times are test times
/*if (millis()/1000 < 1555200) {
for (degrees = 90; degrees <= 135; degrees += 9) {
SERVO.write(degrees);
delay(2000);
}
delay(180000);
for (degrees = 135; degrees >= 90; degrees -= 9) {
SERVO.write(degrees);
delay(2000);
}
for (degrees = 90; degrees >= 45; degrees -= 9) {
SERVO.write(degrees);
delay(2000);
}
delay(180000);
for (degrees = 45; degrees <= 90; degrees += 9) {
SERVO.write(degrees);
delay(2000);
}
} else {
SERVO.write(90);
}*/
}