IoT Door Access: Control a 12V Solenoid Lock via Arduino IoT Cloud & Uno R4 WiFi
Build a remote smart lock system with the Arduino Uno R4 WiFi to revolutionize home security! By connecting a 5V relay module and a 12V solenoid door lock to the Arduino IoT Cloud, this project enables you to use the Arduino IoT Remote mobile app to unlock your door from any location.

Components Used
- : Arduino Uno R4 WiFi
- 12V DC Solenoid Door Lock
- 5V Single-Channel Relay Module
- 12V 2A DC Power Adapter

Circuit Wiring & Schematic Description
| Arduino Uno R4 WiFi | 5V Relay Module | 12V Solenoid Lock | 12V Power Supply |
| 5V Pin | VCC | ||
| GND | GND | ||
| Pin 13 | IN (Signal) | ||
| COM | (+) | ||
| (-) | (-) | ||
| NO | (+) |

Arduino IoT Cloud & Mobile App Setup
First, go to Arduino IoT Cloud, create an account, and then log in to create a project and configure it
Create a Thing in Arduino IoT Cloud

After creating a thing, click “Add variable.”

Give a name to the variable, and you can also change the name of the Thing, and then click on Create.

Add a Device in Arduino IoT Cloud
Click on “Devices” and then click on “New device.”

After your board is detected by Arduino IoT Cloud, click on “Continue” to configure the microcontroller

You can edit the name of your device in the device configuration

Pick your network,, provide its name and its password, click Connect, and then move to cloud provisioning

Configure Web & Mobile Dashboard
On the left of the Arduino IoT Cloud, click on “Dashboards,’ and then click on “CREATE DASHBOARD.”

Then, on the Create Dashboard, click Edit to edit the Dashboard

On the Dashboard, add a widget to the dashboard; in our case, it will be a switch widget

You can change the name of your dashboard

Then link the variable “door” that you have created to the Switch widget so you can control the door remotely.

You can now control your door.

Required Libraries
ArduinoIoTCloud library
Connects the board to the Arduino IoT Cloud infrastructure

Arduino_ConnectionHandler library
Manages Wi-Fi connections for ESP32 and Renesas UNOR4 boards

Arduino Code
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/4df59d31-99c1-4073-aa81-dc4f7ad20c93
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
bool doorState;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#define door 13
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(door, OUTPUT);
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since DoorState is READ_WRITE variable, onDoorStateChange() is
executed every time a new value is received from IoT Cloud.
*/
void onDoorStateChange() {
// Add your code here to act upon DoorState change
if(doorState == 1){
digitalWrite(door, 1);
} else {
digitalWrite(door, 0);
}
}
How it works
GPIO 13 sends a LOW signal to maintain the 5V relay module in its resting state while the solenoid lock is OFF (doorState == 0). The 12V power supply circuit is totally broken since the internal contact between the relay’s Common (COM) and Normally Open (NO) terminals is still severed. Its internal heavy-duty spring pulls the metal latch forward into the door frame when no electrical power reaches the solenoid, keeping the door safely locked.


The Arduino Uno R4 WiFi drives GPIO 13 HIGH to activate the relay coil when you toggle the switch to ON (doorState == 1) in the mobile app. The circuit is closed and 12V from the external power source is dumped straight into the lock coil when the relay contact is magnetically pulled shut. The metal plunger inside the housing is instantly retracted by the generated electromagnetic field, which overcomes the spring tension and permits the door to swing open.


