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!

2.9 Lucky Cat¶

In this project, we use pir and servo to make a lucky cat. The PIR Module is used to detect the visitors and servo is used to imitate the beckoning motion of the lucky cat.

Required Components

In this project, we need the following components.

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

Name

ITEMS IN THIS KIT

LINK

Kepler Kit

450+

Kepler Ultimate Kit

You can also buy them separately from the links below.

SN

COMPONENT

QUANTITY

LINK

1

Raspberry Pi Pico W

1

BUY

2

Micro USB Cable

1

3

Breadboard

1

BUY

4

Jumper Wires

Several

BUY

5

Servo

1

BUY

6

PIR Motion Sensor Module

1

BUY

Wiring

lucky_cat0

  • The orange wire (signal) of the servo is connected to GP15, the red wire (power) is connected to VBUS, and the brown wire (ground) is connected to GND.

  • The middle pin of the PIR module is connected to the GP3.

Code

Note

  • You can refer to the image below to write code by dragging and dropping.

  • Import 2.9_lucky_cat.png from the path of kepler-kit-main\piper. For detailed tutorials, please refer to Import the Code.

lucky_cat

  • After connecting Pico W, click the Start button and the code starts to run.

  • When the PIR module detects a customer arrival, the servo oscillates back and forth five times and then stops.

How it Works?

lucky_cat1

Set the rotation speed of pin15 (servo) to 15%.

lucky_cat2

If GP14 is low, set the variable [prestate] to 0. When the variable [prestate] is 0 and GP14 is high (human detected), set the variable [prestate] to 1.

The purpose of this is to make the main code work only when the GP14 changes from low to high, and to respond only once if the PIR module keeps detecting people.

lucky_cat3

Make the servo cycle 5 times from 0 to 180 degrees rotation.

  • [repeat () times do]: Loop through the code inside the do block a finite number of times.