Dancing Flower
Our project is a dancing flower that reacts to its environment using an Arduino Uno. The flower has two main modes: light mode and distance mode. In light mode, two light sensors detect which side has more light, and the servo motor turns the flower toward the brighter side. In distance mode, the ultrasonic sensor measures how close something is, and the servo moves the flower based on that distance. A button is used to switch between the two modes. This project can be mode super quick and easy!
Supplies
The materials used for this project come mainly from the SparkFun Inventor’s Kit and standard Arduino components. The following items were required to build the dancing flower:
- Arduino Uno (main microcontroller)
- Breadboard (for circuit connections)
- Jumper wires (male-to-male)
- Servo motor (for flower movement)
- Ultrasonic sensor (HC-SR04) (for distance detection)
- 2 Photoresistors (LDRs) (for light detection)
- 2 Resistors (~10kΩ recommended for voltage dividers with LDRs)
- Push button (for switching modes)
- USB cable (to power and upload code)
- Cardboard (8” length, 4” height, 4 ½ “ width
- Peanut butter jar , or 3D-printed housing (for structure)
- Artificial flower or paper flower (attached to servo)
- Screws and bolts (for securing components): 2- M3*20, 1-M3*12, 1-M3*30, 4- M3 nuts
- ⅛ “ drill bit, and a 13/16” drill bit
- Exacto knife
- 2 Mechanical pencils
- Tape
TinkerCAD
Let’s start this project with a TinkerCAD simulation. First, you want to wire your servo, button, and the sensors (photoresistors and ultrasonic sensor) according to the circuit design. Make sure the servo is connected to a PWM pin, the button is set up with INPUT_PULLUP, and the sensors are connected to the correct analog and digital pins. Once everything is wired, upload your code and run the simulation to test that the servo responds correctly in both light mode and distance mode. This step helps catch wiring or coding errors before building the physical circuit.
Component Connections (What you pins you should connect to)
- Servo Motor
- Signal → Pin 2
- Power → 5V
- Ground → GND
- Left Photoresistor (LDR)
- Signal/output → A0
- Right Photoresistor (LDR)
- Signal/output → A1
- Push Button
- One side → Pin 13
- Other side → GND
- Uses INPUT_PULLUP
- Ultrasonic Sensor (HC-SR04)
- TRIG → Pin 5
- ECHO → Pin 6
- VCC → 5V
- GND → GND
Coding
This code makes a “dancing flower” using an Arduino that can react to what’s happening around it. There are two modes, and you switch between them using a button. In the first mode, the flower uses two light sensors to see which side is brighter, and it turns toward the light like a real plant. In the second mode, it uses a distance sensor to tell how close something is, and it moves based on how near or far your hand is. The code also makes the movement slow and smooth so it looks more natural instead of jerky. Overall, the flower “dances” by reacting to light and people nearby.
Downloads
Wiring
Now you're going to want to copy your Tinkercad diagram to your Arduino board. Attached is a video explaining how to wire this project. This might start to look a little crazy with all of the wires. But you’re doing great!
Building
First, we needed to alter the servo. We used the circular servo attachment because the other attachments could weaken and break once holes were drilled into them. The circular attachment was the sturdiest option. We then used a 1/8-inch drill bit to enlarge two opposite holes in the attachment. After that, we took apart a mechanical pencil until only the main shaft remained. Using the drilled holes as a guide, we marked the pencil and drilled two matching holes into it, making sure the eraser side faced downward. We inserted two M3-20 screws into the attachment, mounted it onto the servo, and bolted the pencil onto the attachment. Finally, we inserted the flower into the top of the pencil so it could move with the servo.
Next, we enlarged the servo mounting holes using a 1/8-inch drill bit. We lined the servo up against the plastic jar, drilled out the four corners, and carefully cut out a square opening for the servo to fit through. After inserting the servo from the inside of the jar, we drilled another hole so an M3 screw could secure the servo in place. We also drilled a larger hole in the front of the jar using a 13/16-inch drill bit so the connectors and wires could pass through more easily. Since the connectors were difficult to fit from the outside, we found it easier to insert some of them from inside the jar.
After that, we attached the cardboard box to the jar by placing the lid inside the box and drilling a hole through the jar, lid, and box using a 1/8-inch drill bit. We connected everything using an M3-30 screw, and needle nose pliers helped make assembly easier. We made sure not to place the mounting hole in the center because another large hole was needed for the wires to pass from the jar into the box. We also cut a square opening in the cardboard box for the servo and another opening for the micro USB port so the Arduino could still be plugged in easily. For the distance sensor and light sensors, we used female-to-female connectors and secured them with electrical tape.
Finally, we took apart another mechanical pencil and used the eraser end as a button extension. We slightly enlarged the inside using an X-Acto knife until it fit over the button. Then, we cut a hole in the top of the cardboard box so the pencil shaft would stick out when the box was closed. This allowed us to press the pencil shaft to activate the button underneath. We also added tape to the top of the pencil to make it softer and easier to press. To hide our cardboard box, we printed a vase background and taped it on to the box.
Testing and Troubleshooting
Now it’s time for the fun part. Connect your Arduino, upload the code, and begin testing how the flower responds to its environment. Open the Serial Monitor and set it to 9600 baud so you can observe the live sensor readings and servo movement. In light mode, the monitor will display the left and right photoresistor values along with the servo angle. For example, you may see something like Light Mode: L: 54 R: 974 Servo: 60. This means the left sensor is detecting very little light while the right sensor is detecting a large amount of light, causing the flower to rotate toward the right side where the brighter light source is located. As you move a flashlight or cover one of the sensors, the values and servo angle should continuously update in real time.
In distance mode, the Serial Monitor will display the measured distance in inches along with the servo angle. The flower should smoothly react as you move your hand closer or farther away from the ultrasonic sensor. If the project is not working correctly, there are a few common problems to check. Make sure the servo is connected to the correct pin and has both power and ground connected. If the light sensors are not changing values, verify that they are wired correctly to the analog pins. If the ultrasonic sensor gives no reading or returns -1, check that the trig and echo wires are not swapped. Loose jumper wires and missing ground connections are also common issues, so double-check all wiring until the flower responds smoothly and the Serial Monitor displays changing values correctly.
FINAL PRODUCT
Can We Make This Project Better?
- Add LED’s
- Add an Ardiuno speaker and code the song
- https://projecthub.arduino.cc/tmekinyan/playing-popular-songs-with-arduino-and-a-buzzer-546f4a (popular song codes)
- Use the button to make different “dance moves” for the flower
- Make the flower follow the user’s movements