ARDUINO IOT DOOR LOCK (ALEXA ENABLED)

#include "thingProperties.h"
#include <Servo.h>
Servo myservo; 
void setup() {
  myservo.attach(2);
  // 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();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  
}

/*
  Since Doorlock is READ_WRITE variable, onDoorlockChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onDoorlockChange()  {
  if(doorlock == 1)
  {
    int pos;

   for (pos = 0; pos <= 180; pos += 1) 
    
   myservo.write(pos);         
  }
  
  else
  
  {
    int pos;
    for (pos = 180; pos >= 0; pos -= 1) 
    myservo.write(pos);   
    
  }
  
}

Leave a comment

Design a site like this with WordPress.com
Get started