I need help with my code. I am making an rfid door lock.
when the card is placed the door opens and a laser shines off an ldr.
when the door closes the laser shines on the ldr/ photoresistor again and the servo locks the door
the funtion i want to wright is that when the ldr's output is low and the servo is in the 380 degree position the door should lock
i need help this is what i have done so far
but it is not valid
looking at your code, I assume that you need more experience. Please handle just servo motor separately. Try to learn how to drive stepper motor alone. do the same thing with LDR. You can combine the learning into one project later.
You can test the last position that you wrote to a servo using servo.read() function but you would be better off having a variable holding the state of the door. A boolean variable named doorOpen could have a value of true or false and you can set it to false when you open or close the door so that you can test it elsewhere in the sketch
I still don't get why you were trying to test for a value of 380 when the servo can never go to position 380
As usual, if you were to post your complete sketch it would help
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 + "'");
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 + "'");
everything works fine but it is not doing what i want it to do
it is opening, the buzzer is ringing, everything is fine, but it is not closing when the laser comes in contact with the ldr.