Hi,
I’m looking for a RFID code that allows me to operate 2 servo motors at the same time while the tag is present and when the tag is removed the servo moves back to its original position. This would be a huge help to my project.
Thanks
Hi,
I’m looking for a RFID code that allows me to operate 2 servo motors at the same time while the tag is present and when the tag is removed the servo moves back to its original position. This would be a huge help to my project.
Thanks
you can try this code which is based on circuito.io code
ServoRFID.zip (8.6 KB)
// Include Libraries
#include "Arduino.h"
#include "RFID.h"
#include "Servo.h"
// Pin Definitions
#define RFID_PIN_SDA 10
#define RFID_PIN_RST 2
#define SERVOMD_1_PIN_SIG 3
#define SERVOMD_2_PIN_SIG 4
// Global variables and defines
const int lockPosition = 20; //lock position
const int openPosition = 150; //open Position when event is detected
// object initialization
Servo servoMD_1;
Servo servoMD_2;
RFID rfid(RFID_PIN_SDA, RFID_PIN_RST);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");
//initialize RFID module
rfid.init();
servoMD_1.attach(SERVOMD_1_PIN_SIG);
servoMD_2.attach(SERVOMD_2_PIN_SIG);
servoMD_1.write(lockPosition);
servoMD_2.write(lockPosition);
delay(100);
servoMD_1.detach();
servoMD_2.detach();
}
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
// RFID - RC522 RF IC Card Sensor Module - Test Code
//Read RFID tag if present
String rfidtag = rfid.readTag();
//print the tag to serial monitor if one was discovered
rfid.printTag(rfidtag);
if (rfidtag == "PUT YOUR RFID TAG HERE") {
// if RFID tag detected the servos will move to open position for 2 secs and then move go back to lock position
servoMD_1.attach(SERVOMD_1_PIN_SIG); // 1. attach the servo to correct pin to control it.
servoMD_2.attach(SERVOMD_2_PIN_SIG); // 1. attach the servo to correct pin to control it.
servoMD_1.write(openPosition); // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
servoMD_2.write(openPosition); // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
delay(2000); //wait 2 secs and lock the servos
servoMD_1.write(lockPosition); // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
servoMD_2.write(lockPosition); // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
servoMD_1.detach(); // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
servoMD_2.detach(); // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
}
}
what servo did you use for this code and do you still have the web address for the wiring diagram?
Thanks
I think this code will work well, I just need to find out how you wired it up and if I can use a 9G servo motor.
looking forward to hearing back from you
@maayanmigdal
Thanks
Hi,
The wiring for this code is based on circuito.io
here’s the link https://www.circuito.io/app?components=9442,11021,761981,2345678,2345678
This code will work the same with 9G servo motor.
Note that the servo motors are powered by an external power source since they can’t draw enough current from the arduino board (you will have the part list under the parts tab on circuito.io)
BTW if you are planning to build a lock, it might be better for you to choose a Lock-style Solenoid - 12VDC over the servos
the servo motors are going to be used to open a metal lid
@maayanmigdal
Do you know how I can incorporate the “blink without delay” code into the code I have shared?
Thanks
There’s a good post on Adafruit blog that explains servo and without delay pretty well.
take a look: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-clean-sweep