Linear Actuator and Rfid issue

Hi all

I'have:
Arduino UNO
4 Channel 5V Relay Module wired with 2 Linear Actuator (to retract and extend)
Rfid rc522 module

The normal work would be:
When the rfid tag is present, dhe linear actuators extends
When arduino receives a serialport command (for example "close"), linear actuators retract.

That works while the 2 motors are unplugged (i see the relays that work).

The problem is:
As soon as i plug the linear actuators, it works for a couple of times: retract on serial command, extend on rfid tag presence.
This works for 2-3 times and than the RFID module don'work any more.

If I, on every serialport command call mfrc522.PCD_Init(), all works fine, the problem disapears.

any idea? Can it be a hw o sw problem?

Thank You very much

Here is the code:

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

#define RST_PIN 9
#define SS_PIN 10
#define LED 8

const byte MY_ID = 3;

MFRC522 mfrc522(SS_PIN, RST_PIN);

const int relay1 = 4; //Arduino pin that triggers relay #1
const int relay2 = 5; //Arduino pin that triggers relay #2
const int relay3 = 6; //Arduino pin that triggers relay #3
const int relay4 = 7; //Arduino pin that triggers relay #4

const String DELIMITER = ":AAAAA:";

String message4server = "";
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete

void setup() {
SPI.begin(); // SPI bus
Serial.begin(9600);
mfrc522.PCD_Init(); // MFRC522
pinMode(LED, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);

digitalWrite(LED, LOW);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);

}

void loop() {
message4server = "";
if(getID(true)){

}
else{
if(Serial.available()){
char inChar = (char)Serial.read();
if(inChar == '1'){
extendActuator();
delay(3000);
mfrc522.PCD_Init();
}
}
}
}

void extendActuator() {
digitalWrite(relay1, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay4, LOW);
}

void retractActuator() {
digitalWrite(relay1, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay4, HIGH);
}

boolean getID(boolean stopIt){ //Read new tag if available
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return false;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return false;
}

blinkLed(3, 100);

String tagID = "";
for ( uint8_t i = 0; i < 4; i++) { // The MIFARE PICCs that we use have 4 byte UID
tagID.concat(String(mfrc522.uid.uidByte*, HEX)); // Adds the 4 bytes in a single String variable*

  • }*
  • tagID.toUpperCase();*
  • if(stopIt){*
  • mfrc522.PICC_HaltA(); // Stop reading*
  • //mfrc522.PCD_StopCrypto1();*
  • }*
  • retractActuator();*
  • return true;*
    }
    void blinkLed(int volte, int intervallo){
  • for(int i=0; i<volte;i++){*
  • digitalWrite(LED, HIGH);*
  • delay(intervallo);*
  • digitalWrite(LED, LOW);*
  • delay(intervallo); *
  • }*
    }

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Here is the circuit png picture

Thank you very much

Hi,
OPs fritzy....


Now can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Showing your power supply and labeling pins.
Sorry a fritzy picture is not a circuit diagram.

How are you powering the actuators?
Can you post a link to specs/data for your actuators please?
You are having problems with the actuators, yet do not show how they are connected or powered.

Thanks.. Tom... :slight_smile:

Hi Tom and thank You sincerely

Here I show you ho I connect the two linear actuators to the relay

Hi,
OPs image...

Tom... :o

Hi Tom

Here is a more detailed image.
If you zoom it in you can see all the details.
Sorry, but i don'know proffessional drawing sw

Arduino is connected to pc via USB and I supply electricity only to linear actuators.

Thank you

Any idea???

i am pretty sure those actuators are solenoid driven ones

put a diode 1N400x close (ie: by soldering ) to each actuator's terminal ( diode connected in REVERSE mode, anode goes to '+' rail, cathode goes to '-' rail )

Hi KASSIMSAMJI

The actuator is like this:

https://www.amazon.com/TOOGOO-Linear-Actuator-Opener-Bracket/dp/B073NY8H9F/ref=sr_1_7?keywords=linear+actuator+12v+500n&qid=1557307008&s=gateway&sr=8-7

The relay:

I use rfid tag to extract the actuators and serial commands to retract them

Thanks

Put the power supply of the relais coils also on external PSU. It takes too much power for internal of the arduino

