Unveiling the Art of Crafting Common Security Systems---Raspberry Pi Pico
by osoyooproduct in Circuits > Raspberry Pi
9 Views, 0 Favorites, 0 Comments
Unveiling the Art of Crafting Common Security Systems---Raspberry Pi Pico
In the labyrinth of modern life, security systems are our vigilant guardians. They stand silently, shielding us from unseen threats, and preserving our peace of mind. But have you ever wondered how these sentinels are created, what makes them tick, or felt the urge to delve into their inner workings? Today, we embark on an exciting journey, hand in hand, to construct a simple security system. Together, we'll unravel the principles that underpin these technological marvels.
Inquisitive Minds at Play:
Are you one of those inquisitive souls, forever pondering the secrets behind everyday technology? Well, you're not alone! In a world filled with gadgets and gizmos, curiosity is our guiding light. Today, we'll satiate that curiosity by building a security system from scratch.
Our DIY Security System:
This isn't your run-of-the-mill project. It's a hands-on exploration of how security systems operate in our lives. By crafting our security system, you'll gain profound insights into its core principles. Together, we'll dive into the intricate world of sensors, communication protocols, and data processing.
The Spark of Understanding:
Through this endeavor, you'll witness the birth of security right before your eyes. You'll grasp how sensors detect anomalies, how data is transmitted, and how alarms are triggered. As you assemble this system, you'll gain a newfound appreciation for the technology that safeguards our homes and businesses.
The Joy of Learning:
Building your security system isn't just a lesson in technology; it's an experience that fosters a deeper understanding of the world around us. It's an opportunity to quench your thirst for knowledge and satisfy your curiosity about the inner workings of everyday marvels.
Conclusion:
So, let's embark on this journey of discovery, hand in hand, and witness the magic of technology come to life. As we build our security system, we'll unlock the mysteries that keep us safe, and we'll revel in the joy of learning. Curiosity leads to understanding, and together, we'll explore the fascinating world of security systems.
Supplies
In the realm of security systems, RFID readers stand as a popular and integral component. They possess the ability to read RFID card IDs and transmit this data to a computer system. In this instructional guide, we embark on an exploration of the OSOYOO RFID reader, harnessing it to construct a straightforward security verification system. This RFID reader employs a novel communication protocol known as SPI (Serial Peripheral Interface) to relay data to the Raspberry Pi Pico. By the end of this tutorial, you will have gained insights into three distinct communication protocols: SPI, I2C, and Serial (RS232). It's important to note that these communication methods exhibit varying speeds, with SPI being the fastest, followed by I2C, and Serial trailing behind.
More detailed information see :https://osoyoo.com/2021/07/23/raspberry-pi-pico-learning-kit-lesson-7-using-spi-port-to-access-rfid-reader/#google_vignette
Please order Raspberry Pi Pico Learning Kit from: https://osoyoo.store/products/raspberry-pi-pico-python-hardware-programming-learning-kit
Prerequisites
Before commencing this project, ensure you have the following components at your disposal:
- Raspberry Pi Pico board with a microUSB cable.
- A computer equipped to run the Thonny Python IDE.
- A breadboard for assembling electronic components.
- Two LEDs.
- Two 220Ω resistors.
- A negative-enabled buzzer.
- One OSOYOO RFID reader.
- A set of jumper wires.
Connection Instructions
To construct the necessary circuit for this project, adhere to the following pin connections:
- Pico Pins to RFID Pins:
- GP5 -> SDA
- GP6 -> SCK
- GP7 -> MOSI
- GP4 -> MISO
- GP18 -> RST
- GND -> GND
- 3.3V -> 3.3V
- Pico Pins to Other Devices:
- GP14 -> Red LED through 220Ω resistor
- GP15 -> Green LED through 220Ω resistor
- GP16 -> Buzzer I/O pin
Please note that this configuration enables the Raspberry Pi Pico to interface effectively with the OSOYOO RFID reader.
Code Implementation
We will now proceed to run the Python code on the Raspberry Pi Pico. The code provided below includes comments for clarity:
import time
from machine import I2C, Pin, SPI
from mfrc522 import MFRC522
# Initialize pins and components
buzzer = Pin(16, Pin.OUT)
buzzer.value(1)
true = Pin(15, Pin.OUT)
false = Pin(14, Pin.OUT)
sck = Pin(6, Pin.OUT)
mosi = Pin(7, Pin.OUT)
miso = Pin(4, Pin.OUT)
sda = Pin(5, Pin.OUT)
rst = Pin(18, Pin.OUT)
spi = SPI(0, baudrate=100000, polarity=0, phase=0, sck=sck, mosi=mosi, miso=miso)
card1 = "0xe58a6223" # Change this value to match your testing RFID card 1
card2 = "0xf765bd60" # Change this value to match your testing RFID card 2
while True:
rdr = MFRC522(spi, sda, rst) # Initialize the RFID reader
(stat, tag_type) = rdr.request(rdr.REQIDL) # Read card ID
if stat == rdr.OK:
(stat, raw_uid) = rdr.anticoll()
if stat == rdr.OK:
uid = ("0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3]))
print(uid)
if uid == card1:
print("card 1 detected!")
buzzer.value(0)
time.sleep(0.3)
buzzer.value(1)
true.value(1)
time.sleep(1)
true.value(0)
time.sleep(1)
elif uid == card2:
print("card 2 detected!")
buzzer.value(0)
time.sleep(0.3)
buzzer.value(1)
time.sleep(0.3)
buzzer.value(0)
time.sleep(0.3)
buzzer.value(1)
true.value(1)
time.sleep(1)
true.value(0)
time.sleep(1)
else:
print("invalid card!")
buzzer.value(0)
time.sleep(2)
buzzer.value(1)
false.value(1)
time.sleep(0.1)
false.value(0)
time.sleep(0.1)
false.value(1)
time.sleep(0.1)
false.value(0)
time.sleep(0.1)
false.value(1)
time.sleep(0.1)
false.value(0)
time.sleep(1)
Running the Code
Follow these steps to run the code on your Raspberry Pi Pico:
- Connect your Pico board to a USB port on your PC.
- Open the Thonny Python IDE and select "MicroPython for Raspberry Pi Pico" as the interpreter.
- Choose the appropriate COM port to which your Pico board is connected.
- Click "OK" to save the settings.
Download and Load the Code:
- Download the code from this link, save it on your local PC, and unzip the file.
- You'll find two files: mfrc522.py and pico-lesson7.py. Open the mfrc522.py library file using Thonny.
Save the Library:
- Click "File" and then "Save as."
- Select "Raspberry Pi Pico" as the destination.
- Name the file as "mfrc522.py" and click "OK" to save.
Open and Run the Main Code:
- Open the file pico-lesson7.py using Thonny.
- Click the "Run" button (represented by a ► icon) to execute the Python code.
Working Rusult
Now, you can test the system with different RFID cards. The IDs of the cards will be displayed in the shell window, and the corresponding LEDs and buzzer will indicate the security verification status. Be sure to modify lines 14 and 15 with the IDs of your RFID cards for accurate testing.