Illuminate Your Space: Crafting an Arduino Sunflower

Introduction

Arduino isn’t solely for complex projects; it can also serve as a platform for simpler ones, imparting valuable skills to beginners. Our aim is to demonstrate the fun side of electronic components, educating others about circuits and components. In this tutorial, let’s embark on creating an Arduino Sunflower DIY project. This type of project not only sparks inspiration but also fosters a deeper understanding of electronics, which is essential for learning.

The inclusion of a servo motor is pivotal in our choice of this do-it-yourself (DIY) endeavor. Our objective is to simplify the learning process around the servo motor for you. When approaching Arduino with enthusiasm and purpose, the process of connecting any component becomes much more manageable. Therefore, let’s first grasp the concept of an Arduino sunflower before delving into constructing the circuit.

What is Arduino Sunflower?

The Arduino sunflower essentially mimics the behavior of a sunflower by tracking and following light sources. It involves the utilization of a servo motor, two photoresistors, and a sunflower model to enable movement based on light cues. Notably, this project creates a do-it-yourself (DIY) flower using cardboard sheets, not an actual flower.

Hardware Components

You will require the following hardware to make Arduino sunflower.

S.no Component Value Qty
1. Arduino UNO 1
2. Photoresistor LDR 2
3. Servo Motor SG90 1
4. Breadboard 1
5. Jumper Wires 1

Steps for Making Arduino Sunflower

To craft the Arduino Sunflower, you’ll require easily accessible basic electronic components: an Arduino, servo motor, and photoresistor. Follow a series of steps to construct the circuit for this project.

Schematic

Make connections according to the circuit diagram given below.

Wiring / Connections

Arduino Servo Motor Photoresistor Sensor 1 Photoresistor Sensor 2
5V VCC One End
GND GND One End
D9 Signal
A0 Other End Other pin

Installing Arduino IDE

Initially, you’ll need to download the Arduino IDE Software from the official Arduino website. Here’s a straightforward, step-by-step guide on installing the Arduino IDE.

Code

Now copy the following code and upload it to Arduino IDE Software.

#include <Servo.h>

int sensorPin = A0;
int servoPin  = 9;

int sensorValue = 0;
int servoGrad = 90;
int tolerance = 40;

Servo myservo;

void setup() {
  pinMode( sensorPin, INPUT);
  myservo.attach( servoPin );
  myservo.write( servoGrad );
}

void loop() {
  sensorValue = analogRead(sensorPin);
  if ( sensorValue < (512-tolerance) )
  {
    if (servoGrad < 180) servoGrad++;
  }

  if ( sensorValue > (512+tolerance) )
  {
    if (servoGrad > 0) servoGrad--;
  }

  myservo.write( servoGrad ); 

  delay(100);
}

Let’s Test It

Now, it’s the moment to test the device post the code upload. Let’s power on the Arduino and put the Arduino sunflower to the test. You’ll notice its enthusiasm in seeking out the light. The motor initiates rotation toward the light source. For a closer inspection, move it to a darkened space and then activate your phone’s flashlight to observe the outcomes.

Working Explanation

The entire functionality of the circuit hinges on the code. Let’s delve into understanding the code:

Initially, we define the Arduino pins essential for the circuit’s construction.
Within the void setup, the sensor pin (a photoresistor) is primarily set as an input. By calling the Servo.attach() function, the default position of the servomotor is set at 90 degrees. Subsequently, the Servo.write() function follows this call to initialize the servomotors at a specific position.
In the void loop, the analogRead function is utilized to capture values from the photoresistor sensor. A conditional statement is introduced: if the sensor value falls below a defined threshold and the motor angle is less than 180 degrees, the motor will rotate. Conversely, if the sensor value surpasses a predefined threshold, the servo motor is evaluated; if the motor angle is less than 180 degrees, the motor will remain stationary. The code includes delays to accommodate the reading of subsequent values.


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top