xl97's Iron Man motorized face plate tutorial

Hi everyone! I'm new to this world of Arduino. I definitely have to give thanks to xl97 for helping making affordable costume motorization possible for other users and myself

Now for my question to any experienced user here:

I just bought two Dccduino Nanos (arduino nano clones), one for practice and future usage and the other to actually use on my current helmet. My helmet already has led and sounds, so the only this that's missing is servos for the faceplate

Along with two 12kg metal gear servos, jumper wires, and a breadboard that I'm ordering would this parts kit be sufficient enough to just for a pair of servos for my helmet?

The kit is here: http://www.ebay.com/itm/291928605228


Sent from my Nexus 6P using Tapatalk
 
IMHO...

if all you need is the motorized portion..

then a voltage regulator (whatever your servos need.. usually its +6v)...
servo(s)
battery pack
and button

is all you would need.

resistors, pots, and header pins I dont think will do you much good here.. :)


post some specs on the servo and get a voltage regulator to match...

remember to connect all ground wires together.. (battery, Arduino and servos!)

Nano clones should be fine.. are they +3.3v or +5v based clones?
 
IMHO...

if all you need is the motorized portion..

then a voltage regulator (whatever your servos need.. usually its +6v)...
servo(s)
battery pack
and button

is all you would need.

resistors, pots, and header pins I dont think will do you much good here.. :)


post some specs on the servo and get a voltage regulator to match...

remember to connect all ground wires together.. (battery, Arduino and servos!)

Nano clones should be fine.. are they +3.3v or +5v based clones?
Hey! Thanks for the reply xl97, I really appreciate it man!

The two nanos I ordered from ebay are supposed to be 5v

Specs for the servos are:

Gear Type: All Metal Gears
Operating Speed: 0.17sec / 60 degrees (4.8V no load)
Operating Speed: 0.13sec / 60 degrees (6.0V no load)
Stall torque:12kg/cm(6V)
Operation Voltage : 4.8 - 7.2 V Temperature range: 0℃ to 55℃
Power Supply: Through External Adapter

Sent from my Nexus 6P using Tapatalk
 
What are the specs of the 'power supply'...

Are you sure you want to use an external power supply? Wouldnt a battery pack be easier to use for your costume?

I would use a +7.4v li-ion pack with enough current (mA) as you can find.

I would still get a +6v voltage regulator for the servo side of things..

same as the diagram posted around here.. but make it a +6v regulator instead of a +5v regulator.. (might need to read the spec sheet and see what, if any, caps are required for it)
 
What are the specs of the 'power supply'...

Are you sure you want to use an external power supply? Wouldnt a battery pack be easier to use for your costume?

I would use a +7.4v li-ion pack with enough current (mA) as you can find.

I would still get a +6v voltage regulator for the servo side of things..

same as the diagram posted around here.. but make it a +6v regulator instead of a +5v regulator.. (might need to read the spec sheet and see what, if any, caps are required for it)
Oh that part about the power supply can directly from the description box

These are the servos I was referring to:
http://www.ebay.com/itm/262744766375

Me personally, I would like to power the setup using something rechargeable. Maybe a small portable power bank used for mobile devices? But if you think battery would be better, then I will try to fit one into the helmet

Sent from my Nexus 6P using Tapatalk
 
You can buy/use rechargable li-ion batteries.

you can even wire in a re-charge port, so they batteries never need to be taken out of the 'prop/project' if you like.. but you would need a li-ion battery charger than as well.

its done all the time in the lightsaber scene.

or you can still use re-charageable li-ions but remove them and charge them.. (still need a charger then)

I'm sure this stuff can probably be found elsewhere for cheaper..

but you can rest assured that the quality and shipping is top notch from The Custom Saber Shop: http://www.thecustomersabershop.com


Batteries:
http://www.thecustomsabershop.com/Li-ion-Packs-C85.aspx

Chargers:
http://www.thecustomsabershop.com/Li-ion-Chargers-C86.aspx

Re-Charge Ports/Kill Keys..etc (misc):
http://www.thecustomsabershop.com/Clips-Connectors-C37.aspx

What you need is something that not only can deliver the correct voltage (to both the Arduino and Servos).. but also have enough current to run things for a while.

