this project was my attempt to automate my door lock using a particle photo L298N and motor driver in a DC motor. The goal wasn’t to replace the lock entirely as this is not a permanent project. I just wanted the motor to turn the turn knob automatically through a coupler, which is triggered from an iOS shortcut. It was a simple idea, but turned into a great learning experience about power connections, and problem solving when things don’t go how you expect.
MotivationRecently my key would keep getting stuck in my lock or it won’t properly twist my lock open. I wanted to build that something to unlock or lock my door remotely through my phone. Additionally, most smart locks are very expensive so I thought, “Why not try to make my own cheaper version?“
Build processI started off by wiring the particle photon and the L298N and motor driver together. The L298N motor driver was connected to the Photon using jumper wires: IN1 to D2, IN2 to D3, and the ENA pin to D4 which controlled the motors direction and speed. Additionally, output 1 is connected to motor wire one and output 2 is connected to motor wire 2. Once that was done, I moved on to writing my code on Particle web IDE. I created two simple functions one that will unlock my door and one to lock it which I could later trigger using my phone.
int lockdoor(String Command){
digitalWrite(ena,HIGH);
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
delay(3000);
digitalWrite(in1,LOW);
digitalWrite(ena,LOW);
return 1;
}
int unlockdoor(String Command){
digitalWrite(ena,HIGH);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
delay(3000);
digitalWrite(in2,LOW);
digitalWrite(ena,LOW);
return 1;
}Mounting the motor to the door was probably the most challenging part. I attached the coupler (3mm to 6mm) to the motor shaft (3mm), and then tried connecting it to the lock spindle. The fit for the coupler to the lock spindle wasn’t perfect. The coupler was just a bit too small, but with some adjusting (I go deeper into this in the struggles section), I managed to make it secure enough for testing. Once the hardware was ready, I set up iOS shortcuts that used web hooks to send lock and unlock commands to my Photon. To set up the iOS shortcut, click the plus on the top right of your screen. Then search up "Get contents of" which you will then add your url similar to this, "https://api.particle.io/v1/devices/deviceid/expected string command." Switch your method to post and your request body to form. Add a new field, in the key spot add "access_token" and in the text spot add your access token.
At first, I powered everything from the Photons USB port (5v), but the spindle wouldn’t turn to unlock my door so I decided to up the power. I assumed the DC motor required more torque so I switched to a 12 V power supply. I also had to switch my wiring to accommodate the new voltage, but even in doing so I still made a mistake along this process that fried the electrical components of my Photon. I had to replace the broken Photon with a new one and go back to using 5 V. Due to this, I wasn’t able to finish the project, but I still believe this is doable.
Challengesmy biggest challenges were power issues and fitting a coupler. Couplers have two sides that could be different lengths so I had to order one with a 3MM side for the motor shaft and another side matching the spindles diameter. My PCL teacher Mr. law advised me to use a digital caliber but since I didn’t have one and the one at school had no battery, I had to use a ruler instead because of the error of a ruler to find diameter, I think my measurements were off by about 0.1 MM. When I tried to attaching the coupler to the spindle it wouldn’t fit, and with not enough time to order a new one, I had find another way to make it work.
I carefully used a Drill to widen the couplers hole to match the spindle size, then used sandpaper for smoothing and adjustments. After sometime I was finally able to fit the coupler onto the spindle.
Another problem I ran into was poor power efficiency. The motor wasn’t strong enough to turn the spindle at just 5 V and the motor, so I tried to rewire everything to give 12 V to the motor without sending that voltage to the particle photon. I didn’t get it right, and the Photon ended up getting fried.









Comments