Shanmugaraja
Shanmugaraja

Reputation: 11

Knob control of servo with rfid

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
    Serial.begin(115200);
    SPI.begin();
    mfrc522.PCD_Init();
    Serial.println("Arduino RFID");
    myservo.attach(3);
    myservo.write(0);
}

void loop() {

    val = analogRead(potpin);

    if (!mfrc522.PICC_IsNewCardPresent()) {
        return;
    }

    if (!mfrc522.PICC_ReadCardSerial()) {
        return;
    }

    String content= "";
    for ( byte i = 0; i < mfrc522.uid.size; i++ ) {
        content.concat(String(mfrc522.uid.uidByte, HEX));
        if( i < mfrc522.uid.size-1 ) content += "-";
    }

    content.toUpperCase();
    Serial.println();
    Serial.println("UID tag :'" + content + "'");
    Serial.print(content);

    if (content == "55-33-2C-83")
        val = map(val, 0, 1023, 0, 150);
    else if (content == "91-2B-D2-2F")
        val = map(val, 0, 1023, 0, 60);

    myservo.write(val);
    delay(15);
}

This is my code .i want to do my servo to rotate 0to180 when rfid scan specific tag.and rotate 0 to 60 when scan another tag. But the issue is .i want to change the servo pos when rfid scan once . The above program runs when the rfid scan the tag after removing it doesnt work. Pls help by providing some codes

Upvotes: 1

Views: 55

Answers (0)

Related Questions