A single servo can draw upwards of 1 AMP in current when under load or spiking.. (you'll have 2).. but the Arduino..etc and whatever else

A Panasonic 7.4v Li-ion 3400mAh 18650 Battery Pack but in side by side style might be a good option. (have to source elsewhere for side by side packs.. they wont fit in any current saber hilt styles.. so they arent carried at TCSS)
 
Hi @x197
Thanks for posting all of this great info. I'm new to the boards and to the world of electronics. I've been reading through this board and the other massive board, as well as watching lots of videos, trying to figure everything out. I guess right now my biggest question is how does your wiring schematic translate to testing on the bread board. I've bought all of the supplies and have been tinkering with everything with different levels of success but ultimately am still feeling pretty lost with all of this. Thanks.
 
Sorry.. I'm not sure what your question is?

Using a breadboard would be no different than how you see things wired up in the image/diagram.

any time wires connect.. make sure you are using the same ROW in the breadboard.

if there is something more specific.. just ask.. we'll help if we can! :)
 
Hello,
First of all, thank you for all your explanation, I started with arduino, I just found your code with the servo and I can not get it to work properly with RFID module.
My servo works, but by compiling your code with mine, nothing happens as expected, the LEDs do not go off when I close the headset.
could you help me to redo the correct code with arduino and RFID?
thanks again
Have a good day



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

// broches de contrôle led (doivent être des broches compatibles PWM pour la décoloration)
const int leftEye = 6; // numéro des LEDs œil gauche / pcb
const int rightEye = 3; // numéro des LEDs œil droit / pcb

/* we always wait a bit between updates of the display */
unsigned long delaytime = 1;
unsigned long fadespeed = 500;
unsigned long blinkspeed = 100;
unsigned long currentPWM = 0;

#define S_IDLE 1
#define S_LEDON 2
#define S_WAITON 3
#define S_LEDOFF 4
#define S_WAITOFF 5
#define S_INITON 6
#define S_INITWAIT 7
#define S_BLINKON 8

//FSM init vars
static int state = S_IDLE; // l'état initial est 1, l'état "inactif".
static unsigned long lastTime; // // Pour enregistrer l'heure "actuelle" dans les délais.



#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key;

int code[] = {86,242,179,115}; //This is the stored UID
int codeRead = 0;
int Buzzer = 6;
int activate =0;
Servo myservo;
String uidString;
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
myservo.attach(5); //attach the servo to pin 5
pinMode(Buzzer,OUTPUT);
myservo.write(0); // 0 degree angle for servo
Serial.print("INTIT STATE: ");
Serial.println(state);

//start it off
state = S_BLINKON;



}

void loop() {

{
switch(state)
{
case S_IDLE:
// We don't need to do anything here, waiting for a forced state change...like button press.
break;

case S_BLINKON:
//do blink routine here
analogWrite(leftEye, 155);
analogWrite(rightEye, 155);
delay(blinkspeed);
analogWrite(leftEye, 0);
analogWrite(rightEye, 0);
delay(blinkspeed);
analogWrite(leftEye, 155);
analogWrite(rightEye, 155);
delay(blinkspeed);
analogWrite(leftEye, 0);
analogWrite(rightEye, 0);
delay(10);
currentPWM = 0;

state = S_LEDON;
break;

case S_LEDON:
Serial.println("increase........");
analogWrite(leftEye, currentPWM);
analogWrite(rightEye, currentPWM);
lastTime = millis(); // Remember the current time
state = S_WAITON; // Move to the next state
break;

case S_WAITON:
// If one second has passed, then move on to the next state.
if(millis() > lastTime + delaytime)
{
if(currentPWM < 255){
currentPWM++;
state = S_LEDON;
}
else{
Serial.println("@255 done........");
state = S_IDLE;
//state = S_LEDOFF; //no auto turn off.. set to idle state
}
}
break;

case S_LEDOFF:
Serial.println("........decrease");
lastTime = millis(); // Remember the current time
state = S_WAITOFF;
break;

case S_WAITOFF:
// If one second has passed, then go back to state 2.
if(millis() > lastTime + delaytime)
{
if(currentPWM > 0){
currentPWM--;
state = S_LEDOFF;
}
else{
state = S_LEDON;
}
}
break;

default:
state = S_IDLE;
break;
}
}



if( rfid.PICC_IsNewCardPresent())
{
readRFID();
}
delay(100);

}

