also, @UKHeliBob should i give it as
if (digitalRead(photo) == LOW && myservo.read( 380 ){
delay(500);
myservo.write( 0 );
closingdoor = 0;
}
DO NOT post pictures of code. Use code tags as advised.
What is it with writing 380 to the servo when the maximum sensible value is 180 ?
myservo.read( 380 )
Really ?
I suggest that you consult Servo - Arduino Reference
i am sorry i am new at this but can you please give me an example of what i need to write fro that if statement
for example would it be if (myservo.write(50)){
}
Start by not trying to send the servo to 380 degrees. Why are you using that value ?
The Servo library read() function returns the most recent value written to the servo. It does not take a parameter. If you want to know whether the servo was last commanded to go to a particular position then read it and compare it
if (myservo.read() == someValue)
{
//do something
}
but as I said some time ago this is not the best way to test whether the door is open or closed
thank you soo much you fixed my problem
I am glad it is fixed
Please post your working sketch
but the ldr thing is not working
the code is fine but the door is not locking sadly:(
Start by posting your code as it is now and describing what is wrong on more detail
ok will do
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
const int photo = 7;
#define SERVO_PIN 2
Servo myservo;
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 5 //define green LED pin
#define LED_R 4 //define red LED
#define BUZZER 3
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
pinMode(BUZZER, OUTPUT);
noTone(BUZZER);
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(photo, INPUT_PULLUP);
Serial.println("Arduino RFID door lock");
myservo.attach(SERVO_PIN);
opendoor();
}
void opendoor(){
tone(BUZZER, 800);
delay(50);
noTone(BUZZER);
delay(50);
tone(BUZZER, 800);
delay(50);
noTone(BUZZER);
delay(50);
tone(BUZZER, 800);
delay(50);
noTone(BUZZER);
delay(50);
tone(BUZZER, 800);
delay(50);
noTone(BUZZER);
delay(50);
myservo.write( 380 );
digitalWrite(LED_G, HIGH);
delay(5000);
}
void loop(){
digitalWrite(LED_R, HIGH);
//Look for new cards
if ( !mfrc522.PICC_IsNewCardPresent() ){
return;
}
//Select one of the cards
if ( !mfrc522.PICC_ReadCardSerial() ) {
return;
}
String content= "";
byte letter;
for( byte i = 0; i < mfrc522.uid.size; i++ ){
content.concat(String(mfrc522.uid.uidByte[i], HEX));
if( i < mfrc522.uid.size-1 ) content+="-";
}
content.toUpperCase();
Serial.println();
Serial.println("UID tag :'" + content + "'");
if( content == "D4-73-CA-2A" || "D7-75-2A-7B" || "97-15-35-7B" || "D7-2C-36-7B" || "F7-F4-29-7B" || "67-72-39-7B" || "D7-7A-2C-7B" || "27-17-27-7B" || "F7-DB-37-7B" ){
Serial.println("Authorized access");
delay(300);
opendoor();
}
if (digitalRead(photo) == LOW && myservo.read() == 380) {
delay(500);
myservo.write( 0 );
}
}
the 380 is working fine so i will leave it like that
the problem is the door is unlocking just fine but not vice versa
if ( content == "D4-73-CA-2A" || "D7-75-2A-7B" || "97-15-35-7B" || "D7-2C-36-7B" || "F7-F4-29-7B" || "67-72-39-7B" || "D7-7A-2C-7B" || "27-17-27-7B" || "F7-DB-37-7B" )
FIX THIS LINE !
Fix this line
IT IS WORKING FINE BUT NOT CLOSING. THIS IS NOT THE PROBLEM IT IS OPENING FINE!!
that line has nothing to do with the closing of the door!!
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.