Close
0%
0%

Muscle Reading Portable Lock

Bolt lock solenoid mechanism is connected to Arduino then activated with muscle data from EMG sensor

Similar projects worth following
The solenoid lock mechanism is a bolt lock door stopper that is attached to the bottom of the door for portability. The solenoid, when triggered, will come down onto the floor and work as a door stopper. Here, the lock is attached to the door using clamping mechanism that goes underneath the usual door gap and is connected to the other side. (This is only protoype lock that works on inward opening door but can still be detached through the other side, future projects will address this problem)
Using the EMG sensor and an arduino it should be possible to connect this to the lock mechanism and trigger activation with whenever a muscle is activated
  • 1 × Grove EMG Detector DigiKey Part Number 1597-1070-ND
  • 1 × Relay Board PCB 3V Relay High Level Driver Module
  • 1 × Arduino Arduino UNO R4 WiFi
  • 1 × Solenoid Medium Push/Pull 5V

  • Motor Driver -> Relay Transition

    laurent.andrea03/18/2025 at 21:35 0 comments

    Since it seemed like the Motor Driver was creating too much resistance and making the solenoid receive too little power instead I switched to using the following relay. 

    Here on one side is the Loading interface which connects to the solenoid, and on the other side is the Power interface which connects to the Arduino. I wasn't really sure whether the solenoid power supply should be connected to NO or NC, so I tried out both with some simple code to check it would trigger every 5 seconds. 

    const int ledPin = 5; // Define pin 5 as the LED pin
    
    void setup() {
        pinMode(ledPin, OUTPUT); // Set pin 5 as an output
    }
    
    void loop() {
        digitalWrite(ledPin, HIGH); // Turn LED on
        delay(5000); // Wait for 5 seconds
        digitalWrite(ledPin, LOW); // Turn LED off
        delay(5000); // Wait for 5 seconds
    }

    Using NC would not allow the solenoid to be triggered, which for some reason I would assume it was the opposite since I thought that it was supposed to be usually closed only to open after receiving input from Pin 5. However, the relay only solenoid only worked when the relay was connected to NO. The Arduino side was connected to VCC 3V since the 5V pin had a metal pin stuck inside and couldn't be used. 

View project log

  • 1
    Step 1: Connect Arduino to Solenoid

    Using the relay description below, the relay is connected to the Arduino and the solenoid. 

    The loading interface is connected to the solenoid with COM connection going to GND of solenoid and GND or solenoid power supply (5V). In this case we use NO so that the relay is normally open and can pass on the information from the arduino. This is seen below.

  • 2
    Step 2: Connect Relay to Arduino

    Now the power interface, is connected to the Arduino. In this case the right side goes to the Arduino connection with GND-Arduino GND, VCC-5V, and In-Pin 5

    This will power the relay and will be used to relay information from Pin 5 to control the loading interface. 

    Once it is connected, the Arduino should be connected through USB-C port to computer and the following code should be uploaded (This will test the solenoid and trigger it every 5 sec) :

    const int ledPin = 5; // Define pin 5 as the LED pin
    
    void setup() {
        pinMode(ledPin, OUTPUT); // Set pin 5 as an output
    }
    
    void loop() {
        digitalWrite(ledPin, HIGH); // Turn LED on
        delay(5000); // Wait for 5 seconds
        digitalWrite(ledPin, LOW); // Turn LED off
        delay(5000); // Wait for 5 seconds
    }

    The solenoid should successfully trigger if the solenoid power supply is around 5V. If it is having trouble moving, you may need a bigger power supply..

  • 3
    Step 3: Connect Arudino to EMG Sensor

    The EMG sensor comes with a cable that has 4 different connections:

    - GNDA

    - VCC

    - NC

    - VOUT

    In here only the GND, VCC, and VOUT connections are used with GND-Arduino GND, VCC-5V, and VOUT-Pin A0. 

    Once these are connected, upload the following code, this code has already created a threshold for how to detect muscle movement and reducing some noise.

    int emgPin = A0;
    int emgValue = 0;
    int baseline = 330; // Initial guess, updates over time
    const int alpha = 10; // Smoothing factor for baseline
    const int relayPin = 5; // Pin connected to the relay
    const int threshold = 100; // Activation threshold
    bool solenoidState = false; // Keeps track of solenoid state
    bool lastTrigger = false;   // Prevents multiple toggles from noise
    
    void setup() {
      Serial.begin(9600);
      pinMode(relayPin, OUTPUT);
      digitalWrite(relayPin, LOW); // Start with relay OFF
    }
    
    void loop() {
      emgValue = analogRead(emgPin);
    
      // Update baseline slowly (adaptive filtering)
      baseline = (baseline * (alpha - 1) + emgValue) / alpha;
    
      // Normalize: Shift signal relative to baseline
      int normalizedValue = emgValue - baseline;
    
      // Detect when signal **crosses threshold from below** (rising edge)
      if (normalizedValue > threshold && !lastTrigger) {
        solenoidState = !solenoidState; // Toggle state
        digitalWrite(relayPin, solenoidState ? HIGH : LOW);
        lastTrigger = true; // Prevent multiple triggers from noise
      }
    
      // Reset lastTrigger when signal goes back below threshold
      if (normalizedValue < threshold - 50) { 
        lastTrigger = false;
      }
    
      // Print normalized value for Serial Plotter
      Serial.print("-200"); Serial.print(",");
      Serial.print("200"); Serial.print(",");
      Serial.println(normalizedValue);
    
      delay(200); // Slow down updates for smoother plotting
    }

    This code also has a toggle state so that the solenoid will remain either locked or unlocked unless muscle movement is shown again rather than immediately unlocking after the initial muscle movement activity is finished. Once the EMG sensor is connected, the electrodes should be placed on the arm, making sure that the reference electrode is on a more static muscle. Below is the video of the solenoid being triggered: 

    https://drive.google.com/file/d/1NAdGZYV3zY0vhmNM1JgDnYkp98jSdAp3/view?usp=sharing

View all 5 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates