Eine Rose zum Valentinstag

Today is Valentine's Day is , a date on which we show our affection and love for the special person in our lives. A gift that we always have in mind are red roses because they have a special meaning. But after a few days you lose your freshness and your appearance is not as beautiful as in the first days.

In this project we will make a rose we present in a box. This box will open when touched or when approaching. She has a screen on which we can issue a message. It is a very original gift, and the most important thing is that we can make it with only a few materials and with all the love we want to show a special person.

For the petals of the Rose we use tissue paper as it is transparent. For the goblet sheets, the leaves and the goblet we take a DIN A4 sheet of normal, white paper and for the stalk the tube of a spray bottle. For the illumination of the rose we will use a three-color LED diode.

The project box measures 10 x 10 cm and the rose is 7 cm high, the remaining 3 cm are the case for all circuits.

Although the rose in the project only lights red, we can lit you in the favorite color of the person, which we give the box, or also create a color sequence. We also use a ring with 12 tricolor LEDs to highlight the green color and illuminate the box.

To open and close the box we use a servomotor and as a button two capacitive sensors, which we will produce with only two wires and aluminum foil yourself.

Required materials


LED ring 5V RGB WS2812B 12-bit 37mm




Nano V3.0 with Atmega328 CH340!


MG90s Micro Servo Motor or SG90 Micro Servo Motor 9g


220 ohm resistors


100 KOHM resistors


22 PF capacitors


1.3 inch OLED I2C 128 x 64 pixel display


MB 102 Breadboard Kit with power supply, breadboard and cables


White tissue paper


White plain paper


Plastic spray bottle


Aluminum paper


Transparent universal glue

The box can be made from different materials. I decided for Balsaholz or poplar wood. With a 3D printer, suitable housings can also be created.

Required software

  • Arduino IDE
  • Adafruit Neopixel Library (via library management or here)
  • Wire Library (integrated)
  • Adafruit GFX_Library (via library management or here)
  • Adafruit SSD1306 Library (via library management or here)
  • CapacitIsensor Library (via library management or here)
  • Servo Library (integrated)
  • sketch in O
  • sketch in O

Design and installation of the rose

I'll show now how I manufacture the flower. The template for the parts of the flower must be adapted to the size of the rose we want to create.


Tissue paper is very thin and hard to handle. To make the petals, first make a base of normal paper (1), two petals are sufficient. Then we have to create three petals made of tissue paper and glue them together, taking care that their foundations have the same extent (2). For the goblet, the five skelets (3) and the two leaves (4) take normal paper, it paints with green felt pen and cuts on the edges of the leaves small triangles - the parts of the rose are done. First, glue the five skelets to a starfish (5) and leave a 5 mm high hole for the three-color LED in the middle. Carefully turn the petals inside and glue them to the chalical leaves (6).

For the stem of the flower (7), the hose of any spray bottle is used. The tri-colored LED of the flower we soldered on wires, which we put inside the tube. When the LED is sitting on the stalk, we plug it through the lower hole of the rose and stick the goblet to the chalical sheets. To close the upper hole of the rose, we create a circle of tissue paper, glue a thin strip on it, stick it to the rose and we have already made our flower with love.

the flower

On the mini breadboard we will install the microcontroller, the resistors, capacitors and in our case the 5V DC power supply. All this is placed in the lower part of our box. Inside the box are the servomotor, the LED ring, the two capacitive sensors and inside the rose the three-color LED diode.

Production and description of the capacitive sensor

First of all, I will explain how the capacitive sensor we use to open and close the box works and how to make it.

Switching timetable1

A capacitor consists of two plates separated by a dielectric. For our sensor we only need a 100-k ohm resistance, a 22-pF capacitor, a piece of aluminum foil and cable.

As we can see in the circuit, we have a resistor parallel to a capacitor and the receiver the piece of aluminum foil. Under normal conditions, the capacitor is charged by the transmitter pin to the supply voltage, the receiver pin reads the voltage stored in the 22 PF capacitor and remains stable. Our sensor is the piece of aluminum, which acts as one of the plates of a capacitor, and we, or our finger than the other plate. The dielectric is the room between us and the piece of aluminum. The closer we come, the lower the value of the dielectric, and we reach a distance in which we begin to guide electricity.

