Example Code for Arduino-Electric Solenoid Lock Control

Last revision 2025/12/17

This project demonstrates how to control the FIT0620 Electric Solenoid Lock using an Arduino board (DFRduino UNO) with a digital relay module. Users will learn how to wire the lock, control it via the relay, and monitor the lock status using the feedback signal.

Hardware Preparation

  • DFRduino UNO x1
  • Electric solenoid lock x1
  • 12V Power adapter x1
  • Digital relay module (Arduino compatible) x1
  • Dupont wires x n

Software Preparation

Wiring Diagram

Control the electric solenoid lock via a digital relay and 12V power adapter. Then the feedback wire will pass the lock status to the board DFRduino UNO.

Num Label Description
1 Signal Wire Signal ON/OFF
2 GND -
3 VCC +
4 Ground the black wire, connect the green wire to D6
FIT0620 Electric Solenoid Lock Connection Diagram

Other Preparation Work

Install Arduino IED software, open its compiling environment and upload the following codes.

Sample Code

* **************************************************** 
* @brief Electric Solenoid Lock

 * @copyright	[DFRobot](https://www.dfrobot.com), 2016
 * @copyright	GNU Lesser General Public License

* @author [Xiaoyu]([email protected])
* @version  V1.0
* @date  2019-03-11
  
* GNU Lesser General Public License.
* All above must be included in any redistribution
* ****************************************************/
int Relay = 4;    

void setup() {
  Serial.begin(57600);   
  pinMode(6, INPUT_PULLUP);         //Set Pin6 as output    
  pinMode(Relay, OUTPUT);     
} 
void loop() {
  int singal=digitalRead(6);
  Serial.println(singal);           
  digitalWrite(Relay, HIGH);           
  delay(2000);
  digitalWrite(Relay, LOW);             
  delay(2000);
   
} 

Result

The electric solenoid lock is unlocking in every 4s. In Arduino serial monitor, the output is 0 when unlocked and 1 when locked.

Was this article helpful?

TOP