Skip to main content

Creating a Sunflower Solar Panel using Arduino




Have you ever wanted to create your own sunflower solar panel that follows the movement of the sun? With a light sensor, a servo motor, and an Arduino board, it's easier than you might think! In this guide, we'll walk you through each line of code and explain how it all works in simple terms .

circuit diagram of servo motor ,ldr,arduino and serial communication monitor

circuit diagram of servo motor at light intensity greater than 100 lumens


circuit diagram of servo motor ,ldr,arduino and serial communication monitor

circuit diagram of servo motor at light intensity less than 100 lumens

An images of solar panels arranged like a sunflower
A sunflower solar panel image.

DOWNLOAD PROTEUS FILE AND CODE

```

#include <Servo.h>

```

First, we include the Servo library which allows us to control servo motors with our Arduino board.

The Servo library helps an Arduino board control servo motor. Servo motors have gears and a shaft that can be moved to different positions. The Servo library can control many servos at once and has several methods for controlling them. These methods let you attach a servo motor to an Arduino board, move it to a specific position or speed, read its current position, check if it’s attached, and detach it.


```

int lightpin = A5;

int lightval;

int servpin=9;

int servpos = 180;

int servpos2 = 0;

Servo myservo;

int i;

int delaytime = 50;

```


We then define several variables. `lightpin` is set to `A5`, which means we will be using analog pin 5 to read the value of our light sensor. `lightval` will store the value read from the light sensor. `servpin` is set to `9`, which means we will be using digital pin 9 to control our servo motor. `servpos` and `servpos2` are set to `180` and `0` respectively, which represent the two positions our servo motor will move between. We also create a `Servo` object called `myservo`, which we will use to control our servo motor. Variable `i` will be used later in a for loop. `delaytime` is set to `50`, which represents the amount of time (in milliseconds) we will wait between each step of our servo motor.


```

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  myservo.attach(servpin);

  pinMode(lightpin,INPUT);

}

```


In the `setup()` function, we initialize serial communication at a baud rate of 9600. Baud rate refers to the speed at which data is transmitted over a communication channel. In simpler terms, it's like the speed limit on a road - it determines how fast information can travel between two devices. In this case, data is transmitted at a rate of 9600 bits per second.


We then attach our servo motor to `servpin`, and set `lightpin` as an input.


```

void loop() {

  myservo.write(servpos2);

  // put your main code here, to run repeatedly:

  lightval = analogRead(lightpin);

  Serial.println(lightval);

  while ( true) {

    if(lightval<=201){

      myservo.write(servpos);

      lightval = analogRead(lightpin);

      Serial.println(lightval);

      delay(delaytime);}

    else if (lightval>201){

      for(i=0;i<180;i=i+30){

        myservo.write(i);

        delay(delaytime);

        lightval = analogRead(lightpin);

        delay(delaytime);

        Serial.println(lightval);

      }

    }

  }

}

```


In the `loop()` function, we first move our servo motor to position `servpos2`. We then read the value of our light sensor using the `analogRead()` function and store it in `lightval`. This value is also printed to the serial monitor using the `Serial.println()` function.


Next, we enter an infinite loop using a `while(true)` statement. Inside this loop, we check if the value of `lightval` is less than or equal to 201.

If it is, we move our servo motor to position `servpos`, read the value of our light sensor again using the `analogRead()` function and store it in `lightval`, print it to the serial monitor using the `Serial.println()` function, and wait for a short period of time using the `delay()` function with argument `delaytime`.

NOTE:
The value of 201 was obtained through experimentation by connecting an LDR (light-dependent resistor) to an Arduino board and reading its value in both darkness and sunlight using the serial monitor (the circuit diagram is the same as the one used for the project, its down below). In a Proteus simulation, the value for 0.1 lumens on the analog scale is 1023, while 1000 lumens is 34. Lumens is the unit of measurement for light intensity. It’s important to note that these values were obtained through simulation and may differ in real-life scenarios where a machine would be needed to accurately measure light intensity.
According to our research, a solar panel starts charging at 100 lumens. Using the values obtained from testing the LDR in Proteus, we found that 100 lumens corresponds to a value of 201 on the analog scale.

If the value of `lightval` is greater than 201, we enter a for loop that increments variable `i` from 0 to 180 in steps of 30. Inside this loop, we move our servo motor to position `i` using the `write()` function with argument `i`, wait for a short period of time using the `delay()` function with argument `

Arduibo boards at 6200 naira ,3 day delivery: Buy your arduino board NIGERIA

Cheap arduino boards :Buy your arduino board WORLDWIDE.

circuit diagram of servo motor ,ldr,arduino and serial communication monitor

circuit diagram of sunflower solar panel



Comments

Popular posts from this blog

WHAT IS WEBSCRAPING IN PYTHON

  Web scraping is a technique that allows you to extract data from websites and store it in a format of your choice. It can be useful for various purposes, such as market research, price comparison, content analysis, and more. In this blog post, i will show you everything a beginner needs to know about web scraping, from the basics to some advanced tips and tricks.   What is web scraping?   Web scraping is the process of programmatically retrieving information from web pages. It involves sending requests to web servers, parsing the html code of the web pages, and extracting the data you want. Web scraping can be done manually, by copying and pasting data from a website, or automatically, by using a software tool or a programming language.   Why web scrape?   Web scraping can help you access data that is not available through an api or a downloadable file. For example, you may want to scrape product reviews from an e-commerce website, or news ...

Thevenin’s Theorem: A Beginner’s Guide

                                        table of content  Introduction History of Thevenin’s theorem Basic circuit analysis concepts Voltage, current, and resistance Ohm’s law Thevenin’s theorem: principles and applications Statement of the theorem Finding the Thevenin equivalent circuit What is Thevenin’s theorem? When should you use Thevenin’s theorem? How do you apply Thevenin’s theorem to a circuit Conclusion . Introduction Electrical engineers can effectively convert complicated circuits into smaller equivalent circuits by using Thevenin's theorem. The French telegraph engineer Léon Charles Thévenin is honored by having his theorem called in his honor. He proposed it in 1883. History of Thevenin’s theorem Hermann von Helmholtz, a German scientist, independently derived Thevenin's theorem in 1853; Léon Charles Thévenin did ...

AI Learning: How Machines Learn Like Humans

  Today I’m going to write about how the ways AI learns are similar to how I learn. Sounds interesting, right? let me clarify what I mean by AI. AI stands for artificial intelligence, which is a broad term that covers any system that can perform tasks that normally require human intelligence, such as understanding language, recognizing images, playing games, making decisions, etc. AI can be divided into four types: Strong AI: this is the ultimate form of artificial intelligence, it can reason on its own and act human like, it has not yet been made. Weak AI: it cannot truly reason and solve problems, but can act as if it were intelligent. Weak AI holds that suitably programmed machines can simulate human cognition. Applied AI: aims to produce commercially viable “smart” systems such as, for example, a security system that is able to recognise the faces of people who are permitted to enter a particular building. Applied AI has already enjoyed considerable success. Cognitive AI: compu...