I tried to use an external power suply too, but the problem still remain.
Do you mean to suplay from both: arduino and external power?

I removed the jumper in the picture and put the external power supply

Modulo_Rele_8canali_DC-5V_Arduino_RaspberryPi_jumper.jpg

Let's say it anothar way:

Can someone tell me how can I use an arduino to:

  • extend two linear actuators on rfid tag presenze
  • retract the two activators on serial command from local pc (usb connected)

some guide, wbsite, existing project, experience etc.

The only condition is to use a rfid reader for extending and a serial command for retracting both linear actuators at dhe same time.

Thank You

You have still not posted your code correctly. Note the original code has italics. That is a result of the forum software not being told that that is code.

If you're using F**ing, switch to the schematic view. It will take a little more work to clean up the schematic and reduce line-crossings but your job right now is to help us to help you.

Sorry Morgan.
Here is the code and the image

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

#define RST_PIN   9
#define SS_PIN    10
#define LED 8 

const byte MY_ID = 3;

MFRC522 mfrc522(SS_PIN, RST_PIN);

const int relay1 = 4;   //Arduino pin that triggers relay #1
const int relay2 = 5;   //Arduino pin that triggers relay #2
const int relay3 = 6;   //Arduino pin that triggers relay #3
const int relay4 = 7;   //Arduino pin that triggers relay #4 

byte stato = 0;

void setup() {
  SPI.begin();        // SPI bus
  Serial.begin(9600);
  mfrc522.PCD_Init(); //  MFRC522
  pinMode(LED, OUTPUT); 
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);

  digitalWrite(LED, LOW);

  stopActuator();

  stato = 0;
  //while (! Serial);
}

void loop() {

  if(getID(true)){
    extendActuator();  
  }
  else{
    if(Serial.available()){
      char inChar = (char)Serial.read();
      Serial.println(inChar);
      switch(inChar){
        case '1':               
          retractActuator();
          break;
        case '2':                
          Serial.println("ID:3");
          delay(50);
          break;
        case '3':                 
          Serial.println("CH:80");
          delay(50);
          break; 
        case '4':               
          if(isACardPresent()){
            Serial.println("IAM:1");
          }
          else{
            Serial.println("IAM:0");
          }
          delay(50);
          break;
        case '5':                
          if(isACardPresent()){
            extendActuator();
          }
          break;
      }
    }      
  } 
}

void extendActuator() {
  digitalWrite(relay1, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay2, LOW);
  digitalWrite(relay4, LOW);
  delay(2000);
  //stopActuator();
}

void retractActuator() {
  digitalWrite(relay1, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay4, HIGH);
  delay(2000);
  //stopActuator();
}

void stopActuator() {
  digitalWrite(relay1, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay4, LOW);
}

boolean getID(boolean stopIt){ //Read new tag if available
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return false;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
    return false;
  }

  blinkLed(3, 100);

  String tagID = "";
  for ( uint8_t i = 0; i < 4; i++) { // The MIFARE PICCs that we use have 4 byte UID
    tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
  }
  tagID.toUpperCase();
  if(stopIt){
    mfrc522.PICC_HaltA(); // Stop reading
    //mfrc522.PCD_StopCrypto1();
  }
  return true;
}

void haltRfid(){
  String tagID = "";
  for ( uint8_t i = 0; i < 4; i++) { // The MIFARE PICCs that we use have 4 byte UID
    tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
  }
  mfrc522.PICC_HaltA(); 
}

void blinkLed(int volte, int intervallo){
  for(int i=0; i<volte;i++){
    digitalWrite(LED, HIGH);
    delay(intervallo);
    digitalWrite(LED, LOW);
    delay(intervallo);    
  }
}

bool isACardPresent() {

  //Non sono sicuro se le prossime due istruzioni servano
  //mfrc522.PCD_Reset();
  //mfrc522.PCD_Init();
              
  byte bufferATQA[2];
  byte bufferSize = sizeof(bufferATQA);
  MFRC522::StatusCode result = mfrc522.PICC_WakeupA(bufferATQA, &bufferSize);
  //Serial.print("Status Code: ");
  //Serial.print(mfrc522.GetStatusCodeName(result));
  return (result == MFRC522::STATUS_OK || result == MFRC522::STATUS_COLLISION);
}

any suggestion?