void readRFID()
{
rfid.PICC_ReadCardSerial();
Serial.print(F("\nPICC type: "));
MFRC522::pICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType));

// Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::pICC_TYPE_MIFARE_MINI &&
piccType != MFRC522::pICC_TYPE_MIFARE_1K &&
piccType != MFRC522::pICC_TYPE_MIFARE_4K) {
Serial.println(F("Your tag is not of type MIFARE Classic."));
return;
}


Serial.println("Scanned PICC's UID:");
printDec(rfid.uid.uidByte, rfid.uid.size);

uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);



int i = 0;
boolean match = true;
while(i<rfid.uid.size)
{
if(!(rfid.uid.uidByte == code))
{
match = false;
}
i++;
}

if(match)
{ if (activate==0){
myservo.write(90); // 90 degree angle for servo (Door will open)
Serial.println("\nDoor is open");
delay(1000);
activate = activate+1;
}
else
{ myservo.write(0); // 0 degree angle for servo (Door will close)
activate = 0;
Serial.println("\nDoor is close");
delay(1000);
}
}
else
{
tone(6,400,1000);
Serial.println("\nUnknown Card");
}


// Halt PICC
rfid.PICC_HaltA();

// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}

void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer < 0x10 ? " 0" : " ");
Serial.print(buffer, DEC);
}
}
 
1.) Please wrap your code in between CODE tags [ code ] code pasted here [/ code ]

* remove the spaces in the -code- tags as well..

That way its more readable, and easier to copy/paste into the IDE

2.) Post a link to your RFID reader.. so we know what your using and the documentation..

* dont believe I have the same one?.. so testing will be hard..


That code compiles?? hmmm..

Also.. I dont even see where you are trying to trigger any state change in your RFID routine?? I dont think you are. (hard to tell)
 
Why didnt you use the code with the led and servo stuff in it? (together)

And just add your RFID checking routine to the IDLE state/loop..to call your readRFID() function?

then on active 1 or 0 you can change the STATE to start routines already there/established?
 
Hello,
Thank you for your answer, I'm sorry, I answer you late, with the time difference ^^ (I live in France)
I returned the code I tried to use with the tags.
Here the modified code that does not work:

Code:
#include <MFRC522.h>
#include <SPI.h>
#include <Servo.h>

// broches de contrôle led (doivent être des broches compatibles PWM pour la décoloration)
const int leftEye =  6;  // numéro des LEDs œil gauche / pcb
const int rightEye =  3;  // numéro des LEDs œil droit / pcb

/* we always wait a bit between updates of the display */
unsigned long delaytime = 1;
unsigned long fadespeed = 500;
unsigned long blinkspeed = 100;
unsigned long currentPWM = 0;

#define S_IDLE 1
#define S_LEDON 2
#define S_WAITON 3
#define S_LEDOFF 4
#define S_WAITOFF 5
#define S_INITON 6
#define S_INITWAIT 7
#define S_BLINKON 8

//FSM init vars
static int state = S_IDLE; // l'état initial est 1, l'état "inactif".
static unsigned long lastTime;  // Pour enregistrer l'heure "actuelle" dans les délais.



#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key;

int code[] = {86,242,179,115}; //This is the stored UID
int codeRead = 0;
int Buzzer = 6;
int activate =0;
Servo myservo;
String uidString;
void setup() {
 Serial.begin(9600);
 SPI.begin(); // Init SPI bus
 rfid.PCD_Init(); // Init MFRC522
 myservo.attach(5); //attach the servo to pin 5
 pinMode(Buzzer,OUTPUT);
 myservo.write(0); // 0 degree angle for servo
 Serial.print("INTIT STATE: ");
  Serial.println(state);

  //start it off
  state = S_BLINKON;



}

