Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Bluetooth-Controlled Servo Door Lock

View and Edit Project In Cirkit DesignerImage of Arduino UNO Bluetooth-Controlled Servo Door Lock

Circuit Documentation

Summary

The circuit in question is designed to control a servo motor via commands received from a Bluetooth module, with an Arduino UNO serving as the central microcontroller. The servo motor's position can be adjusted to open or close a door based on the received Bluetooth commands, which are authenticated with a predefined password.

Component List

Arduino UNO

Servo

HC-05 Bluetooth Module

Wiring Details

Arduino UNO

Servo

HC-05 Bluetooth Module

Documented Code

#include <Servo.h>

Servo myservo; 
String inputString = "";
String command = "";
String value = "";
String password = "arduPi"; 
boolean stringComplete = false; 

void setup(){
  Serial.begin(9600); 
  inputString.reserve(50); 
  command.reserve(50);
  value.reserve(50);
  boolean stringOK = false;
  myservo.attach(9); 
}

void loop(){
  if (stringComplete) { 
    delay(100); 
    int pos = inputString.indexOf('='); 
    if (pos > -1) {
      command = inputString.substring(0, pos); 
      value = inputString.substring(pos+1, inputString.length()-1); 
      
      if(!password.compareTo(value) && (command == "OPEN")){
        openDoor(); 
        Serial.println(" OPEN"); 
        delay(100);
      }
      else if(!password.compareTo(value) && (command == "CLOSE")){
        closeDoor();
        Serial.println(" CLOSE"); 
        delay(100);
      }
      else if(password.compareTo(value)){
        Serial.println(" WRONG");
        delay(100);
      } 
    } 
    inputString = "";
    stringComplete = false;
  }
}

void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read(); 
    inputString += inChar;
    if (inChar == '\n' || inChar == '\r') {
      stringComplete = true;
    } 
  }
}

void openDoor(){
  myservo.write(0); 
  delay(100); 
}

void closeDoor(){
  myservo.write(65);
  delay(100); 
}

Filename: sketch.ino

Description: This Arduino sketch is designed to receive commands via the HC-05 Bluetooth module. When a complete string is received, it checks if the command is "OPEN" or "CLOSE" and matches the password. If the authentication is successful, it triggers the openDoor or closeDoor function to move the servo to the respective position. If the password is incorrect, it prints "WRONG" to the serial monitor.