Acrome-SMD Docs
All Acrome ProductsReferencesBlogCase StudiesContact Us
  • ACROME SMD
  • Electronics
    • 🔴SMD Red
      • Troubleshooting Guide
    • 🔵SMD Blue
    • 🟢SMD Green
    • Gateway Modules
      • Arduino Gateway Module
      • USB Gateway Module
    • Electrical Motors
      • Brushed DC Motors (BDC)
      • Stepper DC Motors (SDC)
      • Brushless DC Motor (BLDC)
      • Linear Actuator with Feedback – 75 lbs
    • Add-on Modules
      • Ambient Light Sensor Module
      • Button Module
      • Buzzer Module
      • IMU Module
      • Joystick Module
      • Potentiometer Module
      • Reflectance Sensor Module
      • RGB LED Module
      • Servo Module
      • Ultrasonic Distance Sensor Module
  • SMD Kits
    • Starter Kit
      • What You Can Build
    • Education Kit
      • What You Can Build
    • Motion Kit
      • What You Can Build
  • Software
    • Libraries
      • Python Library
      • Arduino Library
      • Java Library
      • Matlab Library
    • SMD UI
    • SMD Blockly
      • Introducing Customized Blockly Blocks
  • SMD Applications
    • Basics
      • Blink
      • Action - Reaction
      • Autonomous Lighting
      • Smart Doorbell
      • Security System
      • Distance Buzzer Warning
      • Distance Auto Stop
      • Smart Light Control
    • Interactive
      • Automatic Trash Bin
      • Radar
      • Chrome Dino Game Player
      • Play Chrome Dino Game With Joystick
      • Snake Game With Joystick
      • Pan-Tilt with Joystick Module
      • Joystick Mouse Control
      • Rev Up the Engine
      • Motor Rotation Based on Turn Input Value
      • Basic Motor Speed Control Application
      • Basic Motor Control Application Using PWM Input
      • Basic Motor Position Control Application
      • Basic Motor Torque Control Application
      • Motor Rotation Based on Joystick Counting
    • Robotics
      • Differential Robot Projects
      • Mouse Cursor Tracker Motion Robot
      • Waypoint tracker robot
      • Braitenberg Robot
      • Line-Follower Robot
      • Teleoperation Robot
      • Obstacle Avoidance Robot
      • ESP32 Wireless Controlled Mobile Robot
  • AI
    • Object Tracking Robot
    • Groq Chatbot-Controlled Robot
  • ROS
    • Teleoperation Robot with ROS
  • Mechanics
    • Building Set
      • Plates
        • 2x2 Plate Package
        • 2x3 120° Plate Package
        • 3x3 Plate Package
        • 3x5 Plate Package
        • 3x9 Plate Package
        • 11x19 Plate
        • 9x19 Plate
        • 5x19 Plate
        • 3x19 Plate
        • 9x11 Plate
        • 5x13 Plate
      • Joints
        • 60° Joint Package
        • 90° Joint Package
        • 120° Joint Package
        • Slot Joint M2 Package
        • Slot Joint M3 Package
        • U Joint Package
      • Mounts
        • Add-on Mount Package
        • Motor L Mount Package
        • Pan-Tilt Package
      • Wheels
        • Ball Wheel Package
        • Caster Wheel Package
        • Wheel Package
      • Cables
        • Power Cable 10 cm Package
        • Power Cable 20 cm Package
        • Power Cable 35 cm Package
        • RJ-11 Cable 7.5 cm Package
        • RJ-11 Cable 20 cm Package
        • RJ-11 Cable 35 cm Package
        • RJ-45 Cable 7.5 cm Package
        • RJ-45 Cable 20 cm Package
        • RJ-45 Cable 35 cm Package
      • Fasteners
        • M2x5 Allen Hex Screw Package
        • M3x6 Allen Hex Screw Package
        • M3x8 Allen Hex Screw Package
        • M3 Hex Nut Package
  • Help
    • Manual
    • Shops
    • Reach Us
