Electronics Development
The electronic system of the final project is based on the work developed in the previus weeks, where I tested the interaction between a PIR sensor, a servo motor, an LED indicator, and the XIAO ESP32-C3 microcontroller. This previous exercise was important because it allowed me to validate the basic logic that will later be integrated into the kinetic flower.
The objective of the electronic system is to allow the flower to react to the presence of a person. When the PIR sensor detects movement, the microcontroller processes the signal and activates the servo motor. The servo is mechanically connected to the central mechanism, which controls the opening and closing movement of the petals.
A. Electronic Components
- Microcontroller: Seeed Studio XIAO ESP32-C3
- Input device: PIR motion sensor
- Output device: servo motor
- Visual indicator: LED
- Manual control: switch
B. System Logic
The interaction logic follows a simple input-control-output structure:
- The switch enables or disables the system.
- When the system is enabled, the LED turns on as a visual indicator.
- The PIR sensor detects the presence or movement of a person.
- The XIAO ESP32-C3 reads the sensor signal and processes the condition.
- If motion is detected, the servo motor moves between defined angles.
- This servo movement activates the central mechanism that opens or closes the petals.
C. Connection Diagram
The following circuit configuration was tested during Week 10 and will be used as the base for the final project electronics:
- PIR sensor: connected to digital pin D4.
- Servo motor: signal connected to digital pin D3.
- Switch: connected to digital pin D5.
- LED: connected to digital pin D6 through a current-limiting resistor.
- Power: Battery power system.
In the final project, this same logic will be adapted to the physical structure of the flower. The PIR sensor will be placed in the center of the petals using a dedicated 3D-printed support, while the servo will be integrated into the lower central mechanism.
D. Code Used as Reference
#define PIR_PIN D4
#define SWITCH_PIN D5
#define LED_PIN D6
#include <ESP32Servo.h>
Servo myServo;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
pinMode(SWITCH_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
myServo.attach(D3);
}
void loop() {
int encendido = digitalRead(SWITCH_PIN);
Serial.print("button: ");
Serial.println(encendido);
delay(200);
if (encendido == 1) {
digitalWrite(LED_PIN, HIGH);
int estado = digitalRead(PIR_PIN);
Serial.print("pir: ");
Serial.println(estado);
if (estado == 1) {
delay(200);
myServo.write(0);
delay(1000);
myServo.write(180);
delay(1000);
} else {
myServo.write(0);
}
} else {
digitalWrite(LED_PIN, LOW);
myServo.write(0);
}
}
Code Explanation
The code begins by defining the pins used for the PIR sensor, switch, and LED. The servo motor is controlled using the ESP32Servo library, which allows the XIAO ESP32-C3 to generate the PWM signal required to move the servo to specific angles.
In the setup() function, the PIR sensor and switch are configured as digital inputs, while the LED is configured as a digital output. The servo motor is attached to pin D3, and serial communication is initialized to monitor the sensor and switch values during testing.
In the loop() function, the system first reads the state of the switch. If the switch is activated, the LED turns on, indicating that the system is enabled. Then, the PIR sensor is read. If motion is detected, the servo moves between 0° and 180°, generating the mechanical action required for the flower movement.
If no motion is detected, the servo remains in its initial position. If the switch is deactivated, the LED turns off and the servo returns to 0°, keeping the system at rest.
E. Custom PCB Design and Fabrication
To move from a temporary prototype to a stable system, a custom PCB was designed. This allowed the electronic components to be organized in a compact and reliable way, reducing wiring complexity and improving integration with the mechanical structure.
- Schematic design defining all electrical connections.
- PCB layout with organized routing and connection points.
- Generation of toolpaths for CNC milling.
- Manufacturing of the board using a milling machine.
- Soldering of components and connectors.
F. PCB Validation
Before integration, the board was validated to ensure correct operation:
- Continuity tests using a multimeter.
- Voltage and signal verification.
- Oscilloscope measurements to observe signal behavior.
- Functional tests controlling the servo and reading the PIR sensor.
G. Electronic System Validation
The electronic system was designed to be embedded within the structure:
- The PIR sensor is positioned at the center of the petals using a custom support, ensuring a clear detection area.
- The servo motor is mounted in the lower base and mechanically connected to the central mechanism.
- The PCB is placed inside the base, organizing connections and reducing exposed wiring.
This integration transforms the system from a test setup into a functional interactive object, where electronics and mechanics operate together.
For a more detailed explanation of the process, you can visit the corresponding assignment pages.
Considerations and Challenges
- Ensuring stable power supply for the servo motor.
- Avoiding noise or false triggering from the PIR sensor.
- Maintaining reliable connections after moving from breadboard to PCB.
- Aligning the servo movement with the mechanical system.
