0

As inserted in a Arduino Mysql Direct Tablela I'm new to Arduino and would like to know how to do something in the code to make a copy in the database

This code to pass the RFID and authorized storage software, the green light and the one-touch sound, which actually does the carrying out of an insert into a database.

I'm using ESP01

enter image description here

 #include <SPI.h>
 #include <MFRC522.h>

 //Pinos
 #define LED_VERDE 6
 #define LED_VERMELHO 7
 #define BUZZER 8
 #define SS_PIN 10
 #define RST_PIN 9

String IDtag = ""; //Variable that will store Tag ID
bool Permitido = false; //Variable verifying the permission
//Vector responsible for storing the ID's of the registered Tag's
String TagsCadastradas[] = {"669b5d5e", 
                        "ID_2",
                        "ID_3"};

MFRC522 LeitorRFID(SS_PIN, RST_PIN);    // Creates a new instance for the
reader and passes the pins as parameter


void setup() {
    Serial.begin(9600);             // Initializes Serial communication
    SPI.begin();                    // Initializes SPI communication 
    LeitorRFID.PCD_Init();          // Initializes the RFID reader
    pinMode(LED_VERDE, OUTPUT);     // Declare the pin of the green led as 
output
    pinMode(LED_VERMELHO, OUTPUT);  // Declare the red led pin as output

    pinMode(BUZZER, OUTPUT);        // Declares the buzzer pin as output  
}

void loop() {  
Leitura(); // Call the function responsible for reading the Tag's
  }

  void Leitura(){

    IDtag = ""; // Initially IDtag must be empty.

    // Check if there is a Tag present
    if ( !LeitorRFID.PICC_IsNewCardPresent() || 
 !LeitorRFID.PICC_ReadCardSerial() ) {
        delay(50);
        return;
    }


  // Get the Tag ID through the functionRFID.uid and store the ID in the
  variable IDtag     
    for (byte i = 0; i < LeitorRFID.uid.size; i++) {        
        IDtag.concat(String(LeitorRFID.uid.uidByte[i], HEX));
    }        

    // Compare the value of the read ID with the IDs stored in the vector
  TagsCadastradas[]
    for (int i = 0; i < (sizeof(TagsCadastradas)/sizeof(String)); i++) {
      if(  IDtag.equalsIgnoreCase(TagsCadastradas[i])  ){
          Permitido = true; 
 // Permitted variable assumes true valueif the ID Lido is registered
      }
    }       

    if(Permitido == true) acessoLiberado(); // If the Allowed variable is
  the function will be called acessoLiberado()        
    else acessoNegado(); // If the function is not called acessoNegado()

    delay(0001); / wait 2 seconds to re-read
  }

    void acessoLiberado(){
    Serial.println("Tag Cadastrada: " + IDtag); //Exibe a mensagem "Tag 
    Cadastrada" e o ID da tag não cadastrada
    efeitoPermitido();  //Chama a função efeitoPermitido()
    Permitido = false;  // Set the variable Allowed to false again
   }

  void acessoNegado(){
  Serial.println("Tag NAO Cadastrada: " + IDtag); //Exibe a mensagem "Tag 
  NAO Cadastrada" e o ID da tag cadastrada
  efeitoNegado(); //Chama a função efeitoNegado()
  }

  void efeitoPermitido(){  
  int qtd_bips = 2; //definindo a quantidade de bips
  for(int j=0; j<qtd_bips; j++){
  //Switching on the buzzer at a frequency of 1500 Hz and turning on the 
  green led.
  tone(BUZZER,1500);
  digitalWrite(LED_VERDE, HIGH);   
delay(100);   

//Desligando o buzzer e led verde.      
noTone(BUZZER);
digitalWrite(LED_VERDE, LOW);
delay(100);
}  
}

void efeitoNegado(){  
int qtd_bips = 1;  //definindo a quantidade de bips
for(int j=0; j<qtd_bips; j++){   
// Turning on the buzzer with a frequency of 500 hz and turning on the red 
 led.
tone(BUZZER,500);
digitalWrite(LED_VERMELHO, HIGH);   
delay(500); 

//Desligando o buzzer e o led vermelho.
noTone(BUZZER);
digitalWrite(LED_VERMELHO, LOW);
delay(500);
}  
}
  • 1
    See Do posts have to be in English on Stack Exchange? and Non-English Question Policy. Since this is not a foreign-language part of Stack Exchange, questions are required to be posted in English. – Nick Gammon Jun 18 '19 at 6:46
  • 2
    You probably can not do that for the following reasons 1) you will need an SQL connector (odbc driver) running on the arduino (plus networking s/w plus your program). The connector probably has not been ported to arduino - because 2) it will likely require several hundred KB (if not MB) of memory to run just the connector and 3) arduinos typically do not have that much memory in the first place. If you ask the next logical question, please do so in English. – GMc Jun 18 '19 at 7:32
  • I could not do this insert via web service? – Fabio Henrique Jun 18 '19 at 14:39
  • I ain't seeing a ESP01 in your connecting diagram so that might be a problem – Tarick Welling Jun 19 '19 at 10:09
  • I do not know how I include esp8266 to work with arduino – Fabio Henrique Jun 22 '19 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.