Help needed -problem with rfid which triggers servo and led

It’s a Very basic programming, code written for rfid triggering servo and led.

The program compiles successfully. Serial monitor print ‘card accepted’ when right card is detected and ‘wrong key’ when wrong card is detected.(*no problem with rfid)
The problem is - it is not triggering servo and led’s(not working) . But I can see very very low light illuminates in red led when wrong card is detected. No traces in servo and green led.

(Both servo and led are in working condition, I have checked it separately)

I’m new to Arduino . I don’t know the reason though the code seems to be right. Kindly help

 ******PINS FOR ARDUINO*********
 *** Reset = Pin 5 ***
 *** SDA = Pin 10 ***
 *** MOSI = Pin 11 ***
 *** MISO = Pin 12 ***
 *** SCK = Pin 13 ***
 *** GND = GROUND ***
 *** 3.3 = 3.3v ***
 
**Servo**

***Power  = 5 v pin ( arduino)***
*** gnd = gnd (Arduino)***
*** Signal = PIN 9 (arduino)***

***LED***
****ledPin1 = Pin 3 (220 ohm resistor connnected in b/w pin3 & led positive) 
***ledPin2=  Pin4 ('')*****



 ******************************************/

#include <SPI.h>
#include <RFID.h>
#include <Servo.h> 
Servo doorLock;


RFID rfid(10,5); 
int pos = 0;
int ledPin1 = 3; //access accepted LED
int ledPin2 = 4; //access denied LED


void setup()
{ 
  Serial.begin(9600);
  SPI.begin();
  doorLock.attach(9);
  rfid.init();
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
   }


void loop() {
  
   if (rfid.isCard()) {
    
          if (rfid.readCardSerial()) { //this will show the 16 digits of the card
            
                       
                        
                 if(rfid.serNum[0] == 145){  //"29" is the first part of the 5 sets of digits from the card
                        Serial.println("Card accepted!");
                        digitalWrite(ledPin1,HIGH); // LED lights green
                        doorLock.write(180); // door releases
                        delay(2000); // waiting
                        doorLock.write(0); // gate latch
                        digitalWrite(ledPin1,LOW); 
                        }
                       
                       
                  else{  
                        Serial.println("sorry wrong key!"); //serial print for the COM on the PC
                        digitalWrite(ledPin2, HIGH); //turns on red "access denied" LED
                        delay(500);
                          digitalWrite(ledPin2, LOW); //LED turns off
                         }
                      }
                  }
                       rfid.halt();
                    }

RFID Library - http://www.4shared.com/zip/FI3TFguR/RFID.html
Servo - used builtin Arduino servo library

A link to the RFID library? A description of/link to the hardware?

How is the servo powered? Not by the Arduino, right?

I have updated with hardware spec(servo connection pins & leds) and RFID Library link. PaulS Thanks in advance.

it could be a problem with the led wiring. Also, your code looks incomplete at the bottom of the page.

Try this. add this in setup()

Serial.println("Checking Leds");
digitalWrite( Ledpin1, HIGH );
digitalWrite(Ledpin2,HIGH);
delay(1000);
digitalWrite( Ledpin1, LOW );
digitalWrite(Ledpin2,LOW);

Then you will know, if your led wiring is correct.

michinyon

i have used ur code in setup() serial moniter prints 'checking led' but leds are not illuminating(but i can see very very low illumination in red led not the other one).

i dono how wiring could be wrong.

***ledPin1 = Pin 3 (220 ohm resistor connnected in b/w pin3 & led positive) *ledPin2= Pin4 ('')**** and commonly grounded.

How is the servo powered? Not by the Arduino, right?

Servo - used builtin Arduino servo library

Well, then, I'd guess your left show is too tight. Try a ballet slipper, instead.

@PaulS. I couldnt get u... Wat do u mean ?

Servo is powered by arduino 5v pin .. (Which i have referred in code comment)

Wats wrong in using built in servo library ?

ostin-jjs: @PaulS. I couldnt get u... Wat do u mean ?

PaulS's comments are often very cryptic, he means well and helps a huge amount; you just have to work through his sarcasm.

Servo is powered by arduino 5v pin

No, you don't want to do that, even though the tutorial here on this very site says you can. Give it its own supply, with the ground joined to Arduino ground.

You need to post a schematic of the circuit, not a description in words.

@PaulS. I couldnt get u... Wat do u mean ?

I asked a question, in a way that did not feel at all ambiguous. Your answer to that question was completely unrelated to the question. So, my response to the answer was as equally unrelated to your answer.

I hoped that you'd get the point. Which you eventually did.

Which i have referred in code comment

I ignore the comments in the code that do not explain what the [u]code[/u] is doing.

At last it worked . :D :D :D :D :D :D :D

Itz all about powering the servo separately.

and with led's - resistor has a thin strand , it does not connect well with breadboard.

everything is fine now. itz works gr8.

thanks for the help.

Hearty Thanks to JimboZA, PaulS, michinyon