Arduino TFT Touchscreen Door Lock
by Darrenmagoo in Circuits > Arduino
7018 Views, 19 Favorites, 0 Comments
Arduino TFT Touchscreen Door Lock
This is my first Instructable. This project uses Arduino and a 2.8" TFT touchscreen with a password sketch to activate a relay that breaks the circuit to a mag lock door.
Background, the RFID lock on a door at work broke rather than rewiring the whole maglock system back to the buildings control box I added this touchscreen Arduino on top of the existing system.
I would like to thank KonstantinBG who's Topic: TFT Display Gate Opener Password got me 99% of the way to getting the Arduino sketch to work.
Parts
ONE: Arduino Mega: The TFT took up all the pin on an Uno so I used a mega for the extra pins to add the Solid state relay
Geekcreit® MEGA 2560 R3 ATmega2560 MEGA2560 Development Board
https://www.banggood.com/Mega2560-R3-ATmega2560-16..
TWO: 2.8 Inch TFT LCD Shield Touch Display Screen Module For Arduino
Geekcreit® 2.8 Inch TFT LCD Shield Touch Display Screen Module For Arduino
https://www.banggood.com/2_8-Inch-TFT-LCD-Shield-T...
THREE: SSR (had one on hand, but use any relay that is rated for the load you want to control in my case only 5v)
Opto 22 3 A Solid State Relay, DC, PCB Mount, 60 V dc Maximum Load
RS Stock No. 888-7619
https://ie.rs-online.com/web/p/solid-state-relays/...
FOUR: Blank 2 gang box to mount touchscreen onto the wall, and a blank faceplate
Double Dry Lining Box, 35mm
Product Code: 1139636
https://www.woodies.ie/double-dry-lining-box-35mm-...
FIVE: Extra long Arduino extension power cable, the nearest socket to power the Arduino and touchscreen was about 4M away in the roof.
kenable 5.5 x 2.1mm DC Power Plug to Socket CCTV Extension Lead Cable 5m
https://www.amazon.co.uk/dp/B003OSZQGI/ref=pe_3187...
SIX: standard 12V power supply for Arduino
CCTV Camera 12V 0.5A 500mA PSU 2.1mm DC Plug UK Power Supply
https://www.ebay.co.uk/itm/380502176581
Other parts:
- 3D printer (Ultimaker 2) to print the mounting for the Arduino Mega and TFT shield into the blank box, plus a printed bezel to cover the edge of the screen when mounted into the blank faceplate. I will attach the step file I created for this.
- Soldering iron and few connectors and cables etc.
- Hot Glue gun.
- Drill
- Coping saw
Hardware Assembly
The Base support has a groove on one of the legs so the solid state relay (SSR) sits underneath the Arduino mega. I hot glued the SSR onto the base.
A couple of screws to fix the mega onto base support.
The TFT shield sits on top of the mega.
I cut the blank faceplate using a drill and coping saw.
And test fitted it all together, thankfully I got my height correct for the base support so the screen protrudes just past the front of the blank faceplate. I will 3D print a bezel later to hide the rough edge left by the coping saw.
Space is quite tight inside the box so I'll have to cut the 12v power adapter I bought that plugs into the mega and solder it directly to the board to save room.
Electronics Assembly
To prototype this project out for bench testing I started with the 2.8" TFT touchscreen by itself first. You just line up the pins and push it into the Arduino mega plug it into your laptop and fire up the Arduino integrated development environment software.
This is my first touch screen project so it took a bit of tinkering to figure how to calibrate the screen size, touch sensitively etc, also the TFT is not an Adafruit touchscreen meant I had to add some extra library's such as MCUFRIEND_kbv to calibrate the screen etc.
There are much better resources out there than I can write on how to do this.
such as:
https://forum.arduino.cc/index.php?topic=366304.0
https://www.hackster.io/electropeak/ultimate-begin...
https://github.com/prenticedavid/MCUFRIEND_kbv
- I then got the num pad display on the 2.8" TFT touchscreen to report the values via the serial monitor
- Then added the password element to the sketch
- Next was the relay sketch by itself first. This took some soldering andf wiring of the relay to the Mega. Please see the wiring diagram of the relay attached. I used pin 39 on the digital I/O on the mega to trigger the solid state relay and then turn on/off my LED ( to be replaced by the mag locks exit button wiring when fitted).
I then butchered it up and Frankenstein'd it together. (The Sketch works for me but I am sure it can be improved)
Sketch
The hacked-together sketch.
- Import the library's as required.
- When first running the TFT touchscreen use the "TouchScreen_Calibr_native" sketch in the "MCUFIREND" library to get the results to fill in for.....
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
const int TS_LEFT=927,TS_RT=126,TS_TOP=70,TS_BOT=910;
Again i am sure this sketch can be improved overall but it worked for me
Downloads
Fitting Into Location
After I had the benchtop testing done with an LED acting as the stand-in for the mag lock. It was time to fit the system into its location. Luckily the walls are just plasterboard so after checking for pipes and cables I was able to cut out the hole for the box.
I chased the 12v power across the ceiling and dropped it down to the freshly cut hole. (the thicker black wire in the image) I then brought across the wires from the exit button inside the door (thinner black and red wires) this is the load for the Relay, so when the relay is turned on these wires activate the door release/exit button.
Next was fitting the Arduino with TFT Touchscreen and Relay to the box Soldering the power to the board and the load to the relay. Lastly, I enclosed it all with the white cover and the 3D printed black bezel was glued on top.
Check out the images and video.
Thanks
Darren