To illustrate the above embodiments, the following circuit should be established (Download the circuit diagram):

Switching schedule2

For this, the CapacitIsensor library must now be installed and the sketch capacitive_sensor_check.ino getting charged. When we approach one of the aluminum foil pieces, the corresponding LED should light up. In the lines

long Green_reading = Green_sensor.capacitivesor(30);

Standing the number in brackets for the sensitivity of the sensor resulting from the number of scans over a certain period of time. You can change the value to adjust the detection.

The scketch code is simple and each line is explained so that it is very easy to track and analyze.

Circuit and description of the operation of the overall project

The following picture shows the electronic structure of all components used (Download the circuit diagram):

Switching timetable3

The operation is very simple: as soon as the sketch is started, the box is closed, there is no light inside and the OLED display shows the message "February 14". If you put the hand, fingers or (depending on the sensitivity setting) the aluminum foil on the lid, the lid opens with the servomotor and the rose inside lights up red (can also be set to any color), 6 of the 12 LEDs On the ring light up green and reinforce the green of the flower and the message "Happy Valentine's Day" appears on the display. As long as we do not touch the piece of aluminum foil inside, the box does not begin to close, and if closing, the LED stops on the rose to light up. The LEDs of the ring change from green on white, so that the closed box remains illuminated inside. The display shows again the original message "February 14".

To open the box again, you have to touch the aluminum foil of the box cover or approach your. When the box is open, the lid will not move when touching the aluminum foil of the box because I have written a condition in the sketch I'll show later.

Let's start with the analysis of the code of the sketch valentine_day_box.ino. First, the necessary libraries of the modules or components we want to use must be integrated. They contain the methods we use, for example, when initializing a component, or to perform actions with these modules. The libraries we invalid are those of the OLED screen, I2C communication (Wire), the capacitive sensor, servomotor and WS2812B RGB LED ring.

// 1.3 inch OLED I2C 128x64 pixel display libraries
#include <Wire.H>
#include <Adafruit_gfx.H>
#include <Adafruit_ssd1306.H>

// Library Required for Operation of the Capacitive Foil Sensor
#include <Capacitivesor.H>

// servo engine library
#include <Servo.H>

// LED Ring WS2812B Library
#include <Adafruit_neaopixel.H>

After we have integrated the libraries, we need to configure the properties of each module or component and implement an object for a component. The first component at which we carry out these measures is the LED ring. As you can see in the circuit, we have connected it to the digital pin 10, to see in the first line of the following code. In the second line, we specify the number of LEDs contained in the ring, namely 12.

// Define Pin and Number of LEDs on WS2812B Ring
#define ring_led 10
#define ring_led_count 12

In the following line we implement an object for the ring we call ring. In the constructor of the object, as a parameter, we must specify the number of LEDs (12), the PIN of the microcontroller (10) and the properties of the ring. It is the three-color LEDs (RGB) with a working frequency of 800 kHz.

// WS2812B Ring Object
Adafruit_neaopixel ring(ring_led_count, ring_led, Neo_grb + Neo_khz800);

In the following lines we configure a series of colors using RGB values ​​for each LED, e.g. For example, for the color red we have to enable the red LED and leave the green and blue LED disabled. For the yellow color we turn on the red and green LEDs and leave the blue LED off.

// WS2812B Ring Colors
uint32_t red = ring.Color(150,0,0);
uint32_t Green = ring.Color(0,150,0);
uint32_t blue = ring.Color(0,0,150);
uint32_t yellow = ring.Color(150,150,0);
uint32_t purple = ring.Color(150,0,150);
uint32_t Light_blue = ring.Color(0,150,150);
uint32_t white = ring.Color(150,150,150);

The next component we configure is the OLED screen. His features are 128 pixels wide and 64 pixels high.

#define Screen_width 128
#define Screen_height 64

In order to implement a display object, the constructor parameters we need to consider are the variables for the width and height of the display, & wire is a call to an address in the I2C communication library wire and -1 would be the connection of the reset pins , if available.

