hey guys
am looking for help to solve my project problem
i have 10 led to light with switch
when i run it alone it run correctly
but when i run it with other codes
it will be blinking.
it suppose to be lighting without blinking
this is my code on arduino mega 2560
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
//
#define pir 33
#define pir_led 2
#define S 12
#define SS 13
#define S1 15
#define S2 16
#define S3 17
#define S4 18
#define S5 19
#define SS1 42
#define SS2 43
#define SS3 44
#define SS4 45
#define SS5 46
//creating mfrc522 instance
#define RSTPIN 5
#define SSPIN 53
MFRC522 rc(SSPIN, RSTPIN);
Servo myServo; //define servo name
int readsuccess;
/* the following are the UIDs of the card which are authorised
to know the UID of your card/tag use the example code 'DumpInfo'
from the library mfrc522 it give the UID of the card as well as
other information in the card on the serial monitor of the arduino*/
//byte defcard[4]={0x32,0xD7,0x0F,0x2B}; // if you only want one card
byte defcard[][4]={{0xB0,0x68,0xC9,0xA4},{0xE6,0x53,0x1F,0x2B}}; //for multiple cards
int N=2; //change this to the number of cards/tags you will use
byte readcard[4]; //stores the UID of current tag which is read
void setup() {
//define the LED of pir pin as output
pinMode(pir_led, OUTPUT);
//define the sensor pir as input
pinMode(pir, INPUT);
Serial.begin(9600);
SPI.begin();
rc.PCD_Init(); //initialize the receiver
rc.PCD_DumpVersionToSerial(); //show details of card reader module
myServo.attach(6); //servo pin
myServo.write(75); //servo start position
pinMode(8,OUTPUT); //led for authorised
pinMode(7,OUTPUT); //led for not authorised
pinMode(S,INPUT);
pinMode(SS,INPUT);
pinMode(S1,OUTPUT);//led of Switch1
pinMode(S2,OUTPUT);//led of Switch1
pinMode(S3,OUTPUT);//led of Switch1
pinMode(S4,OUTPUT);//led of Switch1
pinMode(S5,OUTPUT);//led of Switch1
pinMode(SS1,OUTPUT);//led of Switch2
pinMode(SS2,OUTPUT);//led of Switch2
pinMode(SS3,OUTPUT);//led of Switch2
pinMode(SS4,OUTPUT);//led of Switch2
pinMode(SS5,OUTPUT);//led of Switch2
Serial.println(F("the authorised cards are")); //display authorised cards just to demonstrate you may comment this section out
for(int i=0;i<N;i++){
Serial.print(i+1);
Serial.print(" ");
for(int j=0;j<4;j++){
Serial.print(defcard[i][j],HEX);
}
Serial.println("");
}
Serial.println("");
Serial.println(F("Scan Access Card to see Details"));
}
void loop() {
PIR();
RFID();
SWITCH1();
SWITCH2();
}
int getid(){
if(!rc.PICC_IsNewCardPresent()){
return 0;
}
if(!rc.PICC_ReadCardSerial()){
return 0;
}
Serial.println("THE UID OF THE SCANNED CARD IS:");
for(int i=0;i<4;i++){
readcard[i]=rc.uid.uidByte[i]; //storing the UID of the tag in readcard
Serial.print(readcard[i],HEX);
}
Serial.println("");
Serial.println("Now Comparing with Authorised cards");
rc.PICC_HaltA();
return 1;
}
void RFID(){
readsuccess = getid();
if(readsuccess){
int match=0;
//this is the part where compare the current tag with pre defined tags
for(int i=0;i<N;i++){
Serial.print("Testing Against Authorised card no: ");
Serial.println(i+1);
if(!memcmp(readcard,defcard[i],4)){
match++;
}
}
if(match)
{Serial.println("CARD AUTHORISED");
digitalWrite(8,HIGH);
myServo.write(10);
delay(5000);
myServo.write(75);
digitalWrite(8,LOW);
}
else {
Serial.println("CARD NOT Authorised");
digitalWrite(7,HIGH);
delay(2000);
digitalWrite(7,LOW);
delay(500);
}
}
}
void PIR (){
//using the digitalRead function we will read the signal of the sensor
int value = digitalRead(pir);
if (value == HIGH){
digitalWrite(pir_led, HIGH);
delay(500);
}
else {
digitalWrite(pir_led, LOW);}
}
void SWITCH1(){
int switchValue = digitalRead(S);
if (switchValue == 0){
digitalWrite(S1, HIGH);
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
digitalWrite(S4, HIGH);
digitalWrite(S5, HIGH);
}else{
digitalWrite(S1, LOW);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
digitalWrite(S4, LOW);
digitalWrite(S5, LOW);
}}
void SWITCH2(){
int switchValue1 = digitalRead(SS);
if (switchValue1 == 0){
digitalWrite(SS1, HIGH);
digitalWrite(SS2, HIGH);
digitalWrite(SS3, HIGH);
digitalWrite(SS4, HIGH);
digitalWrite(SS5, HIGH);
}else{
digitalWrite(SS1, LOW);
digitalWrite(SS2, LOW);
digitalWrite(SS3, LOW);
digitalWrite(SS4, LOW);
digitalWrite(SS5, LOW);
}
}
PLEASE HELP ME GUYS