Sensor Flower- Jenny

Materials:
Paper flower

Cardboard box

Tree branch 

Red and black wire 

2 Adafruit LED sequin and 2 High power LED chips- white but will change to color ones

Ultrasonic Ranger sensor 

MG90S motor

Adafruit Circuit Playground Express 

Alligator- clips one side and the other side is JST-SM pin connector cable. 

  • One to use to connect to motor 
  • Second to connect to Ultrasonic

Battery Holder

Fishing string

Code:

#include <Servo.h>

Servo flowerServo;

// Pins

const int servoPin = A1;

const int openAngle = 180;

const int closeAngle = 0;

const int trigPin = A2;

const int echoPin = A3;

const int distanceThreshold = 50; // cm

const int sequinPin = A5;

// Flower state

bool flowerOpen = false;

bool readyForNextTrigger = true;

// Get distance

long getDistance() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

long duration = pulseIn(echoPin, HIGH, 20000);

if (duration == 0) return 999;

return duration * 0.034 / 2;

}

void fastOpen() {

digitalWrite(sequinPin, HIGH);

for (int pos = closeAngle; pos <= openAngle; pos++) {

flowerServo.write(pos);

delay(4); // <– FASTER (was 8)

}

}

void fastClose() {

digitalWrite(sequinPin, LOW);

for (int pos = openAngle; pos >= closeAngle; pos–) {

flowerServo.write(pos);

delay(4); // <– FASTER (was 8)

}

}

void setup() {

Serial.begin(9600);

flowerServo.attach(servoPin);

flowerServo.write(closeAngle);

flowerOpen = false;

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(sequinPin, OUTPUT);

digitalWrite(sequinPin, LOW);

Serial.println(“Flower Ready (Starts CLOSED)”);

}

void loop() {

long distance = getDistance();

Serial.print(“Distance: “);

Serial.println(distance);

bool isNear = distance < distanceThreshold;

if (isNear && readyForNextTrigger) {

if (!flowerOpen) {

Serial.println(“OPENING…”);

fastOpen();

flowerOpen = true;

} else {

Serial.println(“CLOSING…”);

fastClose();

flowerOpen = false;

}

readyForNextTrigger = false;

}

if (!isNear) {

readyForNextTrigger = true;

}

delay(100);

}

I used an MG90S motor and the Ultrasonic Ranger sensor is connected to the JST-SM pin and the other side of the Alligator- clips are connected to the Adafruit Circuit Playground Express it shows in the next picture.

This picture shows how I connected the two wires and the clips connected to.

MG90S motor pin to CPX

  • Red- VOUT pin
  • Orange- A1 pin
  • Brown- GND pin

Ultrasonic Ranger sensor pin to CPX 

  • Black- GND to GNG pin 
  • Blue- ECHO to A3 pin
  • White- TRIG to A2 pin
  • Gray- VCC to 3.3V

Two wire for LED

  • Red- A5 pin
  • Black- GND pin

These pictures show the inside and outside of my interactive flower project, where I placed the MG90S servo motor, the Ultrasonic Ranger sensor, and the Adafruit CPX inside a hand-painted floral box. I created the flowers using paper petals and mounted them on four separate branches that I painted to look like real stems. Each flower has a small LED light attached in the center. To make the petals move, I tied a clear fishing string from the servo motor up through the branch and onto the petals so that when the motor rotates, the string pulls and opens or closes the flower. The ultrasonic sensor on the front of the box detects when a person comes close, and this triggers the motor to move, causing the petals to respond. The photos show how the wiring runs through the branches, how the components fit inside the decorated box, and how the string is connected directly to the servo arm to control the flower’s motion.

The video shows a handmade electronic flower sculpture where the petals open and close using a servo mechanism. As the camera moves around the project, you can see the ultrasonic distance sensor mounted on the decorated blue base. When a person moves closer to the Ultrasonic Ranger sensor, it detects the distance and activates the MG90S micro servo motor. The servo pulls a string that is attached to the paper petals, causing them to move opening or closing the flower depending on the position. At the center of the flower, a small LED light glows, adding a soft illuminated effect while the mechanism operates.