i want some help me to delay the srevo motor and tern off the servo to change the angle manual ,
i working on lockdoor with servomotor and i want the angle of the servo change from 0 to 180 degree and delay 7sec and change the angle from 180 to 0 and when the angle 0 i want to move the servo manually ,
digitalWrite(LED_G, HIGH);
tone(BUZZER, 500);
delay(500);
noTone(BUZZER);
for (angle =0 ; angle <180; angle +=10)
{
myservo.write(angle); //servo start position
delay(150); //speed time to open
}
delay(7000);
for(angle = 180; angle>=0; angle -=10)
{
myservo.write(angle);
delay(150); // speed time to close
}
digitalWrite(LED_G, LOW);
please help me
this is my code :
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLB8_djuKD"
#define BLYNK_DEVICE_NAME "SMART LOCK"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
const char* ssid = "snap: pxx.7"; // your network SSID (name)
const char* password = "55443322"; // your network key
#define SS_PIN 4
#define RST_PIN 5
#define LED_G 16 //define green LED pin
#define LED_R 0 //define red LED
#define BUZZER 15 //buzzer pin
#define SERVO_PIN 2
Servo myservo;
#define ACCESS_DELAY 2000
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int angle =0;
int fflag = 0;
int eflag = 0;
int jflag = 0;
#include "BlynkEdgent.h"
void Open()
{
digitalWrite(LED_G, HIGH);
tone(BUZZER, 500);
delay(500);
noTone(BUZZER);
for (angle =0 ; angle <180; angle +=10)
{
myservo.write(angle); //servo start position
delay(150); //speed time to open
}
delay(7000);
for(angle = 180; angle>=0; angle -=10)
{
myservo.write(angle);
delay(150); // speed time to close
}
digitalWrite(LED_G, LOW);
}
void NotAuthorized()
{
Serial.println(" Not Authorized to Enter ");
digitalWrite(LED_R, HIGH);
tone(BUZZER, 300);
delay(1500);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
delay(DENIED_DELAY);
}
void setup()
{
Serial.begin(115200);
delay(100);
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
myservo.attach(SERVO_PIN);
myservo.write( 0 );
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
digitalWrite(LED_R, LOW);
digitalWrite(LED_G, LOW);
pinMode(BUZZER, OUTPUT);
noTone(BUZZER);
Serial.println("Put your card to the reader...");
Serial.println();
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
BlynkEdgent.begin();
}
void loop() {
//________________________if there is NO internet_____________________
// attempt to connect to Wifi network:
while ( WiFi.status() != WL_CONNECTED) {
// Look for new cards
if ( (! mfrc522.PICC_IsNewCardPresent()) )
{
return;
}
// Select one of the cards
if ( (! mfrc522.PICC_ReadCardSerial()))
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if ( (content.substring(1) == "E9 CB BC B2")) //change here the UID of the card
{
Serial.println("Authorized access");
Serial.println("Abdulrahman_201712803");
Serial.println();
Open();
}
else {
NotAuthorized();
}
// wait 10 seconds for connection:
delay(1000);
}
//________________________if there is internet_____________________
while ( WiFi.status() == WL_CONNECTED) {
// once you are connected :
BlynkEdgent.run();
// check the network status connection once every 1 seconds:
delay(1000);
// Look for new cards
if ( (! mfrc522.PICC_IsNewCardPresent()) )
{
return;
}
// Select one of the cards
if ( (! mfrc522.PICC_ReadCardSerial()))
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
//change here the ( Student's )UID of the card_______________________________________________
if ( ( (content.substring(1) == "E9 CB BC B2") || //the first card for Abdulrahman_201712803
(content.substring(1) == "C9 F4 CA BB") //the second card for Ibrahim_201716556
)&& (fflag== 1))
{
//the first card
if ( (content.substring(1) == "E9 CB BC B2") && (fflag== 1)){
Serial.println("The student Enter:");
Serial.println("Abdulrahman_201712803");
Blynk.virtualWrite(V2, "The student Enter:" );
Blynk.virtualWrite(V2, "Abdulrahman_201712803" );
}
// the second card
else if ( (content.substring(1) == "C9 F4 CA B1") && (fflag== 1)){
Serial.println("The student Enter:");
Serial.println("Ibrahim_201716556");
Blynk.virtualWrite(V2, "The student Enter:" );
Blynk.virtualWrite(V2, "Ibrahim_201716556" );
}
Serial.println();
// here we want from you do the change please____
digitalWrite(LED_G, HIGH);
tone(BUZZER, 500);
delay(500);
noTone(BUZZER);
for (angle =0 ; angle <180; angle +=10)
{
myservo.write(angle); //servo start position
delay(150); //speed time to open
}
delay(7000);
for(angle = 180; angle>=0; angle -=10)
{
myservo.write(angle);
delay(150); // speed time to close
}
digitalWrite(LED_G, LOW);
//until here
}
//change here the ( Doctors's )UID of the card_______________________________________________
else if ( ((content.substring(1) == "C9 F4 CA B2")|| //the first card
(content.substring(1) == "C9 F4 CA B1") //the second card
)&& (eflag== 1))
{
//the first card
if ( (content.substring(1) == "C9 F4 CA B2") && (eflag== 1)){
Serial.println("The Doctor Enter:");
Serial.println("Dr.Abdullah Albaker");
Blynk.virtualWrite(V2, "The Doctor Enter:" );
Blynk.virtualWrite(V2, "Dr.Abdullah Albaker" );
}
//the second card
else if ( (content.substring(1) == "C9 F4 CA B1") && (eflag== 1)){
Serial.println("The Doctor Enter:");
Serial.println("Dr.Abdulaziz almalaq");
Blynk.virtualWrite(V2, "The Doctor Enter:" );
Blynk.virtualWrite(V2, "Dr.Abdulaziz almalaq" );
}
Serial.println();
Open();
}
//change here the ( Head of Department )UID of the card_______________________________________________
else if ( (content.substring(1) == "C9 F4 CA CC") ) //change here the UID of the card
{
Serial.println("Head of Department Enter");
Serial.println("Dr.Ahmad saud");
Blynk.virtualWrite(V2, "Head of Department Enter" );
Blynk.virtualWrite(V2, "Dr.Ahmad saud" );
Serial.println();
Open();
}
else {
Blynk.virtualWrite(V2, "Some one (Not authorized) try to Enter" );
NotAuthorized();
}
delay(1000);
}
}
BLYNK_CONNECTED(){
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
Blynk.syncVirtual(V2);
}
BLYNK_WRITE(V3)
{
fflag = param.asInt(); // assigning incoming value from pin V3 to a variable
}
BLYNK_WRITE(V4)
{
eflag = param.asInt(); // assigning incoming value from pin V4 to a variable
}