How to make Bluetooth Controlled Door Lock with Arduino using Mobile

 







Click here and download App 

             CODE 
#include <Servo.h>



Servo myServo;  // create servo object

char data;



void setup() {

  Serial.begin(9600);

  myServo.attach(9);  // attach servo to pin 9

}



void loop() {

  if (Serial.available() > 0) {

    data = Serial.read();



    if (data == 'a') {

      // Rotate from 0° to 150°

      for (int pos = 150; pos >= 0; pos--) {

        myServo.write(pos);

        delay(10); // delay for smooth movement

      }

    }

    else if (data == 'b') {

      // Rotate from 150° to 0°

      for (int pos = 0; pos <= 150; pos++) {

        myServo.write(pos);

        delay(10); // delay for smooth movement

      }

    }

  }

}

Post a Comment

Previous Post Next Post

Contact Form