I am currently needing help creating my feeder project. I want to be able to have an arduino read a RFID chip (RFID-RC522) that simply outputs a number (e.g. 5) then once read, a small dc motor will start running (allowing feed to be dispensed, in our case BBs) that will be counted using a IR break beam (IR sensor is a Omron 1070). Once the IR break beam count matches that which is outputted by the RFID, the motor will then stop.
So far I have the break beam counting every 6ms and outputting the number of times the IR beam was broken during that time as a continuous loop. I still cannot seem to implement the RFID code samples and motor code examples I have found into this.
int motorPin = 3; //motor connected to digital pin 3
int ledPin = 13; // LED connected to digital pin 13
int photoPin = 4; //
int val = 0;
int valold = 0;
int start;
unsigned int count = 0;
void setup() // run once, when the sketch starts
{
pinMode(motorPin, OUTPUT);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(photoPin, INPUT);
valold = digitalRead(photoPin);
Serial.begin(9600);
}
void loop() // run over and over again
{
start = millis(); // take the start time
count = 0; // reset couter
while (millis()-start < 6) // do the following loop for 6ms
{
// check for overflow of millis()
if (start > millis()) {
start = millis();
count = 0;
}
val = digitalRead(photoPin);
if (val==LOW)
{
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, HIGH);
if (val > valold) {
count ++;
valold = val;
}
}
}
// 6 ms over. print conts
Serial.print("BBs counted: ");
Serial.println(count,DEC);
}
Elvert:
I still cannot seem to implement the RFID code samples and motor code examples I have found into this.
Do the RFID an motor control examples work separately?
If so, Are there any pin conflicts between the three pieces of hardware?
What RFID hardware are you using? What motor control hardware are you using?
The RFID chip is a (RFID-RC522). The motor is simply a small 6V DC motor (two wires. one power, one ground).
I added the RFID software to my arduino library (rdif-master is the folder). I got it from a tutorial link on the same RFID chip that I have. The code attached is the code for reading and writing for the rfid chip. I used the manufactured spec sheet to wire it properly and the program works all on its own but I do not know how to us it. Just that it detects the rfid.
As for the motor the only way I have wired it is simply through a digital pin for power and then grounded it. For the code I simply turned the power HIGH and LOW to that digital pin.
I also attached the code that I am currently using to count when the IR sensor beam is broken.
Elvert:
As for the motor the only way I have wired it is simply through a digital pin for power and then grounded it.
You need to stop doing that, for either or both of these reasons:
The motor probably draws too much current for a digital pin
The back emf when the motor stops will damage the pin
You need to connect the motor something like this which uses the pin to control a transistor which controls a separate power supply, and uses a diode to handle the back emf.
Note that your RFID is wired to pins 9, 10, 11, 12, and 13. You can't also use Pin 13 for an LED output and expect the RFID to work. Add an external LED and resistor to some other output pin so your existing code and your RFID code can work together.
The RFID example is supposed to do reading and writing. Study that example until you understand how to write what you want on the RFID tag.
As mentioned above, you need some kind of motor driver hardware. The Arduino pins can only source an ABSOLUTE MAXIMUM of 40 mA. Better to keep it below 30 mA. The USB power input is limited to 500 mA which leaves about 450 mA for your motor if you use USB power. If the motor draws more than that the Arduino will turn off.