Shy Flower

Build a shy flower project on the micro:bit. The flower will wave vigorously when it's dark, but will slow down its waving when it's bright!


YOU WILL NEED

  • Micro:bit
  • Breakout board
  • Light sensor
  • Servo

STEP 1

Connect the light sensor to the micro:bit

Plug the micro:bit into a breakout board to break out the external pins. We will plug the light sensor into Pin P1 on the breakout board.




Materials

micro:bit
breakout board
light sensor



STEP 2

Program the light sensor

Try out this simple program to check that the light sensor is working. As you move your hands to cast a stronger or weaker shadow on the light sensor, the readings should change.



STEP 3

Attach the servo motor
Attach the servo motor to Pin P2 on the breakout board.




Materials

Servo motor



STEP 4

Programming the servo motor

Test that the servo motor works using the simple code here. This code will move the servo horn back and forth continually. Remember to set the pin on the code block to Pin P2.



STEP 5

Now we have ensured that our light sensor and our servo motor component works. The next step is to have the input of the light sensor control the frequency of the servo motor's movements.



STEP 6

Create two variables: light value to store the value from the light sensor, and period which will be a calculated value that determines the frequency of the servo motor.

A dark environment will set the period of the servo motor to about 200ms, while a bright environment will set the period to about 3000ms.



STEP 7

We now use the value of the period variable to control how long the servo motor waits before it does another rotation.

We replace the duration of the pause with the period variable.



STEP 8

Voila! We are done with the programming. Create a simple flower decoration using construction paper and pipe cleaners, attach it to the servo motor, and mount the whole project on the side of the table to give the servo motor clearance to rotate.

You will also have to adjust the angle of rotation so that the flower will be more or less vertical. In our experiment and based on the angle that we attach the servo horn, we found the angles between 90 and 150 good.

As we tried it out, we also adjusted the mapping from the light value to the period to try and make our flower more responsive. In this screenshot, you will see that the values of our mappings have changed.



STEP 9

Extensions
* Use a ultrasonic distance sensor instead of a light sensor
* Make the program more sophisticated and responsive. In the screenshot, we make it so that the flower stops waving when it's very bright.


Made this activity? Good Job! Now spread the word. Share a photo of your creation on social media with #letsgethacking #ShyFlower