Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security NachrichtenObservability should start with business outcomes, not infrastructure(22.09.2026 um 11:00 Uhr)
Sicherheitslücken (CVE)CISA orders feds to patch Zyxel flaw exploited for data theft(22.09.2026 um 10:53 Uhr)
AI & KI NachrichtenDeutscher KI-Markt legt 2026 um fast 50 % zu(22.09.2026 um 10:59 Uhr)
AI & KI NachrichtenKI-Regulierung in Deutschland: Grüne sehen deutliche Defizite(22.09.2026 um 11:04 Uhr)
IT Security NachrichtenKMU von Cyber-Attacken besonders gebeutelt - Versicherungsmagazin.de(22.09.2026 um 01:04 Uhr)
IT Security NachrichtenObservability should start with business outcomes, not infrastructure(22.09.2026 um 11:00 Uhr)
Sicherheitslücken (CVE)CISA orders feds to patch Zyxel flaw exploited for data theft(22.09.2026 um 10:53 Uhr)
AI & KI NachrichtenDeutscher KI-Markt legt 2026 um fast 50 % zu(22.09.2026 um 10:59 Uhr)
AI & KI NachrichtenKI-Regulierung in Deutschland: Grüne sehen deutliche Defizite(22.09.2026 um 11:04 Uhr)
IT Security NachrichtenKMU von Cyber-Attacken besonders gebeutelt - Versicherungsmagazin.de(22.09.2026 um 01:04 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

🔐 Control a Solenoid Lock with Arduino Mega (Using a Relay & Push Button)

Introduction Welcome back, makers! 👋 If you enjoyed building Wi-Fi-controlled LEDs, let’s take things a step further into the world of physical security. Today, we’re working with solenoid locks — the same mechanism used in lockers, cabin…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




Introduction



Welcome back, makers! 👋

If you enjoyed building Wi-Fi-controlled LEDs, let’s take things a step further into the world of physical security. Today, we’re working with solenoid locks — the same mechanism used in lockers, cabinets, and access-control systems.



In this project, you’ll learn how to lock and unlock a solenoid lock using:




  1. 1. Arduino Mega

  2. 2. A relay module

  3. 3. 12V power supply

  4. 4. Simple push button

  5. Breadboard

  6. Jumper wires(male to male and male to female)




  • By the end, you’ll push a button → the solenoid will pull → the lock will OPEN.

  • Push the button again → the solenoid releases → the lock goes back to LOCKED.



Let’s dive in!





🧰 What You’ll Need











































Component Image Description
Arduino Mega Arduino Mega Microcontroller to read button and control relay
12V Solenoid Lock Solenoid Lock The physical locking mechanism
Relay Module (5V Control) Relay Module Acts as a switch to send 12V to the solenoid
12V Power Adapter 12V Adapter Powers the solenoid and Arduino
Push Button Push Button Triggers lock/unlock
Breadboard & Jumper Wires Breadboard For easy wiring




⚡ Step 1: Wiring Diagram



Here’s the wiring logic broken down clearly:



🔘 Button to Arduino























Component Arduino Pin Purpose
Button Lead 1 D2 Reads button press
Button Lead 2 GND Completes button circuit


🔁 Relay Module to Arduino




























Component Arduino Pin Purpose
VCC 5V Powers relay coil
GND GND Ground
IN D8 Arduino signal to toggle solenoid


🔌 Power + Solenoid Connection

































Component Connected To Purpose
12V Adapter Arduino Barrel Jack Powers Arduino and relay
12V Adapter + (Positive) Relay COM 12V source for switching
Solenoid Red Wire Relay NO Receives switched 12V
Solenoid Blue Wire GND Completes 12V circuit


💡 We use the relay because the solenoid draws more current than Arduino can provide.





💻 Step 2: Write the Code



Open your Arduino IDE and paste the following code:




// Define the pins used
const int buttonPin = 2;
const int relayPin = 8;

bool isLocked = true;

void setup() {
pinMode(relayPin, OUTPUT);
// Use INPUT_PULLUP for simpler button wiring
pinMode(buttonPin, INPUT_PULLUP);

// SET INITIAL STATE: LOCK the door (Solenoid needs POWER ON to be locked)
digitalWrite(relayPin, HIGH);
}

void loop() {
// Read the button state (it reads LOW when pressed)
int buttonState = digitalRead(buttonPin);

if (buttonState == LOW) { // Button pressed
delay(50); // Debounce
if (digitalRead(buttonPin) == LOW) {
isLocked = !isLocked; // Toggle the state

if (isLocked) {
// LOCK: Solenoid ON (Power applied)
digitalWrite(relayPin, HIGH);
} else {
// UNLOCK: Solenoid OFF (Power removed)
digitalWrite(relayPin, LOW);
}

// Wait for the button to be released
while(digitalRead(buttonPin) == LOW){
// Do nothing
}
}
}
}









🧠 Explanation




  • The button uses INPUT_PULLUP, meaning:


    • Released → HIGH

    • Pressed → LOW






  • When pressed, Arduino sets relay HIGH → relay sends 12V to solenoid → it unlocks.


  • When pushed again → relay turns OFF → the solenoid locks again.







🧪 Step 3: Test the Setup




  1. Power the Arduino using your 12V adapter.

  2. Open the Serial Monitor — you should see "Solenoid Lock System Ready".

  3. Press the button:


    • You should hear a click from the relay.

    • Solenoid retracts (unlock).



  4. Press the button again:


    • Solenoid extends (lock).





🔐⚡ If everything is wired correctly — congratulations, you’ve built your own electromechanical locking system!



Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 🔐 Control a Solenoid Lock with Arduino Mega (Using a Relay & Push Button)

Thematisch verwandte Begriffe: Control, Solenoid, Lock, with · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94426 | A vulnerability was determined in xuxueli xxl-job up to 3.5.0. The impac…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick