Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
AZ-Delivery
Published © GPL3+

Theft alarm with pressure sensors, RGB-LED rings and MP3 mod

This project will use strength-sensitive pressure sensors to produce a visible and audible alert for figure manipulation in a display.

BeginnerShowcase (no instructions)35
Theft alarm with pressure sensors, RGB-LED rings and MP3 mod

Things used in this project

Hardware components

Microcontroller Board AZ-ATMEGA328 board with USB cable
×1
3 Flexible thin film pressure sensor
×1
3 LED ring 5V RGB WS2812B 12-bit 37mm
×1
Ultra -lexified tinned silicone cable switching loads kit
×1
1 SYB-1660 solder-free Breadboard Protoboard | Breadboard kit
×1
1 Mini-MP3 player DFPlayer Master module
×1
1 DFPlayer Mini 3 Watt 8 Ohm Mini loudspeakers
×1
1 1K OHM resistance
×1

Software apps and online services

Arduino id
DFPlayer mini library from Dfrobot (Dfrobotdfplayermini.h)
Adafruit Neopixel Library for WS2812B Ring (Adafruit_neopixel.h)
flex_print_sensor_alarm.ino
1.mp3 Sound file

Story

Read more

Schematics

Circuit diagram

Code

flex_pressure_sensor_alarm.ino

Arduino
Flexible pressure sensor alarm project.
/***************************************************************************************************************************************
*   Flexible pressure sensor alarm project.                                                                                            *
*                                                                                                                                      *
*   The components used are:                                                                                                           *
*   1 Microcontroller Board AZ-ATmega328-Board                                                                                         *
*   3 Film Force Sensitive Resistor                                                                                                    *
*   3 LED Ring 5V RGB WS2812B 12-Bit 37mm                                                                                              *
*   Ultra Flexible Cable Temperature Resistant with Silicone Sheathing                                                                 *
*   1 SYB-1660 Solderless Breadboard Protoboard | Breadboard Kit                                                                       *
*   1 Mini MP3 Player DFPlayer Master Module                                                                                           *
*   1 DFPlayer Mini 3 Watt 8 Ohm Mini loudspeakers                                                                                     *
*   1 1K ohm resistor                                                                                                                  *
*                                                                                                                                      *
*                                                                                                                                      *
*   Miguel Torres Gordo                                                                                                                *
*   Getafe (Madrid) - ESPAÑA          Last revision 18-02-2024                                                                         *
*                                                                                                                                      *
***************************************************************************************************************************************/


#include <SoftwareSerial.h>                                     // Library allows serial communication on other digital pins of an Arduino board.
#include <DFRobotDFPlayerMini.h>                                // Library for DFPlayer Mini from DFRobot.
#include <Adafruit_NeoPixel.h>                                  // LED ring WS2812B Library.

SoftwareSerial mySoftwareSerial(5, 6);                          // Digital pins RX, TX for the mp3 player module.
DFRobotDFPlayerMini myDFPlayer;                                 // Implementation of an object for the mp3 module.

int sensor_flowers_pin = A1;                                    // Definition of the connection pins of the pressure sensor of the flowers to the microcontroller.
int sensor_flowers_signal;                                      // Variable to store the state of the pressure sensor signal of the flowers.
int sensor_menina_pin = A2;                                     // Definition of the connection pins of the pressure sensor of figure Menina to the microcontroller.
int sensor_menina_signal;                                       // Variable to store the state of the pressure sensor signal of figure Menina signal.
int sensor_hand_pin = A3;                                       // Definition of the connection pins of the presure sensor of the hand figure.
int sensor_hand_signal;                                         // Variable to store the state of the pressure sensor of the hand figure.

// Definition of the connection pins of the LED rings to the microcontroller and the number of LEDs on the WS2812B ring.
#define hand_ring_LED 4
#define menina_ring_LED 3
#define flowers_ring_LED 2
#define number_LEDs_ring 8