Powered by GitBook
On this page
  • Step 1: Hardware & Software Overview
  • Step 2: Assemble
  • Step 3: Run & Test
  • Codes
  1. SMD Applications
  2. Basics

Security System

PreviousSmart DoorbellNextDistance Buzzer Warning

Last updated 2 months ago

The Security System project is a simple yet useful real-life scenario application. It uses a , the and the to work like a geniune security system. The system is designed to be activated when there is a movement in designated area.

About Tools and Materials:

()

()

()

()

()

()

Step 1: Hardware & Software Overview

Project Key Components

  1. The SMD acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the and actuate the visual and audible warning signals.

  2. The measures the distance between the sensor and an object in its path. It provides distance data to the script for security monitoring.

  3. The serves as the audible warning. It emits sound when activated when there is an object in the designated area.

  4. The is used to provide visual warning. It can emit different colors and light intensities as programmed.

  5. The SMD library is at the heart of the application. It communicates with the SMD using a specific communication protocol, sending commands to read the and actuate the visual and audible warnings, the and the .

Project Key Features

  • Distance-based Security Monitoring

Step 2: Assemble

Getting Started

  1. Hardware Setup

    • Make sure that the SMD is powered and all connections are correct.

Project Wiring Diagram

Step 3: Run & Test

  1. Run the Application

    • Execute the script, initiating the Security System application.

  2. Customize Security Thresholds

    • Adjust the predetermined distance threshold in the script to customize the security monitoring levels.

    • Experiment with different colors and sound patterns for the LED and buzzer to suit specific security scenarios.

Codes

from serial.tools.list_ports import comports
from platform import system
from smd.red import *
import time

baudrate = 115200          # Baud rate of communication
ID = 0                     # ID of the SMD
buzzer_module_id = 5       # ID of the buzzer module
distance_sensor_id = 1     # ID of the ultrasonic distance sensor module
rgb_led_id = 5             # ID of the RGB LED module


def USB_Port():
    """
    Scans and identifies a compatible USB port for the current operating system.

    Returns:
        str: The detected USB port or None if no suitable port is found.
    """
    # Get a list of available ports
    ports = list(comports())
    
    # Known USB port names for different operating systems
    usb_names = {
        "Windows": ["USB Serial Port"],  # Names specific to Windows
        "Linux": ["/dev/ttyUSB"],        # Names specific to Linux
        "Darwin": [                      # Names specific to macOS
            "/dev/tty.usbserial",
            "/dev/tty.usbmodem",
            "/dev/tty.SLAB_USBtoUART",
            "/dev/tty.wchusbserial",
            "/dev/cu.usbserial",
        ]
    }

    # Detect the operating system
    os_name = system()
    print(f"Operating System: {os_name}")

    if ports:
        for port in ports:
            # Check if the port matches any known USB names
            if any(name in port.device or name in port.description for name in usb_names.get(os_name, [])):
                print(f"USB device detected on port: {port.device}")
                return port.device  # Return the first matching port
        # If no suitable port is found, print the list of available ports
        print("No suitable USB device found. Available ports:")
        for port in ports:
            print(f"Port: {port.device}, Description: {port.description}, HWID: {port.hwid}")
    else:
        print("No ports detected!")
    return None


