Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Solar Tracking System with DHT11 Sensor and OLED Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Solar Tracking System with DHT11 Sensor and OLED Display

Solar Tracker Circuit with DHT11 and OLED Display Documentation

Summary

This circuit is designed to control a solar tracking system using two SG90 servo motors. It utilizes photoresistors to detect solar light intensity, a DHT11 sensor to measure temperature and humidity, and an OLED display to show the solar panel voltage and environmental data. The system is controlled by an Arduino UNO microcontroller, which processes the sensor inputs and drives the servo motors to adjust the solar panel's position for optimal sunlight exposure.

Component List

DHT11 Sensor V2

OLED 1.3" Display

Arduino UNO

SG90 Servo Motor

Resistor (10k Ohms)

Photocell (LDR)

Solar Panel

Wiring Details

DHT11 Sensor V2

OLED 1.3" Display

SG90 Servo Motor

Resistor (10k Ohms)

Photocell (LDR)

Solar Panel

Documented Code

/*
 * Arduino Sketch for Solar Tracker with DHT11 and OLED Display
 *
 * This code controls a solar tracking system using two SG90 servo motors, 
 * detects solar light intensity using photoresistors, displays temperature 
 * and humidity using a DHT11 sensor, and shows voltage from a solar panel 
 * on an OLED display.
 */

#include <Servo.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

#define DHTPIN 2          // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11     // DHT 11 type
#define OLED_RESET -1     // OLED display reset pin (not used)
Adafruit_SSD1306 display(OLED_RESET);

Servo servo1;             // Servo motor for horizontal movement
Servo servo2;             // Servo motor for vertical movement
DHT dht(DHTPIN, DHTTYPE); // DHT sensor object

// LDR pins connected to analog inputs
const int ldrPin1 = A0;
const int ldrPin2 = A1;
const int ldrPin3 = A2;
const int ldrPin4 = A3;

// Servo pins connected to digital outputs
const int servoPin1 = 9;
const int servoPin2 = 10;

// Solar panel voltage pin connected to analog input
const int solarPin = A4;

void setup() {
  servo1.attach(servoPin1); // Attach servo1 to its control pin
  servo2.attach(servoPin2); // Attach servo2 to its control pin
  dht.begin();              // Initialize the DHT sensor
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize the OLED display
  display.display();        // Show initial display buffer
  delay(2000);              // Wait for 2 seconds
  display.clearDisplay();   // Clear the display buffer
}

void loop() {
  // Read values from the LDRs
  int ldr1 = analogRead(ldrPin1);
  int ldr2 = analogRead(ldrPin2);
  int ldr3 = analogRead(ldrPin3);
  int ldr4 = analogRead(ldrPin4);

  // Read the solar panel voltage
  int solarVoltage = analogRead(solarPin);

  // Read temperature and humidity from the DHT sensor
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  // Calculate the difference in light between pairs of LDRs
  int error1 = ldr1 - ldr2;
  int error2 = ldr3 - ldr4;

  // Map the error values to servo positions
  int servo1Pos = map(error1, -1023, 1023, 0, 180);
  int servo2Pos = map(error2, -1023, 1023, 0, 180);

  // Write the servo positions
  servo1.write(servo1Pos);
  servo2.write(servo2Pos);

  // Display the temperature, humidity, and solar voltage on the OLED
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("Temp: ");
  display.print(temperature);
  display.print(" C");
  display.setCursor(0,10);
  display.print("Humidity: ");
  display.print(humidity);
  display.print(" %");
  display.setCursor(0,20);
  display.print("Solar V: ");
  display.print(solarVoltage * (5.0 / 1023.0));
  display.print(" V");
  display.display();

  delay(2000); // Wait for 2 seconds before the next loop iteration
}

This code is responsible for reading sensor data, controlling the servo motors based on the light intensity detected by the LDRs, and displaying the temperature, humidity, and solar panel voltage on the OLED display. The setup() function initializes the components, and the loop() function contains the main logic that is executed repeatedly.