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
Components
1×
Grove EMG Detector
DigiKey Part Number 1597-1070-ND
1×
Relay Board PCB
3V Relay High Level Driver Module
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.
constint ledPin = 5; // Define pin 5 as the LED pinvoidsetup() {
pinMode(ledPin, OUTPUT); // Set pin 5 as an output
}
voidloop() {
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.
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) :
constint ledPin = 5; // Define pin 5 as the LED pinvoidsetup() {
pinMode(ledPin, OUTPUT); // Set pin 5 as an output
}
voidloop() {
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 timeconstint alpha = 10; // Smoothing factor for baselineconstint relayPin = 5; // Pin connected to the relayconstint threshold = 100; // Activation thresholdbool solenoidState = false; // Keeps track of solenoid statebool lastTrigger = false; // Prevents multiple toggles from noisevoidsetup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Start with relay OFF
}
voidloop() {
emgValue = analogRead(emgPin);
// Update baseline slowly (adaptive filtering)
baseline = (baseline * (alpha - 1) + emgValue) / alpha;
// Normalize: Shift signal relative to baselineint 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 thresholdif (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: