The heart of this electronic sunflower is a Circuit Playground Express board. It has a built in light sensor. When the flower is in darkness, it uses a servo motor to pivot until it finds a position with a high enough brightness value.
I thought this would be a fun activity to do with a class, library group, or at home. First, you construct a sunflower out of popsicle sticks and construction paper. During the steps you are waiting for the glue to dry, you can work on the code. The video below explains how to construct the sunflower and the thought process behind creating the code (not just a line by line explanation). Let me know if you have any questions. Enjoy!
Supplies- Circuit Playground Express (CPE)
- Servo motor
- Battery
- Alligator clips
- Tape
- Pot for plant
- Scissors
- Hot glue
- Elmers glue
- Black and yellow construction paper
- Popsicle sticks
- Green paint
- Paintbrush
1. Paint the popsicle sticks green. The number of sticks you use depends on how high you want your sunflower to go. I used two. The more you use, the more unstable your flower will become when moving.
2. Fold the yellow construction paper to the size of the petal you want.
3. Draw the petal.
4. Cut out petal while folded so you have several at once.
5. Repeat steps 2 through 4 with more sheets of paper until you have the number of petals you want.
6. Trace out the CPE board on a black sheet of construction paper.
7. Cut out the circle.
8. Using Elmers or hot glue, attach the first layer of yellow petals to the black circle. I started out near the edge.
9. Add more layers of petals further out from the center of the circle.
10. While the sunflower is drying, you can glue the popsicle sticks together. I used hot glue.
11. Glue arm of servo to the bottom popsicle stick.
12. You can code your sunflower while glue is drying. You can skip down to the code section for details. This link has the code that you can download -- https://makecode.com/_ekoWdr3wk5ry
13. If you are using the servo that comes in the CPE kit, the brown wire is ground. The red wire is power and should be hooked to the 3.3 V output on the CPE. The yellow wire is the signal wire and should be hooked to the A1 pin.
14. Test out servo. After testing, you can unhook wires to finish assembly and reconnect at the end.
15. Use hot glue to attach the servo to the inside of the pot. The motor should be attached lengthwise with wires pointing up. The arm should be allowed to pivot about 90 degrees to the left and to the right.
16. Hot glue the sunflower to the popsicle stick.
17. Hot glue the battery pack (or tape if LiPo) to the back of the popsicle stick.
18. Hot glue the CPE to the sunflower.
19. Attach the servo arm, which is glued to the popsicle stick, to the servo. Make sure the motor is at the 90 mark. This means once attached, the popsicle stick can turn evenly left and right.
20. Reconnect wires.
21. Plug in battery.
CodeLink to code:
https://makecode.com/_ekoWdr3wk5ry
The first decision the code makes is what direction the sunflower should be tilting. In the pot, the flower can't turn the full 180 degrees. I limited it from 40 degrees to 120 degrees. You should adjust those values for the container that your sunflower is in.
If the sunflower has tilted all the way to 40 degrees, the direction variable will switch from 1 to 0. If the sunflower has tilted all the way to 120 degrees, the direction variable will switch from 0 to 1.
I set the darkness threshold to 40. You can adjust this level. The higher the number, the brighter the light threshold is.
If the light level is below 40 and the direction is set to 0, then it will do the three steps inside the third if statement. The left side neopixels will turn blue and the right side will be purple. The degrees variable will increase by 2. Then the servo will rotate 2 degrees.
If the light level is below 40 and the direction is set to 1, then it will do the three steps inside the else if statement. The left side neopixels will turn purple and the right side will be blue. The degrees variable will decrease by 2. Then the servo will rotate -2 degrees.
If the light level is above 40, then the neopixels will turn yellow and the servo will not move.
Comments