void loop() {

{
  switch(state)
  {
  case S_IDLE:
    // We don't need to do anything here, waiting for a forced state change...like button press.
    break;

  case S_BLINKON:
    //do blink routine here
    analogWrite(leftEye, 155);
    analogWrite(rightEye, 155);
    delay(blinkspeed);
    analogWrite(leftEye, 0);
    analogWrite(rightEye, 0);
    delay(blinkspeed);
    analogWrite(leftEye, 155);
    analogWrite(rightEye, 155);
    delay(blinkspeed);
    analogWrite(leftEye, 0);
    analogWrite(rightEye, 0);
    delay(10);
    currentPWM = 0;
   
    state = S_LEDON;   
    break;

  case S_LEDON:
    Serial.println("increase........");
    analogWrite(leftEye, currentPWM);
    analogWrite(rightEye, currentPWM);
    lastTime = millis();  // Remember the current time
    state = S_WAITON;  // Move to the next state
    break;

  case S_WAITON:
    // If one second has passed, then move on to the next state.
    if(millis() > lastTime + delaytime)
    {
      if(currentPWM < 255){
        currentPWM++;
        state = S_LEDON;       
      }
      else{
        Serial.println("@255 done........");
        state = S_IDLE;
        //state = S_LEDOFF; //no auto turn off.. set to idle state
      }
    }
    break;

  case S_LEDOFF:
    Serial.println("........decrease");
    lastTime = millis();  // Remember the current time
    state = S_WAITOFF;
    break;

  case S_WAITOFF:
    // If one second has passed, then go back to state 2.
    if(millis() > lastTime + delaytime)
    {
      if(currentPWM > 0){
        currentPWM--;
        state = S_LEDOFF;       
      }
      else{
        state = S_LEDON;
      }
    }
    break;

  default:
    state = S_IDLE;
    break;
  }
}


 
 if( rfid.PICC_IsNewCardPresent())
 {
 readRFID();
 }
 delay(100);

}

void readRFID()
{
 rfid.PICC_ReadCardSerial();
 Serial.print(F("\nPICC type: "));
 MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
 Serial.println(rfid.PICC_GetTypeName(piccType));

// Check is the PICC of Classic MIFARE type
 if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
 piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
 piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
 Serial.println(F("Your tag is not of type MIFARE Classic."));
 return;
 }


 Serial.println("Scanned PICC's UID:");
 printDec(rfid.uid.uidByte, rfid.uid.size);

uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);



 int i = 0;
 boolean match = true;
 while(i<rfid.uid.size)
 {
 if(!(rfid.uid.uidByte[i] == code[i]))
 {
 match = false;
 }
 i++;
 }

if(match)
 { if (activate==0){
 myservo.write(90); // 90 degree angle for servo (Door will open)
 Serial.println("\nDoor is open");
 delay(1000);
 activate = activate+1;
 }
 else
 { myservo.write(0); // 0 degree angle for servo (Door will close)
 activate = 0;
 Serial.println("\nDoor is close");
 delay(1000);
 }
 }
 else
 {
 tone(6,400,1000);
 Serial.println("\nUnknown Card");
 }


 // Halt PICC
 rfid.PICC_HaltA();

// Stop encryption on PCD
 rfid.PCD_StopCrypto1();
}

void printDec(byte *buffer, byte bufferSize) {
 for (byte i = 0; i < bufferSize; i++) {
 Serial.print(buffer[i] < 0x10 ? " 0" : " ");
 Serial.print(buffer[i], DEC);
 }
}

My rfid is a rfid-Rc522 module.
What works with the rfid reader but without the leds:
Code:
#include <MFRC522.h>
#include <SPI.h>
#include <Servo.h>


#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key;

int code[] = {86,242,179,115}; //This is the stored UID
int codeRead = 0;
int activate =0;
Servo myservo;
String uidString;
void setup() {
 Serial.begin(9600);
 SPI.begin(); // Init SPI bus
 rfid.PCD_Init(); // Init MFRC522
 myservo.attach(5); //attach the servo to pin 5
 myservo.write(0); // 0 degree angle for servo


}

void loop() {
 
 if( rfid.PICC_IsNewCardPresent())
 {
 readRFID();
 }
 delay(100);

}

void readRFID()
{
 rfid.PICC_ReadCardSerial();
 Serial.print(F("\nPICC type: "));
 MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
 Serial.println(rfid.PICC_GetTypeName(piccType));

// Check is the PICC of Classic MIFARE type
 if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
 piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
 piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
 Serial.println(F("Your tag is not of type MIFARE Classic."));
 return;
 }


 Serial.println("Scanned PICC's UID:");
 printDec(rfid.uid.uidByte, rfid.uid.size);

uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);



 int i = 0;
 boolean match = true;
 while(i<rfid.uid.size)
 {
 if(!(rfid.uid.uidByte[i] == code[i]))
 {
 match = false;
 }
 i++;
 }

