PROJECT Nº 4: Sunflower

Create your own sunflower that turns in search of light using the components of the Maker Control Kit and Maker Kit 1.

The key to this project is the analog light sensor, which alters its electrical resistance depending on the light it detects. Thanks to it, the sunflower will detect the absence of light and turn to find it. See it turn like a real sunflower!

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 60 min.

MATERIALS:

  • 1 Analog light sensor
  • 1 Servomotor
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer
  • Sunflower stencil
  • Cardboard or other material to make the structure
  • Adhesive
  • Dark plastic cup

What is a light sensor?

An analog light sensor is a resistor that varies its electrical resistance depending on the amount of light that hits it. It is also called a photoresistor or photoresistance.

CONNECTIONS:

  1. Connect the light sensor to the analog port A0 on the 4in1 Build&Code board.
  2. Connect the servomotor to digital port 9 on the 4in1 Build&Code board.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Each cable should be connected to its color:

BUILDING THE STRUCTURE:

The materials that you will use are mainly cardboard and a plastic cup. If you have other materials that can be used to do the project, you can incorporate them, as well. In order to build the structure, download the sunflower stencil and the quick assembly guide. Follow the steps given.

Place the light sensor inside a dark plastic cup and glue it onto the base. Make a hole in the side of the cup on the lower part to be able to pass the light sensor cable through to the outside.

Then cut out the picture of the sunflower, glue it on cardboard, and cut it out. Use another piece of cardboard to draw and cut out different parts that will make the base of the sunflower. Assemble the sunflower, including the parts of the base.

Next, draw and cut out the base to which the servomotor and the joining base between the servomotor and the sunflower will be attached. Assemble the base of the servomotor and join it to the sunflower.

PROGRAMMING CODE:

The program is based on the readings from the light sensor. We have set a range of values from 0 to 800. Based on this range of the light sensor, the servomotor will turn at an angle from 0º to 180º at most, making the 0 value of the light sensor coincide with the servomotor at 0º. Similarly, values greater than 800 from the light sensor will coincide with the servomotor at 180º.

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

 Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in, copy the following program:
    #include <Servo.h> // SERVOMOTOR LIBRARY
    Servo Motor; // SERVOMOTOR VARIABLE
    int PortLight = A0; // Port connected to the light sensor
    int Degree, LightB; // Degree variable motor degrees // LightB variable light sensor value
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      Motor.attach (9); //Port connected to the servomotor
      Degree = 15; 
      Motor.write (Degree); // Servomotor to 15º
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      LightB = analogRead(PortLight); // Light sensor reading values
      Serial.println(LightB); // Show light sensor values on screen
      if(LightB < 100) // If Light is less than 100
      {
       Degree = 15; // Degrees = 15
      }
      if((LightB > 100)&(LightB < 200)) // If Light is less than 200 and greater than 100
      {
        Degree = 36; // Degrees = 36
      }
      if((LightB > 200)&(LightB < 300)) // If Light is less than 300 and greater than 200
      {
        Degree = 57; // Degrees = 57
      }
      if((LightB > 300)&(LightB < 400)) // If Light is less than 400 and greater than 300
      {
        Degree = 78; // Degrees = 78
      }
      if((LightB > 400)&(LightB < 500)) // If Light is less than 500 and greater than 400
      {
        Degree = 99; // Degrees = 99
      }
      if((LightB > 500)&(LightB < 600)) // If Light is less than 600 and greater than 500
      {
        Degree = 120; // Degrees = 120
      }
      if((LightB > 600)&(LightB < 700)) // If Light is less than 700 and greater than 600
      {
        Degree = 140; // Degrees = 140
      }
      if((LightB > 700)&(LightB < 800)) // If Light is less than 800 and greater than 700
      {
        Degree = 160; // Degrees = 160
      }
      if(LightB > 800) // If Light is greater than 800
      {
        Degree = 180; // Degrees = 180
      }
      Motor.write (Degree); // Set the servomotor at the corresponding angle.
    }
    
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

As a result of the project, the system will measure the amount of light that hits the light sensor, and it will move the servomotor a certain number of degrees depending on these values, imitating the movement of a real sunflower.

1 0

0