top of page

Arduino Bluetooth Door Lock

  • Alexa F.
  • May 3, 2018
  • 1 min read

SOURCE CODE:

//CREATED BY ROBOTIC NATION //https://www.youtube.com/channel/UCdNnHNkhaRYr-3nhQqY7_dw

#include <Servo.h> #define LED 13 //Define 13 pin for LED bool state = LOW; //The initial state of the function is defined as a low level char getstr; //Defines a function that receives the Bluetooth character int pos = 0; //create servo position variable Servo servo;

void setup() { pinMode(LED, OUTPUT); //set led to an output servo.attach(9); //attach servo to pin 9 Serial.begin(9600); //begin the serial monitor }

//Control LED sub function void stateChange() { state = !state; digitalWrite(LED, state); } //Tells servo to unlock void unlock(){ for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree servo.write(pos); // tell servo to go to position in variable 'pos' delay(15); digitalWrite(LED, HIGH); } } //Tells servo to lock void lock(){ for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees servo.write(pos); // tell servo to go to position in variable 'pos' delay(15); digitalWrite(LED, LOW); } } void loop() { //The Bluetooth serial port to receive the data in the function getstr = Serial.read(); if(getstr == 'a'){ stateChange(); } if(getstr == 'u'){ unlock(); Serial.write("Door is Unlocked"); } if(getstr == 'l'){ lock(); Serial.write("Door is Locked"); } }


 
 
 

2 Comments


Nexpulse7
Nexpulse7
5 days ago

Nexpulse7 is a results-driven digital marketing agency focused on helping businesses grow through data-backed strategies. We create campaigns that build strong online visibility, attract potential customers, and turn engagement into measurable business growth.

Like

Joe Hendry
Joe Hendry
Oct 03

Arduino Bluetooth door locks are such a smart DIY project! Perfect for Smart Home 2025, they show how automation can make homes safer, more connected, and future-ready with hands-on innovation.

Like
Single post: Blog_Single_Post_Widget

Address

Fanwood, NJ 07023, USA

Contact

©2017 by Robotic Nation. Proudly created with Wix.com

bottom of page