if(match)
 { if (activate==0){
 myservo.write(90); // 90 degree angle for servo (Door will open)
 Serial.println("\nDoor is open");
 delay(1000);
 activate = activate+1;
 }
 else
 { myservo.write(0); // 0 degree angle for servo (Door will close)
 activate = 0;
 Serial.println("\nDoor is close");
 delay(1000);
 }
 }
 else
 {
 tone(6,400,1000);
 Serial.println("\nUnknown Card");
 }


 // Halt PICC
 rfid.PICC_HaltA();

// Stop encryption on PCD
 rfid.PCD_StopCrypto1();
}

void printDec(byte *buffer, byte bufferSize) {
 for (byte i = 0; i < bufferSize; i++) {
 Serial.print(buffer[i] < 0x10 ? " 0" : " ");
 Serial.print(buffer[i], DEC);
 }
}
I'm sorry if my english is not good, I'm french: D
I am new in arduino, I learn a lot but I have no basis in electronics or electricity.

Thank you very much and I will try to continue to edit, but I do not know how to start the code by replacing the buttons (as you have posted) by triggering the rfid.
 
I am trying this code, but I do not understand how to replace the buttons by reading the RFID tag?
I'm really bad, I'm trying to change since this morning but nothing happens.

Code:
// IronMan Helmet: eye blink sequence_v1.0
// created by: xl97


//import servo lib
#include <Servo.h>

//servo object names
Servo myservo; // create servo object to control a servo
Servo myservo1;

const int buttonPin = 2; // the pin that the pushbutton is attached to
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button


// led control pins (need to be PWM enabled pins for fading)
const int leftEye =  6;  // the number of the left eye/pcb LEDs
const int rightEye =  3;  // the number of the right eye/pcb LEDs

unsigned long fadeDelay = .5; //speed of the eye 'fade'
unsigned long callDelay = 700; //length to wait to start eye flicker after face plate comes down
unsigned long blinkSpeed = 100; //delay between init blink on/off
unsigned long currentPWM = 0;
boolean isOpen = true;

#define S_IDLE 1
#define S_LEDON 2
#define S_WAITON 3
#define S_LEDOFF 4
#define S_WAITOFF 5
#define S_INITON 6
#define S_INITWAIT 7
#define S_BLINKON 8
#define S_SERVOUP 9
#define S_SERVODOWN 0
#define S_SERVOWAIT 10



//FSM init vars
static int state = S_IDLE; // initial state is 1, the "idle" state.
static unsigned long lastTime;  // To store the "current" time in for delays.


void setup() {
  // Set up serial port
  Serial.begin(9600); 
  //start it off
  //state = S_BLINKON;
  Serial.print("INTIT STATE: ");
  Serial.println(state);

  myservo.attach(9); // attaches the servo on pin 9 to the servo object
  myservo1.attach(10); // attaches the servo on pin 10 to the servo object

  pinMode(buttonPin, INPUT); // initialize the button pin as a input
  digitalWrite(buttonPin, HIGH); //use interal pull up resistors
}

