Go Down

Topic: Weird LEDs + Servo problems  (Read 213 times) previous topic - next topic

InvalidIP

Hello everyone,

 I'm doing a University project and designing a small parking with a RFID_RC522 for access control and a Micro Servo that controls a barrier (if that's the word you use in English for that). I verified and re-verified my code and connections and can't get the hang of it. The LED together with the buzzer are pinned to a breadboard and since I'm doing testing RED LED, GREEN LED and BUZZER share the same GROUND from POWER "section" of an Arduino UNO.

 When the RFID TAG UID is not stored in the system, we have the RED LED lightning and the buzzer making a "reject" sound.

 When the RFID TAG UID is in the system, the GREEN LED SHOULD light up, a short buzzer beep and the servo does his stuff.

 The thing is, the green LED never turns on - I verified it and it's in working condition (even if I replace the RED LED with GREEN it never lights), some fractions of code:

Code: [Select]

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
 
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 5 //define green LED pin
#define LED_R 4 //define red LED
#define BUZZER 2 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
Servo myServo; //define servo name

void setup()
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(3); //servo pin
  myServo.write(0); //servo start position
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  Serial.println("Put your card to the reader...");
  Serial.println();


...
Code: [Select]
if (content.substring(1) == "XX XX XX XX")
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(180);
    delay(5000);
    myServo.write(0);
    digitalWrite(LED_G, LOW);
  }
 
 else   {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
  }
}


 Else, the system works flawlessly - I'm guessing there is a problem with the delay conflict of the motor and LED or other problem with my code that I'm not aware of. Can someone give me some hints?

 Thank you,
 InvalidIP

septillion

Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

InvalidIP

Ayay, captain!

Code: [Select]
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
 
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 7 //define green LED pin
#define LED_R 4 //define red LED
#define BUZZER 2 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
Servo myServo; //define servo name
 
void setup()
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(3); //servo pin
  myServo.write(0); //servo start position
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  Serial.println("Put your card to the reader...");
  Serial.println();

}
void loop()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "A0 B9 8D 7C")
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(160);
    delay(5000);
    myServo.write(0);
    digitalWrite(LED_G, LOW);

  }
 
 else   {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
  }
}

septillion

Alright, lot of comments but let's start with, what DOES happen when you preset a valid card? You say "no green light" but then I assume no sound and no barrier either? Just a Access denied?

Alright, let's start with the comments :p It would be a heck of a lot faster//easier to just check the uidByte instead of first making it a String...
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

InvalidIP

Well, I'm fine with the string part. So when I have a valid card (stored in the string) I have Authorized access, the buzzer works and the servo works but the green light doesn't want to light up.

septillion

At least if "Authorized access" is printed the (terrible) code doesn't seem to be the problem :) Then move to the electronics, time to post a schematic :)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

InvalidIP

#6
May 15, 2017, 03:52 pm Last Edit: May 15, 2017, 04:18 pm by InvalidIP
Sorry for the delay, kind of busy:

The RFID-RC522 usual layout:

MOSI -> pin 11
MISO -> pin 12
SCK -> pin 13
SS (or SDA) -> pin 10
RST -> pin 9
3.3V -> 3.3V
GND -> GND

The rest (servo, buzzer and 2 LEDs)

LED_G -> pin 7
LED_R -> pin 4
Buzzer -> pin 2
//both LED's GREEN and RED + BuZzer are sharing the same  GND connection to Arduino UNO Ground on POWER "line"
//both LED's have a 220 Ohm resistor added to PIN 7 and PIN 4

 The Servo Orange is connected to Arduino PIN3, POWER to Arduino 5V and GND to Arduino GND on powerstrip.

 Thank you for trying to help septillion.
 The project this far is a clone of https://www.youtube.com/watch?v=3uWz7Xmr55c - I want to add the capSense library also.

septillion

That's not a schematic ;) Because the serial print is done the write to high must be done as well. So I'm still convinced the problem is in how it's connected.

And if it's a clone, why not grab that code?
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

InvalidIP

Well, I don't know what you mean with the serial print.

The code is cloned entirely.

 //I'm doing my miniature parking right now, I'll redo the whole wiring and I will come up with a proper schematic also.

septillion

Well, I don't know what you mean with the serial print.
Code: [Select]

    Serial.println("Authorized access");
    

Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

InvalidIP

Well, today I had a quick lunch break and I had some time left. I remade the whole wiring, this time the other LED stopped working. After I got a little mad I did some striping, soldering and threw away the cheap breadbord who seemed to cause me problems and everything is working as it should.

 So, kids - what have we learned today? Check, check - get mad - do it the "classic" way - everything good.
 @septillion, I will try to improve my string part code, I promise. After everything done I'll post everything on the arduino comunity :)

 Thank you, good luck!

septillion

Hehe, yeah, breadboards are fine for a quick small test but I'm also terrible at using them for bigger projects like Julian Ilett is doing all the time. I always have a bad connection, touching components, errors etc when I do so :p
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Go Up