Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

1.17 Rotating fan¶

In this project, we will make a spinning star sprite and fan.

../_images/1.17_header.png

Required Components¶

In this project, we need the following components.

../_images/1.17_list.png

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Raphael Kit

337

Raphael Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

GPIO Extension Board

BUY

Breadboard

BUY

Jumper Wires

BUY

Power Supply Module

-

L293D

-

DC Motor

BUY

Build the Circuit¶

../_images/1.17_image117.png

Load the Code and See What Happens¶

Load the code file (1.17_rotating_fan.sb3) to Scratch 3.

After clicking the green flag on the stage, click on the star sprite,then it and the motor will rotate clockwise; you can change the direction of rotation by clicking on the two arrow sprites. When you click on the star sprite again, it and the motor will stop rotating.

Tips on Sprite¶

Delete the default sprite, then select the Star sprite and the Arrow1 sprite, and copy Arrow1 once.

../_images/1.17_motor1.png

In the Costumes option, change the Arrow2 sprite to a different direction costume.

../_images/1.17_motor2.png

Adjust the size and position of the sprite appropriately.

../_images/1.17_motor3.png

Tips on Codes¶

Flow Chart

../_images/1.17_scratch.png

In this code, you will see 2 pink blocks, turn left and turn right, which are our custom blocks (functions).

../_images/1.17_new_block.png

How to Make a Block?

Let’s learn how to make a block (function). The block (function) can be used to simplify your program, especially if you perform the same operation multiple times. Putting these operations into a newly declared block can be very convenient for you.

First find My Blocks in the block palette, then select Make a Block.

../_images/1.17_motor4.png

Enter the name of the new block.

../_images/1.17_motor5.png

After writing the function of the new block in the coding area, save it and then you can find the block in the blocks palette.

../_images/1.17_motor6.png

turn left

This is the code inside the turn left block to make the motor rotate counterclockwise.

../_images/1.17_motor12.png

turn right

This is the code inside the turn right block to make the motor rotate clockwise.

../_images/1.17_motor11.png