void loop() {
  switch(state)
  {
  case S_IDLE:
   // We don't need to do anything here, waiting for a forced state change...like button press.
   //check mian button state
   buttonState = digitalRead(buttonPin);

   // compare buttonState to previous state 
   if (buttonState != lastButtonState) {
     //if button pressed/down
     if (buttonState == LOW){
       //ie: pressed   
       if(isOpen == true){
         Serial.print("CLOSING FACE PLATE: ");
         Serial.println(isOpen, DEC);
         state = S_SERVODOWN;
       }
       else{
         Serial.print("OPENING FACE PLATE: ");
         Serial.println(isOpen, DEC);
         //state = S_SERVOUP;
         state = S_LEDOFF;
       }
       isOpen = !isOpen;
     }
     else{
       //went from ON/HIGH to LOW/OFF..ie: released
       //Serial.print("RELEASE: ");
       //Serial.println(isOpen, DEC);
     }
   }
   // save the current state for next loop
   lastButtonState = buttonState;
   break;

  case S_BLINKON:
   Serial.println("init blink.........");   
   //do blink routine here
   //one blink
   analogWrite(leftEye, 155);
   analogWrite(rightEye, 155);
   delay(blinkSpeed);
   analogWrite(leftEye, 0);
   analogWrite(rightEye, 0);
   delay(10);
   //two blinks
   /*
   analogWrite(leftEye, 155);
    analogWrite(rightEye, 155);
    delay(blinkSpeed);
    analogWrite(leftEye, 0);
    analogWrite(rightEye, 0);
    delay(10);
    */
   state = S_LEDON;   
   break;

  case S_LEDON:
   Serial.println("increase........");   
   lastTime = millis();  // Remember the current time
   analogWrite(leftEye, currentPWM);
   analogWrite(rightEye, currentPWM);
   state = S_WAITON;  // Move to the next state
   break;

  case S_WAITON:
   // If one second has passed, then move on to the next state.
   if(millis() > (lastTime + fadeDelay)){
     if(currentPWM < 255){
       currentPWM += 5;
       state = S_LEDON;       
     }
     else{
       Serial.println("@ 255 done........");
       state = S_IDLE;
       //state = S_LEDOFF; //no auto turn off.. set to idle state
     }
   }
   break;

  case S_LEDOFF:
   Serial.println("........decrease");     
   lastTime = millis();  // Remember the current time
   analogWrite(leftEye, currentPWM);
   analogWrite(rightEye, currentPWM);
   state = S_WAITOFF;
   break;

  case S_WAITOFF:
   // If one second has passed, then move on to the next state.
   if(millis() > (lastTime + fadeDelay)){
     if(currentPWM > 0){  //change 0 to higher number to init face 'up' function sooner.
       currentPWM -= 5;
       state = S_LEDOFF;       
     }
     else{
       Serial.println("@ 0 done........");
       state = S_SERVOUP; //leds off..raise faceplate
     }
   }
   break;

  case S_SERVOUP:
   Serial.println("servo up.........");
   myservo.write(100);
   myservo1.write(100);
   state = S_IDLE;   
   break;

  case S_SERVODOWN:
   lastTime = millis();  // Remember the current time
   Serial.println("servo down.........");   
   myservo.write(0);
   myservo1.write(0);
   state = S_SERVOWAIT;   
   break;

  case S_SERVOWAIT:
   // If enough time has passed, call the eye flicker routine
   if(millis() > (lastTime + callDelay)){   
     Serial.println("start eye flicker routine");
     state = S_BLINKON;       
   }
   else{
     Serial.println("waiting........");
   }
   break;

  default:
   state = S_IDLE;
   break;
  }
}
 
Hi, I'm really happy, I managed to work as I wanted!
I post the code that works for me!
I managed by modifying, adding, a lot of codes, I started to understand what some codes do !!!!!!!
I am far from being an expert but happy to have succeeded !!!!
Thank you again for your help, I will see on the forum because it has been a gold mine for me, a lot of explanation and support!
Good evening to you and thank you for your patience !!
Code:
#include <MFRC522.h>
#include <SPI.h>
#include <Servo.h>


#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key;

int code[] = {86,242,179,115}; //This is the stored UID
int codeRead = 0;
int activate =0;
Servo myservo;
String uidString;
void setup() {
 Serial.begin(9600);
 SPI.begin(); // Init SPI bus
 rfid.PCD_Init(); // Init MFRC522
 pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
 myservo.attach(5); //attach the servo to pin 5
 myservo.write(0); // 0 degree angle for servo


}

void loop() {
 
 if( rfid.PICC_IsNewCardPresent())
 {
 readRFID();
 }
 delay(100);

}

void readRFID()
{
 rfid.PICC_ReadCardSerial();
 Serial.print(F("\nPICC type: "));
 MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
 Serial.println(rfid.PICC_GetTypeName(piccType));

// Check is the PICC of Classic MIFARE type
 if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
 piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
 piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
 Serial.println(F("Your tag is not of type MIFARE Classic."));
 return;
 }


 Serial.println("Scanned PICC's UID:");
 printDec(rfid.uid.uidByte, rfid.uid.size);

uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);



 int i = 0;
 boolean match = true;
 while(i<rfid.uid.size)
 {
 if(!(rfid.uid.uidByte[i] == code[i]))
 {
 match = false;
 }
 i++;
 }