try:
    # Find and initialize the USB port
    SerialPort = USB_Port()
    if not SerialPort:
        raise Exception("No compatible USB port found. Please check your connection.")

    # Initialize the SMD module
    master = Master(SerialPort, baudrate)       # Defines the USB gateway module
    master.attach(Red(ID))                      # Gives access to the SMD of specified ID
    master.scan_modules(ID)                     # Scans and identifies the modules connected to the SMD

    # Main loop
    while True:
        # Get distance data from the ultrasonic sensor
        distance = master.get_distance(ID, distance_sensor_id)  # Variable to store the distance data
        print(f"Distance: {distance} cm")                      # Print the value to observe

        if distance is not None:
            if distance < 15:
                # Activate the buzzer and set RGB LED to red
                master.set_buzzer(ID, buzzer_module_id, 600)          # Set buzzer frequency to 600 Hz
                master.set_rgb(ID, rgb_led_id, red=255, green=0, blue=0)  # Set LED to red
                time.sleep(0.5)                                       # Wait for half a second
                master.set_rgb(ID, rgb_led_id, red=0, green=0, blue=255)  # Change LED to blue
            else:
                # Deactivate the buzzer and turn off the RGB LED
                master.set_buzzer(ID, buzzer_module_id, 0)            # Turn off the buzzer
                master.set_rgb(ID, rgb_led_id, red=0, green=0, blue=0)  # Turn off the LED

        time.sleep(0.1)  # Delay for smooth operation

except Exception as e:
    print(f"Error: {e}")
#include <Acrome-SMD.h>

// Definitions
#define ID 0                   // ID of the SMD
#define BAUDRATE 115200         // Baud rate of communication
#define BUZZER_MODULE_ID 5      // ID of the buzzer module
#define DISTANCE_SENSOR_ID 1    // ID of the ultrasonic distance sensor module
#define RGB_LED_ID 5            // ID of the RGB LED module

Red master(ID, Serial, BAUDRATE);  // Defines the USB gateway module

void setup() {
    Serial.begin(BAUDRATE);  // Initialize serial communication
    master.begin();          // Start communication with the SMD
    master.scanModules();    // Scan and identify connected modules
}

void loop() {
    // Get distance data from the ultrasonic sensor
    int distance = master.getDistance(DISTANCE_SENSOR_ID);
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");

    if (distance > 0) {  // If a valid distance value is received
        if (distance < 15) {
            // Activate the buzzer and set RGB LED to red
            master.setBuzzer(BUZZER_MODULE_ID, 600);  // Set buzzer frequency to 600 Hz
            master.setRGB(RGB_LED_ID, 255, 0, 0);     // Set LED to red
            delay(500);  // Wait for half a second
            master.setRGB(RGB_LED_ID, 0, 0, 255);     // Change LED to blue
        } else {
            // Deactivate the buzzer and turn off the RGB LED
            master.setBuzzer(BUZZER_MODULE_ID, 0);
            master.setRGB(RGB_LED_ID, 0, 0, 0);
        }
    }

    delay(100);  // Delay for smooth operation
}

The Security System continuously monitors the distance measured by the . If the distance of the detected object is equal or closer than the determined distance value, the alert system will be activated.

Visual Feedback with the

The displays red and blue lights to indicate the security status. Red lights may represent an alert or danger, while blue lights indicate a normal or safe condition.

Audible Feedback with the

The emits a sound when the system detects a potential security threat, providing an audible alert to draw attention to the situation.

Connect the SMD to the PC or Arduino board using or .

Connect the , the and the to the SMD using an RJ-45 cable.

Observe the displaying colors and the emitting sound based on the detected distance.

Ultrasonic Distance Sensor Module
Buzzer Module
RGB LED Module
SMD Red
Purchase Here
SMD USB Gateway
Purchase Here
Arduino Gateway Module
Purchase Here
Ultrasonic Distance Sensor Module
Purchase Here
Buzzer Module
Purchase Here
RGB LED Module
Purchase Here
SMD
Ultrasonic Distance Sensor Module
Ultrasonic Distance Sensor Module
Ultrasonic Distance Sensor Module
Buzzer Module
Buzzer Module
RGB LED Module
RGB LED Module
SMD Libraries
Ultrasonic Distance Sensor Module
RGB LED Module
Buzzer Module
Ultrasonic Distance Sensor Module
RGB LED Module
RGB LED Module
Buzzer Module
Buzzer Module
USB Gateway Module
Arduino Gateway Module
Ultrasonic Distance Sensor Module
Buzzer Module
RGB LED Module
RGB LED Module
Buzzer Module