// WS2812B implementation of LED ring objects for each figure,
// number of LEDs on the WS2812B ring, connection to microcontroller pin, pixels are wired for GRB and 800 KHz bitstream.
Adafruit_NeoPixel flowers_ring(number_LEDs_ring, flowers_ring_LED, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel menina_ring(number_LEDs_ring, menina_ring_LED, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel hand_ring(number_LEDs_ring, hand_ring_LED, NEO_GRB + NEO_KHZ800);

// Definition of variables with colors for WS2812B LEDs flower ring.
uint32_t flowers_color_red = flowers_ring.Color(150,0,0);
uint32_t flowers_color_white = flowers_ring.Color(150,150,150);

// Definition of variables with colors for WS2812B ring of the Menina figure.
uint32_t menina_color_red = menina_ring.Color(150,0,0);
uint32_t menina_color_white = menina_ring.Color(150,150,150);

// Definition of variables with colors for WS2812B ring of the hand figure.
uint32_t hand_color_red = hand_ring.Color(150,0,0);
uint32_t hand_color_white = hand_ring.Color(150,150,150);


void setup() {

      mySoftwareSerial.begin(9600);                                                   // Initialization of SoftwareSerial communication for mp3 module.
      Serial.begin(115200);                                                           // Initialization Serial Monitor communitations.

      if (!myDFPlayer.begin(mySoftwareSerial)) {                                      // Use softwareSerial to communicate with mp3 module.
            Serial.println(F("Error initializing mp3 module:"));                      // Serial Monitor error message on failure to initialize the mp3 module.
            Serial.println(F("1. Please check the connections!"));                    // Serial Monitor error message on failure to initialize the mp3 module.
            Serial.println(F("2. Please insert the microSD memory!"));                // Serial Monitor error message on failure to initialize the mp3 module.
            while(true){
                  delay(0);                                                           // Code to compatible with ESP8266 watch dog.
            }
      }

      Serial.println(F("Correct DFPlayer initialization."));                          // Successful initialization message of the mp3 module.

      flowers_ring.begin();                                                           // Initialization of the ring WS2812B for the flowers.
      menina_ring.begin();                                                            // Initialization of the ring WS2812B for the Menina figure.
      hand_ring.begin();                                                              // Initialization of the ring WS2812B for the hand figure.

      flowers_ring.clear();                                                           // Power off the ring LEDs for the flowers.
      menina_ring.clear();                                                            // Power off the ring LEDs for the Menina figure.
      hand_ring.clear();                                                              // Power off the ring LEDs for the hand figure.

      flowers_ring.setBrightness(200);                                                // Set brightness to 200 of 254 of the 8 LEDs of the flowers.
      for (int i=0; i<number_LEDs_ring; i++) {                                        // Loop to LIGHT ON the 8 leds of the WS2812B rings of the flowers.
            flowers_ring.setPixelColor(i, flowers_color_white);                       // LED configuration of the flowers with white color.
            flowers_ring.show();                                                      // LED lighting.
      }

      menina_ring.setBrightness(200);                                                 // Set brightness to 200 of 254 of the 8 LEDs of the Menina figure.
      for (int i=0; i<number_LEDs_ring; i++) {                                        // Loop to LIGHT ON the 8 leds of the WS2812B rings of the Menina figure.
            menina_ring.setPixelColor(i, menina_color_white);                         // LED configuration of the Menina figure with white color.
            menina_ring.show();                                                       // LED lighting.
      }

      hand_ring.setBrightness(200);                                                   // Set brightness to 200 of 254 of the 8 LEDs of the hand figure.
      for (int i=0; i<number_LEDs_ring; i++) {                                        // Loop to LIGHT ON the 8 leds of the WS2812B rings of the hand figure.
            hand_ring.setPixelColor(i, hand_color_white);                             // LED configuration of the hand figure with white color.
            hand_ring.show();                                                         // LED lighting.
      }

      // Initialization of the variables with a high value, since the figures will be placed.
      sensor_flowers_signal = 900;
      sensor_menina_signal = 900;
      sensor_hand_signal = 900;

}


void loop() {

      if (sensor_flowers_signal < 1000) {                                                 // Conditional, if the value of the flower pressure sensor signal is less than a value of 1000, the code contained between braces is executed.

            sensor_flowers_signal = analogRead(sensor_flowers_pin);                       // The current value of the flower pressure sensor is read and the value is stored in the sensor_flowers_signal variable.
            Serial.print("Sensor flowers reading = ");                                    // The text written between the brackets is displayed in the Serial Monitor.
            Serial.print(sensor_flowers_signal);                                          // The current value of the sensor_flowers_signal variable is displayed in the Serial Monitor after the above text.

            if (sensor_flowers_signal < 200) {                                            // Conditional, if the value of the sensor_flowers_signal variable is less than 200, the code between the braces will be executed.

                  Serial.println("The flowers have been manipulated !!!!");               // The text written between the brackets is displayed in the Serial Monitor.
                  flowers_ring.setBrightness(200);                                        // Set brightness to 200 of 254 of the 8 LEDs of the flowers.
                  for (int i=0; i<number_LEDs_ring; i++) {                                // Loop to LIGHT ON the 8 leds of the WS2812B rings of the flowers.
                        flowers_ring.setPixelColor(i, flowers_color_red);                 // Configuration of the 8 LEDs of the flowers with the red color.
                        flowers_ring.show();                                              // Illumination of the ring LED of the flowers.
                  }

                  myDFPlayer.volume(10);                                                  // Set the volume value to 10, values from 0 to 30.
                  myDFPlayer.loop(1);                                                     // Loop playback of mp3 sound from microSD card, does not stop the alarm sound.
                  delay(500);

            } else if (sensor_flowers_signal < 1000) {                                    // If the value of the flower pressure sensor signal is less than a value of 1000 but greater than or equal to 200, the code contained between braces is executed.
                  Serial.println("Flowers are OK and have not been manipulated.");        // The text written between the brackets is displayed in the Serial Monitor.
            }
      }

      if (sensor_menina_signal < 1200) {                                                  // Conditional, if the value of the flower pressure sensor signal is less than a value of 1200, the code contained between braces is executed.

            sensor_menina_signal = analogRead(sensor_menina_pin);                         // The current value of the Menina figure pressure sensor is read and the value is stored in the sensor_menina_signal variable.
            Serial.print("Sensor menina figure reading = ");                              // The text written between the brackets is displayed in the Serial Monitor.
            Serial.print(sensor_menina_signal);                                           // The current value of the sensor_menina_signal variable is displayed in the Serial Monitor after the above text.

            if (sensor_menina_signal < 200) {                                             // Conditional, if the value of the sensor_menina_signal variable is less than 200, the code between the braces will be executed.

                  Serial.println("The Menina figure have been manipulated !!!!");         // The text written between the brackets is displayed in the Serial Monitor.
                  menina_ring.setBrightness(200);                                         // Set brightness to 200 of 254 of the 8 LEDs of the Menina figure.
                  for (int i=0; i<number_LEDs_ring; i++) {                                // Loop to LIGHT ON the 8 leds of the WS2812B rings of the Menina figure.
                        menina_ring.setPixelColor(i, menina_color_red);                   // Configuration of the 8 LEDs of the Menina figure with the red color.
                        menina_ring.show();                                               // Illumination of the ring LED of the Menina figure.
                  }

                  myDFPlayer.volume(10);                                                  // Set the volume value to 10, values from 0 to 30.
                  myDFPlayer.loop(1);                                                     // Loop playback of mp3 sound from microSD card, does not stop the alarm sound.
                  delay(500);

            } else if (sensor_menina_signal < 1200) {                                     // If the value of the flower pressure sensor signal is less than a value of 1200 but greater than or equal to 200, the code contained between braces is executed.
                  Serial.println("Menina figure are OK and have not been manipulated.");  // The text written between the brackets is displayed in the Serial Monitor.
            }
      }

      if (sensor_hand_signal < 1000) {                                                    // Conditional, if the value of the flower pressure sensor signal is less than a value of 1000, the code contained between braces is executed.

            sensor_hand_signal = analogRead(sensor_hand_pin);                             // The current value of the hand figure pressure sensor is read and the value is stored in the sensor_hand_signal variable.
            Serial.print("Sensor hand figure reading = ");                                // The text written between the brackets is displayed in the Serial Monitor.
            Serial.print(sensor_hand_signal);                                             // The current value of the sensor_hand_signal variable is displayed in the Serial Monitor after the above text.

            if (sensor_hand_signal < 200) {                                               // Conditional, if the value of the sensor_hand_signal variable is less than 200, the code between the braces will be executed.

                  Serial.println("The hand figure have been manipulated !!!!");           // The text written between the brackets is displayed in the Serial Monitor.
                  hand_ring.setBrightness(200);                                           // Set brightness to 200 of 254 of the 8 LEDs of the hand figure.
                  for (int i=0; i<number_LEDs_ring; i++) {                                // Loop to LIGHT ON the 8 leds of the WS2812B rings of the hand figure.
                        hand_ring.setPixelColor(i, hand_color_red);                       // Configuration of the 8 LEDs of the hand figure with the red color.
                        hand_ring.show();                                                 // Illumination of the ring LED of the hand figure.
                  }

                  myDFPlayer.volume(10);                                                  // Set the volume value to 10, values from 0 to 30.
                  myDFPlayer.loop(1);                                                     // Loop playback of mp3 sound from microSD card, does not stop the alarm sound.
                  delay(500);

            } else if (sensor_hand_signal < 1000) {                                       // If the value of the flower pressure sensor signal is less than a value of 999 but greater than or equal to 200, the code contained between braces is executed.
                  Serial.println("Hand figure are OK and have not been manipulated.");    // The text written between the brackets is displayed in the Serial Monitor.
            }
      }

}

Credits

AZ-Delivery
16 projects • 3 followers
We are "AZ-Delivery - Your Expert for Microelectronics". Visit our shop with regularly new Blogs and free E-Books.
Contact

Comments

Please log in or sign up to comment.