if(match)
 { if (activate==0){
 
 myservo.write(160); // 90 degree angle for servo (Door will open)
 Serial.println("\nDoor is open");
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(50);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(50);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(70);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(70);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(100);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(100);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(150);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(100);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(500);
 activate = activate+1;
 }
 else
 { myservo.write(0); // 0 degree angle for servo (Door will close)
 activate = 0;
 Serial.println("\nDoor is close");
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(1000);
 }
 }
 else
 {
 tone(6,400,1000);
 Serial.println("\nUnknown Card");
 }


 // Halt PICC
 rfid.PICC_HaltA();

// Stop encryption on PCD
 rfid.PCD_StopCrypto1();
}

void printDec(byte *buffer, byte bufferSize) {
 for (byte i = 0; i < bufferSize; i++) {
 Serial.print(buffer[i] < 0x10 ? " 0" : " ");
 Serial.print(buffer[i], DEC);
 }
}
 
I just managed to implement varspeedservo to adjust the speed of movement of the servo, it's great !!!!
The link of my program below !!!
Good reading

link varspeedservo netlabtoolkit/VarSpeedServo

Code:
#include <VarSpeedServo.h>
#include <MFRC522.h>
#include <SPI.h>



#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key;

int code[] = {86,242,179,115}; //This is the stored UID
int codeRead = 0;
int activate =0;
VarSpeedServo myservo;
String uidString;
void setup() {
 Serial.begin(9600);
 SPI.begin(); // Init SPI bus
 rfid.PCD_Init(); // Init MFRC522
 pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
 myservo.attach(5); //attach the servo to pin 5
 myservo.write(0); // 0 degree angle for servo


}

void loop() {
 if( rfid.PICC_IsNewCardPresent())
 {
 readRFID();
 }
 delay(100);

}

void readRFID()
{
 rfid.PICC_ReadCardSerial();
 Serial.print(F("\nPICC type: "));
 MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
 Serial.println(rfid.PICC_GetTypeName(piccType));

// Check is the PICC of Classic MIFARE type
 if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
 piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
 piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
 Serial.println(F("Your tag is not of type MIFARE Classic."));
 return;
 }


 Serial.println("Scanned PICC's UID:");
 printDec(rfid.uid.uidByte, rfid.uid.size);

uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);



 int i = 0;
 boolean match = true;
 while(i<rfid.uid.size)
 {
 if(!(rfid.uid.uidByte[i] == code[i]))
 {
 match = false;
 }
 i++;
 }

if(match)
 { if (activate==0){
 myservo.write(180, 50, true); // 90 degree angle for servo (Door will open)
 Serial.println("\nDoor is open");
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(50);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(50);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(70);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(70);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(100);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(100);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(150);
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(100);
 digitalWrite(3, HIGH);
 digitalWrite(6, HIGH);
 delay(500);
 activate = activate+1;
 }
 else
 { myservo.write(0, 50, true); // 0 degree angle for servo (Door will close)
 activate = 0;
 Serial.println("\nDoor is close");
 digitalWrite(6, LOW);
 digitalWrite(3, LOW);
 delay(1000);
 }
 }
 else
 {
 tone(6,400,1000);
 Serial.println("\nUnknown Card");
 }


 // Halt PICC
 rfid.PICC_HaltA();

// Stop encryption on PCD
 rfid.PCD_StopCrypto1();
}

void printDec(byte *buffer, byte bufferSize) {
 for (byte i = 0; i < bufferSize; i++) {
 Serial.print(buffer[i] < 0x10 ? " 0" : " ");
 Serial.print(buffer[i], DEC);
 }
}
 
You arent using my code.. and you dont seem to need help any more..

please post in your own thread.

This thread is for the assets posted here.. and help with that code/schematic..etc..

Thanks
 
You arent using my code.. and you dont seem to need help any more..

please post in your own thread.

This thread is for the assets posted here.. and help with that code/schematic..etc..

Thanks

ahh sorry, I did not know!
Sorry to have invaded your thread.
I wanted to post it so I could help other people.
I did not create a thread!
Thank you again for your help !
 
I'm saying.. if you post in your OWN thread.. others will see it and benefit from it..

If they see it here...

It might be confusing since it does NOT use the code supported in this thread/initial post.

- nothing to be sorry about!
 
Last edited:

Your message may be considered spam for the following reasons:

If you wish to reply despite these issues, check the box below before replying.
Be aware that malicious compliance may result in more severe penalties.
Back
Top