Adafruit_ssd1306 display(Screen_width, Screen_height, &Wire, -1);

The next two lines are the implementations of two objects of the capacitive sensor class for detecting the opening and closing of the box. The first parameter is the transmitter pin, via which we supply the sensors with 5 VDC, and the second parameter is the recipient, which we recognize the voltage change.

Capacitivesor Touch_open = Capacitivesor(4, 3);
Capacitivesor Touch_close = Capacitivesor(6, 5);	

For the configuration of the servomotor we first implement the object servo_box of the class Servo and define a variable called degree to store the position value of the servomotor in degrees.

Servo servo_box;
int degree;

The last three lines of the definition block are the pins of the microcontroller to which we connect the pins of the three-colored diode for the rose (7, 8 and 9) for the colors red, green or blue.

#define red_led 7
#define Green_LED 8
#define Blue_LED 9

The next block is the setup () that runs only once and is the initial configuration of the components in the power supply of the microcontroller and when starting. We start with the initialization of the serial IDE console, we also initialize the OLED screen and check if it is connected via the address 0x3c via I2C communication protocol. If he is not connected or the address is different, a message appears on the serial IDE console that informs us about it. Open the serial monitor (Ctrl + Shift + M) for the output.

    IF(!display.Begin(SSD1306_SWITCHCAPVCC, 0x3c)) {            // Display Connection Check
          Serial.Println(F("SSD1306 ALLOCATION FAILED"));

After initializing the screen, we want to show a message on it. To do this, we have to assign values ​​to the parameters of the methods of the screen object. We set the color of the text and the font size (2 corresponds to a height of 16 pixels), position the cursor in column 20 and line 0, where we want to write "February" and put the cursor in column 40 and line 30 to the Word "14" word. After allowing all values ​​of the text properties and the text itself, we use display.display () the command to display the text described in the previous lines with the values ​​for positioning, font size and color on the screen.

    display.Clear display();                                     // DELETE SCREEN CONTENT
    display.SettextColor(White);                                // set color text 
    display.SatxSize(2);                                     // SET FONT SIZE
    display.setcursor(20,0);                                    // position The cursor in Column 20 and Row 0
    display.print("February");                                  // Word to be displayed
    display.setcursor(40,30);                                   // position The cursor in Column 40 and Row 30
    display.print("14th");                                      // Word to be displayed
    display.display();                                          // show all the ABOVE Words with the Settings

In the next line of the setup () block, we indicate that we have connected the servomotor to pin 12 of the microcontroller.


We also need to configure the output pins of the microcontroller where we have connected the three-color LED of the rose. Remember that we have defined three variables with the PIN numbers in the previous block.

    pinmode(red_led, OUTPUT);
    pinmode(Green_LED, OUTPUT);
    pinmode(Blue_LED, OUTPUT);

The last line of this block is the initialization of the LED ring.


Now we go to the loop () - block over, which runs as a permanent loop constantly. It was simplified by methods to obtain a cleaner and more schematic code. In this block, we only have the definitions of two variables for the values ​​of the capacitive sensors for opening and closing the box. In addition, the simple conditional blocks to check the values ​​and execute the appropriate methods. Let us remember Dara that the number in brackets ((30)) in the definition lines of the variables is the sensitivity. It is the number of samples in a certain period of time we can customize to detect the touch and perform the appropriate action.

The detection takes place because, when we approach the aluminum foil, we create a "capacitor" between us and the box. Our approach means that the voltage value changes in the transmitter pin. The value is in the variables Open_Box or Close_box saved. These variables are handed over to the IF conditions as arguments for verification. If a condition is satisfied, the corresponding method is executed.

    long Open_Box = Touch_open.capacitivesor(30);        // Variable to Store The Value of Open Box, Sensitivity in Parentheses

    long Close_box = Touch_close.capacitivesor(30);      // Variable to Store The Value of Close Box, Sensitivity in Parentheses

    // Compare Readings
    IF(Open_Box > 1) {
        Opening_Box();              // Call to the Method of Opening the Box

    IF(Close_box > 1) {
        closing_box();             // Call to the Method of Closing the Box 

We will now be the method Opening_Box analyze. When this method is performed, the first command is reading the position of the servomotor. If the box is open, we do not have to make action. If the position of the servo motor is higher than 175 degrees, this means that it is open. Then we leave the method and return to the loop () - block.

    degree = servo_box.reading();
    IF (degree>175) {                             // we check that if the servo motor position is highher Than 170 degrees we exit and the Lid does not move.

Otherwise, if the box is closed, we run the for loop and the position of the servo motor moves from the 90 degree position to 180 degrees. Then our rose lights up red immediately.

    Else {
      for (int pos=90; pos<180; pos++) {          // if it is Lower, The Box Open At Slow Speed ​​Up to 180 degrees.
    color_led(255, 0, 0); 

The WS2812B-RGB LED ring will light 6 of the 12 LEDs green. The commands we program for it is in the following order:

First, we turn off all LEDs when they light up. We set the brightness to a value of 50 out of a total of 255. Then we declare the LEDs we want to use, and the color of each one of them. Here we have to remember that they are listed by LED0 to LED11. Finally, we carry everything that was previously declared with the command Ring.Show () out.

    ring.Clear();                                 // Power Off the LEDs
    ring.setBrightness(50);                       // Set Luminosity Set to 50 Out of 255
    ring.SetpixelColor(0, Green);                 // WE set the LED 1 of 12 of the ring Lights Green
    ring.SetpixelColor(2, Green);                 // LED 3
    ring.SetPixelColor(4, Green);                 // LED 5
    ring.SetPixelColor(6, Green);                 // LED 7
    ring.SetpixelColor(8, Green);                 // LED 9
    ring.SetpixelColor(10, Green);                // LED 11
    ring.show();                                  // Turn on the LEDs with the Configured Color and Brightness.

When the box is open, we change the message on the screen in "Happy Valentine's Day"With the following code lines:

    display.Clear display();                       // DELETE SCREEN CONTENT
    display.SatxSize(1);                       // SET FONT SIZE
    display.setcursor(50,0);                      // position The cursor in Column 50 and Row 0.
    display.print("Happy");                       // Word to be displayed
    display.setcursor(30,20);                     // position The cursor in Column 30 and Row 20.
    display.print("Valentine's");                 // Word to be displayed
    display.setcursor(55,40);                     // position The cursor in Column 55 and Row 40.
    display.print("Day");                         // Word to be displayed
    display.display();                            // show all the ABOVE Words with the Settings 

These lines are similar to those previously in set up()Block have been described, where we also have the text "February 14" on the screen. With the analysis of the Opening_Box ()Methods will be easy for you to analyze the Closing_Box ()Blocks themselves perform as they are very similar.

The last method we have in the sketch is used to make the three-color LED of the Rose lit. This LED consists of three independent diodes indicating the desired color by the visual mixture. These are 8-bit values ​​from 0 to 255.

void color_led (int value_red_led, int value_green_led, int VALUE_BLUE_LED) {

      // Analog Output Method for the Tricolor LED (Output Pin, RGB Value)
      analogwrite(red_led, value_red_led);
      analogwrite(Green_LED, value_green_led);
      analogwrite(Blue_LED, VALUE_BLUE_LED);

Sketch Downloads:



Touch with low and high sensitivity:

We hope that you like this new project.

DisplaysFor arduinoSensorsSpecials


Andreas Wolter

Andreas Wolter

@Dieter: Möglicherweise haben Sie ein Display mit einem anderen Chip drauf. Die Displays ähneln sich stark. Das Problem hatte ich auch schon. Das ist aber nur eine Vermutung. Dann funktioniert die SSD1306 Bibliothek nicht.



Danke für diese tolle Anwendung, die sich auch auf andere Gelegenheiten übertragen lässt. Mit dem Ansteuern des Dispaly habe ich ein problem: es gibt zwar keine Fehlermeldung, aber der Text wird nicht angezigt (es gibt ein random dot pattern auf dem Schirm). Das Display funktionier, wenn ich dieU8g2 library verwende…

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN