# Help raspberry pi/arduino with a pir sensor, needed for a newbie!

#### Chopzilla

Joined Jan 7, 2023
7
Hi everyone, i'm working on a project and i really have no idea what im doing past a couple of points.

The idea is to make butterfly wings flap using stepper motors, drivers and a rapberry pi/arduino with a pir sensor as the on/off. Where i'm struggling is i have no idea on the components i need to make this happen.

Is there anyone here willing to help me?

#### WBahn

Joined Mar 31, 2012
28,192
There are kits that do just this. They aren't too expensive, so you might get one of those and see how they did it and then adapt it to suit your particular interests.

#### Chopzilla

Joined Jan 7, 2023
7
There are kits that do just this. They aren't too expensive, so you might get one of those and see how they did it and then adapt it to suit your particular interests.
Would that just be something that uses pulse width modulation?

#### BobTPH

Joined Jun 5, 2013
6,319
A DC motor + a mechanical linkage tied to the rim of a wheel would be the easiest way. No microcontroller needed. Think of windshield wipers, that is how they work.

#### KeithWalker

Joined Jul 10, 2017
2,724
Your question jumped directly directly to a hardware solution without giving us any other information. If you would like us to help you to achieve your goal, please give us the basic requirements such as budget, size, weight, environment, orientation, angle and speed of wing motion, range of sensors, etc. Then we can discuss what is available and find you a workable solution.

#### Chopzilla

Joined Jan 7, 2023
7
A DC motor + a mechanical linkage tied to the rim if a wheel would be the easiest way. No microcontroller needed. Think of windshield wipers, that is how they work.
this was the original plan but the space it needs to fit in is very very small and the tiny stepper motors provided a smaller profile overall

#### Chopzilla

Joined Jan 7, 2023
7
Your question jumped directly directly to a hardware solution without giving us any other information. If you would like us to help you to achieve your goal, please give us the basic requirements such as budget, size, weight, environment, orientation, angle and speed of wing motion, range of sensors, etc. Then we can discuss what is available and find you a workable solution.
okay, budget isnt an issue right now as i dont see components costing thousands, the butterflies will be sitting on human realistic rib bones so most of the components can be hidden in them, best idea i can give you on size is as small as possible, environment will be indoors, i can make the motor operation work in either orientation (horizontal, vertical), angle will be through 90 degrees (i think) but im not sure how possible this will be.

I'm sorry if this is vague but its still an idea in its infancy and this has been the stumbling block.

Below is a rough starting code if that helps give you some idea? Please dont give to much thought to the code, i had an ai write it.

Code:
 # Import the necessary libraries import time from AccelStepper import AccelStepper # Set the pins for the stepper motor and PIR motion detector step_pin = 3 direction_pin = 4 pir_pin = 2 # Set the flapping frequency flapping_frequency = 2 # flaps per second # Calculate the delay between steps step_delay = 1.0 / (flapping_frequency * 200) # 200 steps per revolution # Set up the AccelStepper object stepper = AccelStepper(1, step_pin, direction_pin) stepper.setMaxSpeed(200) stepper.setAcceleration(50) while True:  # Wait for motion to be detected  while not digitalRead(pir_pin):    time.sleep(0.1)    # Flap the wings for 10 seconds  start_time = time.time()  while time.time() - start_time < 10:    # Take 200 steps to complete one revolution    for i in range(200):      stepper.setSpeed(200)      stepper.runSpeed()      time.sleep(step_delay)    # Pause for a moment    time.sleep(0.5) [CODE]

#### MrChips

Joined Oct 2, 2009
28,155
The idea is to make butterfly wings flap using stepper motors, drivers and a rapberry pi/arduino with a pir sensor as the on/off. Where i'm struggling is i have no idea on the components i need to make this happen.
I begin, is this thing actually supposed to fly?
If so, you need to consider total weight, power management, etc.
If you want to minimize weight then I would not choose raspberry pi nor arduino.
Also, stepper motors would be a off the list.

#### Chopzilla

Joined Jan 7, 2023
7
I begin, is this thing actually supposed to fly?
If so, you need to consider total weight, power management, etc.
If you want to minimize weight then I would not choose raspberry pi nor arduino.
Also, stepper motors would be a off the list.
No, it's not meant to fly, apart from a breathing led light (I know how to do this) and the wings just moving up and down it's static.

#### MrChips

Joined Oct 2, 2009
28,155
Ok. Don't use stepper motors. Use a small hobby DC motor that rotate at a fixed speed in one direction.
Use a mechanical linkage to make the wings flap.

#### djsfantasi

Joined Apr 11, 2010
8,792
Using Nitinol to make a heat activated spring is the smallest way to make butterfly wings flap. It is a common way of making commercial animated butterflies.

#### Chopzilla

Joined Jan 7, 2023
7
Here’s a commercial Nitinol butterfly.

You can make your own easily by buying the Nitinol wire .
I have briefly looked at this but it still leaves me with my original problem of I don't know what I'm doing or need to make any of these things work and past wiring up some LEDs with an on/off switch I have no knowledge of how to do this. It doesn't matter how much I read or watch, I just simply don't understand it.

#### djsfantasi

Joined Apr 11, 2010
8,792
You can use a pre-made PIR Module as your sensor. Besides power to the module you need two connections to its relay. With the commercial Nitinol butterfly in the link above, you would cut one of its power supply wires in two and connect them to the Common and NO (Normally Open) connections of the relay. Then when someone comes near, the butterfly will flap its wings. That’s it: 4 wires and 2 modules. There is one gotcha. Depending on if the butterfly adapter is the correct voltage for the PIR module, you may need a second power supply. But still 4 wires and 2 modules.

#### KeithWalker

Joined Jul 10, 2017
2,724
You don't need a microcontroller or a stepper motor for this project. There are small geared 60RPM motors available for low DC voltages that could be driven directly by a PIR switch. Check out both components on AliExpress.
The mechanical linkages are very rudimentary as you can see on the pictures below of a little 6" flying butterfly that I made:

#### djsfantasi

Joined Apr 11, 2010
8,792
@KeithWalker
Great project. But it seems to me the TS ability is at the wiring diagram phase and even a schematic would be over his / her head. I’d have done so in my post, but don’t even have a pen and paper in my hospital bed (slight temporary inconvenience)

#### MrChips

Joined Oct 2, 2009
28,155
@djsfantasi Hope they send you home soon.
Get well!

#### Chopzilla

Joined Jan 7, 2023
7
@KeithWalker
Great project. But it seems to me the TS ability is at the wiring diagram phase and even a schematic would be over his / her head. I’d have done so in my post, but don’t even have a pen and paper in my hospital bed (slight temporary inconvenience)
Not entirely true. I've been using wiring diagrams and reading architectural as well as m&e blueprints for the past 16 years, just because I don't understand how a thing works doesn't mean I can't follow a plan...

#### djsfantasi

Joined Apr 11, 2010
8,792
Not entirely true. I've been using wiring diagrams and reading architectural as well as m&e blueprints for the past 16 years, just because I don't understand how a thing works doesn't mean I can't follow a plan...
I apologize for my assumptions. How very rude of me.

#### KeithWalker

Joined Jul 10, 2017
2,724
Here is what you need:

12VDC PIR sensor switch module: