Use the phone sensors to create a pinwheel that spin depends on the loudness level. For testing the program, just blow near the phone’s microphone.

What bricks and objects do you need?

Create a new program and add the following object from the media library:


Now add these scripts to the pinwheel object:

1. Step

First place the pinwheel on a y-position that you like.


2. Step

Then you have to check continuously if the loudness level is higher than a certain limit. You can set the limit to 60 or another value you like. To do this you need the forever-brick and the if then else-brick. If the loudness value is higher than 60, save the value into a variable. Multiply the loudness value with 10 to get a higher number respectively a more realistic spin for the pinwheel. To rotate the pinwheel add a rotate right-brick and insert the “spin speed” variable into the text field. You find the variables in the formula editor under the category data.


3. Step

The pinwheel should not stop immediately after the loudness level is under 60. Copy the rotate right and set variable-brick and paste them under the else-brick. Change the formula in the set variable-brick to “spin wheel * 0,99” to reduce the speed of the rotation smoothly.


4. Step

Every time the camera is detecting a face, your object is shown on the screen. Now you need to add movement to the object so it stays on a certain part of your face. Pick the place at X: Y: – brick and insert into the x-position field the sensor value “face_x_position” which you find under “devices” in the formula editor. Into the y-value field insert “face_y_position + 500” since the object is a hat.