Arduino 33 IoT Pushbutton to Servo - Breathing Bud Mechanical Flower

by rimonsta in Circuits > Arduino

587 Views, 3 Favorites, 0 Comments

Arduino 33 IoT Pushbutton to Servo - Breathing Bud Mechanical Flower

IMG_4780.jpg

The Breathing Bud is a mechanical flower, a friend you can slow down and breathe with when you've got too much on your mind. You don't need much to make a Breathing Bud, and once it's dead you can certainly repurpose it, as they're designed to fall apart eventually.

Supplies

Microcontroller [like Arduino Nano 33 IoT] $24

Breadboard [link] $7 for 3

Jumper wires [link] $7 for a pack

Pushbutton [from Sparkfun] $0.50 a piece

Prototype board [for soldering] $2

3 servo motors [link] $2 each

Hot glue & glue gun [link] $10

Lamp shade [from Goodwill] $2

Sculpting wire [from Michael's] $7

Packaging tape [from Home Depot] $12

Colored construction paper [from Michael's] $5

Fluff [polyester fiber fill] $30 a bag

MicroUSB cord [from Best Buy] $8

Laptop [like MacBook]

with Arduino IDE installed [free]

if you have a Mac you will also need a USB-C to MicroUSB adaptor [link] $7

TOTAL: ~ $135 [plus cost of laptop]

Connect Your Microcontroller

IMG_4769.jpg
IMG_4770.jpg

Make sure your microcontroller is stable on your breadboard and, using jumper wire, connect your power and ground on the microcontroller to the breadboard's power rails.

PRO TIP: For more secure connections, use coated solid core wire and cut it to a size where it can lay flat on your breadboard. Use red for power and black for ground. I didn't have black solid core wire so I used green. Solid core wire costs around $16. Link on Amazon: https://www.amazon.com/TUOFENG-Hookup-Wires-6-Different-Colored/dp/B07TX6BX47/ref=asc_df_B07TX6BX47/?tag=&linkCode=df0&hvadid=366430786295&hvpos=&hvnetw=g&hvrand=11252791347404772323&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9028818&hvtargid=pla-793870383734&ref=&adgrpid=75985294733&th=1

PRO TIP: Connect your power rails across your breadboard so you can access power and ground from either side.

Solder Your Pushbutton

IMG_4771.jpg
IMG_4783.jpg
IMG_4784.jpg

Break off a small piece of the breakout board and solder your pushbutton to it. You may need some help getting access to a soldering iron. I used multiple tutorials to figure this one out.

Here is a link to understanding pushbutton circuits: https://docs.arduino.cc/built-in-examples/digital/Debounce

Here is a link to soldering on prototype boards: https://www.youtube.com/watch?v=l9Kbr8cPqOE

PRO TIP: I was told that you don't need to add a resistor to your pushbutton circuit, just connect your power to a digital pin and ground to ground. The important part is debouncing your pushbutton in your Arduino code so that the loop doesn't try to read your button state too quickly, otherwise you will get unreliable readings.

Connect Pushbutton to Servo

IMG_4772.jpg

I followed this tutorial for connecting my pushbutton to a single servo motor, just to make sure I could get one working. Connect the red wire to your power, the brown wire to your ground, and the orange wire to a digital pin. You want to make sure that the servo motor can move to your desired angle (mine ended up being 60) after you push the button, and then move back to 0.

PRO TIP: Use the Serial monitor to get feedback from your button and motor.

Connect All 3 Servo Motors

IMG_4773.jpg
Screen Shot 2022-12-16 at 7.10.20 PM.png

This is the final part of hardware and coding needed to make your flower petals move properly. Attach all of your servo motors to the microcontroller on your breadboard and in your code. I created a variable called "activateServo" to be toggled when the pushbutton is pressed. The servos are delayed 60 ms for each degree they move by.

Github code

// install the servo library
#include <Servo.h>


// declare servos
Servo petal_1;
Servo petal_2;
Servo petal_3;


// define digital pins for button and servos
#define SERV_PIN1 10
#define SERV_PIN2 9
#define SERV_PIN3 8
#define BUTT_PIN 20


// time to delay servo motion between degree change
int wait = 60;


// toggle for button press to activate motors
bool activateServo;


// state variable initialized at high (meaning button is off)
boolean buttOldState = HIGH;


void setup() {
Serial.begin(9600); // begin serial monitor

pinMode(BUTT_PIN, INPUT_PULLUP);
// initilaizes button pin as input without resistor


// attach servos
petal_1.attach(SERV_PIN1);
petal_2.attach(SERV_PIN2);
petal_3.attach(SERV_PIN3);


// initialize servo activation
activateServo = false;


// ensure servos are at 0 degrees
petal_1.write(0);
petal_2.write(0);
petal_3.write(0);


}


void loop() {


// get a reading from your pushbutton
boolean buttNewState = digitalRead(BUTT_PIN);


// check if button state has changed from off to on
if((buttNewState == LOW) && (buttOldState == HIGH)) {
// short delay to debounce button.
delay(20);


// get a new reading from your pushbutton
buttNewState = digitalRead(BUTT_PIN);
// if it is still on, activate the servo motors
if(buttNewState == LOW) {
Serial.println("button press");
activateServo = true;
}
}


// check if the button has been pressed
if (activateServo == true) {
Serial.println("movin to 60");


// slowly move your servo motors to desired angle
for (int i = 0; i <= 60; i++) {
petal_1.write(i);
petal_2.write(i);
petal_3.write(i);
delay(wait);
}
// slowly move your servos back to 0
for (int i = 60; i >= 0; i--) {
petal_1.write(i);
petal_2.write(i);
petal_3.write(i);
delay(wait);
}
// stop servo motion
activateServo = false;
}


// Set the last-read button state to the old state, should be off (high)
buttOldState = buttNewState;
}

Glue Servos to Lampshade and Attach Arms

IMG_4774.jpg
IMG_4777.jpg

Cut three pieces of sculpting wire about two finger-lengths each and hot glue them to your servo motor arms, bending the wire in a petal-shape. Hot glue your servo motors to the inside of your lampshade. Attach the servo arms with wire petals to your lampshade using hot glue. Test your servo motors again and adjust the arms so that they move out and in together.

PRO TIP: Make sure your wires are long enough that you can lift your lampshade up and ensure your connections are still good.

Attach Petals

IMG_4778.jpg

Cut out petals from construction paper in whatever shape you like. 3 petals for each arm of the servo motor should be glued together at the base. Use a loop of tape on the back of each petal arrangement to slide the petals onto the sculpting wire/servo arms. Make sure the loop is small enough that the petals are secured to the wire. Adjust the wire as needed. If you're having trouble with connections in your circuit, you can remove the petals and lift up your lampshade to see what's going on underneath.

PRO TIP: More glue at the base of your petals will help balance the weight of the construction paper toward the center.

Add a Bit of Fluff

IMG_4780.jpg

Some fluff in the middle will help conceal any wires sticking out. Push the button and breathe in as your flower closes, then breathe out as the flower opens back up again. It will be a little shake-y but that is ok! Just keep breathing.

PRO TIP: The fluff is unnecessary and will only get in the way of you being able to access your connections. I spray-painted my fluff outside and inhaled some toxic fumes, which gave me a headache. Then I became too anxious to share my work with others.

Dispose of Your Flower

Eventually your flower will die and that is ok. If you add too much fluff and fumes, it may die before you get to share it with others. Don't worry, you don't need the flower to breathe, you can do it all on your own.

Disconnect your microcontroller.

Throw away the fluff.

Throw away the tape.

Throw away the wire (or put it back in an organizing bin).

Recycle the construction paper (or reuse it for a collage).

Remove your servo motors using pliers and save them in an organizing bin for future use.

Clean up your hot glue using alcohol.

Make sure everything is unplugged, including your hot glue gun and soldering iron (hopefully you did that already).

Go home and recharge. :)