Servo programming-Please answer,i am new

Hello to everyone! I am new and i am trying to make a rfid lock
Rfid and servo works but separately(not in the same sketch.
Sorry for my bad english
Servo:MG90S
Rfid:RC522
I am using arduino leonardo
I am powering the servo with a driver
I am getting that when i scan the rfid card,but servo does nothing:
54493fc
open_lock
54493fc
open_lock

/*
 * ----------------------------------------------------------------------------
 * This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 * 
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 * 
 * This sketch show a simple locking mechanism using the RC522 RFID module.
 * ----------------------------------------------------------------------------
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          10          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

String read_rfid;
String ok_rfid_1="A537EB54";
String ok_rfid_2="165FCE5E";
String ok_rfid_3="067AC65E";
String ok_rfid_4="544903FC";
String ok_rfid_5="454CF054";
//String ok_rfid_2=""; //add as many as you need.
int lock=7; //Led positive wich will light if rfid tag is OK 

//Use the lines below if you plan on using a servo as a locking mechanism.
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
int posClosed = 100;    // variable to store the servo position for locked
int posOpen = 7;    //same for open...
 

/*
 * Initialize.
 */
void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card

    //Choose which lock below:
    myservo.attach(2);  // attaches the servo on pin 2 to the servo object 
}

/*
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
    read_rfid="";
    for (byte i = 0; i < bufferSize; i++) {
        read_rfid=read_rfid + String(buffer[i], HEX);
    }
}

void open_lock() {
  //Use this routine when working with Servos.
  myservo.write(7); 
  delay(2000);
  myservo.write(100);
}

void loop() {

      // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
        return;

    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
    Serial.println(read_rfid);
    Serial.println("open_lock");
    if (read_rfid==ok_rfid_1) {
      //ok, open the door.
      open_lock();
    }
    if (read_rfid==ok_rfid_2) {
      //ok, open the door.
      open_lock();
    }
    if (read_rfid==ok_rfid_3) {
      //ok, open the door.
      open_lock();
    }
    if (read_rfid==ok_rfid_4) {
      //ok, open the door.
      open_lock();
    }
    if (read_rfid==ok_rfid_5) {
      //ok, open the door.
      open_lock();
    }
    //Add below as many "keys" as you want
    //if (read_rfid==ok_rfid_2) {
      //also ok, open the door
    //  open_lock();
    //}
    // else not needed. Anything else is not ok, and will not open the door...
}

The code you improperly posted does something. You failed to describe what it actually does. It's hard to help you make the code do what you want without knowing how what it does differs from what you want.

Is it calling open_lock()? Perhaps stick a serial print inside it to prove it’s getting called.

i don't know to code,in this moment i just want to know what to do.
i can see that the rfid module scans the cards,but the servo is doing nothing.
i don't know why..

i don't know why..

And, you don't really seem to be interested in learning why.

It is not at all difficult to add

   Serial.print("ope_lock called");

somewhere in your code.

It is not at all difficult to figure out the appropriate place.

PaulS:
And, you don’t really seem to be interested in learning why.

It is not at all difficult to add

   Serial.print("ope_lock called");

somewhere in your code.

It is not at all difficult to figure out the appropriate place.

i tried and Arduino: 1.8.0 (Windows 8.1), Board: “Arduino Leonardo”

C:\Users\cristian\Documents\Arduino\rfid_finish\rfid_finish.ino: In function ‘void loop()’:

rfid_finish:89: error: call of overloaded ‘print(void (&)())’ is ambiguous

Serial.print(open_lock);

^

C:\Users\cristian\Documents\Arduino\rfid_finish\rfid_finish.ino:89:27: note: candidates are:

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232,

from sketch\rfid_finish.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:61:12: note: size_t Print::print(char)

size_t print(char);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:61:12: note: no known conversion for argument 1 from ‘void()’ to ‘char’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:62:12: note: size_t Print::print(unsigned char, int)

size_t print(unsigned char, int = DEC);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:62:12: note: no known conversion for argument 1 from ‘void()’ to ‘unsigned char’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:63:12: note: size_t Print::print(int, int)

size_t print(int, int = DEC);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:63:12: note: no known conversion for argument 1 from ‘void()’ to ‘int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:64:12: note: size_t Print::print(unsigned int, int)

size_t print(unsigned int, int = DEC);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:64:12: note: no known conversion for argument 1 from ‘void()’ to ‘unsigned int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: size_t Print::print(long int, int)

size_t print(long, int = DEC);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: no known conversion for argument 1 from ‘void()’ to ‘long int’

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: size_t Print::print(long unsigned int, int)

size_t print(unsigned long, int = DEC);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: no known conversion for argument 1 from ‘void()’ to ‘long unsigned int’

exit status 1
call of overloaded ‘print(void (&)())’ is ambiguous

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Did you try printing a value that is in double quotes, as my example showed? What does printing a function mean to you?

in serial monitor i get:
open_lock()54493fc

mihoc:
in serial monitor i get:
open_lock()54493fc

With some code we can't see, you got some results. Well, OK.

So, fix the code to do what you want.

By the way, how are you powering the servo?

mihoc:
in serial monitor i get:
open_lock()54493fc

Is that after you put the thing you wanted to print inside " "?

Just for clarity, make it a Serial.println not a Serial.print so it gets a line end.

Then post your code again but if you put it in code tags [code]...[/code] it's much easier to read.

Ok now by changing the code in the first post to have the serial print, and not putting it in its own post, you’ve confused the crap out of anyone who tries to read the thread from the beginning.

But never mind… the serial print you added doesn’t prove the open_lock function was called, you need to put that inside open_lock like this:

void open_lock() {
  //Use this routine when working with Servos.
Serial.println("in the open_lock function");  //<<<<<<<<<<<<<<<<<<<<
  myservo.write(7); 
  delay(2000);
  myservo.write(100);
}

Only then will we know if the function is actually being entered.

you need to put that inside open_lock

Well, I did say “in the appropriate place…”. OP failed that test.

now i get just:
454cf054
454cf054
454cf054
454cf054
454cf054

So, which of your 5 String instances is that supposed to match? CasE MaTtErS.

PaulS:
So, which of your 5 String instances is that supposed to match? CasE MaTtErS.

454cf054 <----correct case(anyway it’s just the id number of the rfid card

Yeah it is "just" but the fact that you're now not priniting the "we're in the open_lock" or whatever, proves that it's not calling that function which means your "if" statement is failed, which means it doesn't recognise the code in the card as the code you have saved in the String at the top of the sketch.

So, it's not a servo problem: you're not getting far enough to access the servo.

so what i can do? where is the problem?

mihoc:
so what i can do? where is the problem?

Clue… compare what you have in the Strings at the top of the sketch, with the code it actually read from the card and printed. Then read the last two words in #14

the code is the same but which are the last two words in #14,what means #14?
the original code:

/*
 * ----------------------------------------------------------------------------
 * This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 * 
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 * 
 * This sketch show a simple locking mechanism using the RC522 RFID module.
 * ----------------------------------------------------------------------------
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          10          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

String read_rfid;
String ok_rfid_1="25bcefb0";
//String ok_rfid_2="ffffffff"; //add as many as you need.
int lock=7; //Which pin the lock will be on if using a relay or solenoid or similar 

//Use the lines below if you plan on using a servo as a locking mechanism.
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
int posClosed = 0;    // variable to store the servo position for locked
int posOpen = 360;    //same for open...
 

/*
 * Initialize.
 */
void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card

    //Choose which lock below:
    pinMode(lock, OUTPUT);
    myservo.attach(2);  // attaches the servo on pin 2 to the servo object 
}

/*
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
    read_rfid="";
    for (byte i = 0; i < bufferSize; i++) {
        read_rfid=read_rfid + String(buffer[i], HEX);
    }
}

void open_lock() {
  //Use this routine when working with Relays and Solenoids etc.
  digitalWrite(lock, HIGH);
  delay(2000);
  digitalWrite(lock,LOW);
  
  //Use this routine when working with Servos.
  myservo.write(360); 
  delay(2000);
  myservo.write(0);
}

void loop() {

      // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
        return;

    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
    Serial.println(read_rfid);
    if (read_rfid==ok_rfid_1) {
      //ok, open the door.
      open_lock();
    }
    //Add below as many "keys" as you want
    //if (read_rfid==ok_rfid_2) {
      //also ok, open the door
    //  open_lock();
    //}
    // else not needed. Anything else is not ok, and will not open the door...
}