I connected an Arduino uno clone with a DHT11, Liquid Crystal 12c, and a servo tower pro-SG92R to make an incubator that tracks the temperature and humidity and rolls
the eggs. I tried the code out, and everything went well except for the servo. Can you guys tell me what could be the problem? Can't attach hardware photo because I'm a new user
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
#define VCC2 12 // define pin 5 or any other digital pin here as VCC2
#define GND2 13 // define pin 2 or any other digital pin as Ground 2
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD
Servo eggRotator; // Servo motor object
int servoPin = 9; // Servo control pin
unsigned long rotationInterval = 24 * 60 * 60 * 1000; // Rotation interval: 24 hours
void setup() {
// Robojax.com getting extra 5V pin from Arduino 20181202
pinMode(VCC2, OUTPUT);//define a digital pin as output
digitalWrite(VCC2, HIGH);// set the above pin as HIGH so it acts as 5V
pinMode(GND2, OUTPUT);//define a digital pin as output
digitalWrite(GND2, LOW);// set the above pin as LOW so it acts as Ground
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight();
eggRotator.attach(servoPin); // Attaching servo motor to pin
}
void loop() {
readTemperatureAndHumidity();
rotateEgg();
delay(rotationInterval);
}
void readTemperatureAndHumidity() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print("%");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print("°C. Humidity: ");
Serial.print(humidity);
Serial.println("%");
}
void rotateEgg() {
// Rotate the egg 90 degrees clockwise
eggRotator.write(180);
delay(1.44e+7);
// Return to initial position
eggRotator.write(0);
delay(1.44e+7);
eggRotator.write(180);
delay(1.44e+7);
eggRotator.write(0);
delay(4.32e+7);
}
This is an incubator program I made as a project that can track the temperature and humidity(Can also roll eggs). I don't think there's a problem with the software, so I'm guessing as a hardware problem. The servo motor just doesn't move and only makes a small buzzing noise. Everything else works just fine
You really need a better connection than just sticking a wire into the connector.
There does need to be a common ground between the servo power supply and the UNO.