Advanced RFID System (Uses PIR and Status LED's) - C# .NET source, bs2, schemat
JamesDougherty
Posts: 48
INTRODUCTION
On Friday I picked up some parts for something I want to design and I decided to·do·this as a learning project. I have programmed in basic languages before (PICK/D3 BASIC as an example) so I picked up this flavor all right. Of course there is going to be a learning curve, but that’s half the fun. I’m not going to go and build deep blue anytime soon, but we all have to start somewhere. Anyway, on with the project...
·
PROGRAM OVERVIEW
I read that the power consumption for the RFID Reader was 10 in idle mode and 100 in active mode. There are two ways that I know of to enter these states.
·
1)···· Ground the /ENABLE so it always stays in the active state (consumes constant power)
2)···· Control the idle/active states via the DTR pin on the serial port. However, this still requires that it be done manually.
·
This got me thinking and I knew that I wanted to try a different approach so I fiddled around with the idea of using a PIR sensor. The idea was to leave the RFID Reader in idle mode until motion has been detected. If motion is detected then it will set the RFID Reader to active state. If no tag is detected in the specified amount of time them it will put the RFID Reader back into idle mode. Not only will this save a lot of power consumption, but it is completely automated in changing states. Finally, I have LED’s showing when the system is busy, For instance, I have the PIR sensor go through a warm-up process and during this time the red LED will be light up and when it is finished the green LED will light. Likewise, when the system detects a tag the red LED will light up while the tag data is being processed and then the green LED will light when the processing has completed.
·
C# .NET
I wrote a C# .NET class that handles the serial communications. I originally wrote it specific for the RFID, but I expanded it to allow reading, writing, events, etc. so more projects can be built with minimal effort. I attached a simple program to test it and demo it. If you find any bugs or have any suggestions then please let me know. I wrote this in Visual Studio 2008 Professional, but you should be able to compile/run it in the express edition as well. If you can’t then please let me know and I will change it so it will run. I put some comments in the code, but the documentation is still not 100% done and I apologize for that. Feel free to use the source code anyway you see fit, just leave the copyright in place. This code has been tested, but still may contain some bugs so Ariel Productions has no warrenty at this time.
·
PLEASE READ
It works pretty well and I learned a lot from it. This is my first time doing any BS2 programming, my first time doing any kind of hardware design, my first time doing any circuit board schematics, etc. so please do not be too harsh.
·
I included a picture of what my board looks like with everything in place just in case I messed up the circuit board schematics. Like I said, it was my first time doing this so please let me know if you have any questions.
[noparse]/noparse][b][color=blue]EDIT[/color][/b
I almost forogt... I wanted to use a bi-color LED instead of using two seperate ones, but I don't have one at the moment. This would be easy to change so feel free·
Sincerely,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Post Edited (JamesDougherty) : 1/6/2009 3:28:54 AM GMT
On Friday I picked up some parts for something I want to design and I decided to·do·this as a learning project. I have programmed in basic languages before (PICK/D3 BASIC as an example) so I picked up this flavor all right. Of course there is going to be a learning curve, but that’s half the fun. I’m not going to go and build deep blue anytime soon, but we all have to start somewhere. Anyway, on with the project...
·
PROGRAM OVERVIEW
I read that the power consumption for the RFID Reader was 10 in idle mode and 100 in active mode. There are two ways that I know of to enter these states.
·
1)···· Ground the /ENABLE so it always stays in the active state (consumes constant power)
2)···· Control the idle/active states via the DTR pin on the serial port. However, this still requires that it be done manually.
·
This got me thinking and I knew that I wanted to try a different approach so I fiddled around with the idea of using a PIR sensor. The idea was to leave the RFID Reader in idle mode until motion has been detected. If motion is detected then it will set the RFID Reader to active state. If no tag is detected in the specified amount of time them it will put the RFID Reader back into idle mode. Not only will this save a lot of power consumption, but it is completely automated in changing states. Finally, I have LED’s showing when the system is busy, For instance, I have the PIR sensor go through a warm-up process and during this time the red LED will be light up and when it is finished the green LED will light. Likewise, when the system detects a tag the red LED will light up while the tag data is being processed and then the green LED will light when the processing has completed.
·
C# .NET
I wrote a C# .NET class that handles the serial communications. I originally wrote it specific for the RFID, but I expanded it to allow reading, writing, events, etc. so more projects can be built with minimal effort. I attached a simple program to test it and demo it. If you find any bugs or have any suggestions then please let me know. I wrote this in Visual Studio 2008 Professional, but you should be able to compile/run it in the express edition as well. If you can’t then please let me know and I will change it so it will run. I put some comments in the code, but the documentation is still not 100% done and I apologize for that. Feel free to use the source code anyway you see fit, just leave the copyright in place. This code has been tested, but still may contain some bugs so Ariel Productions has no warrenty at this time.
·
PLEASE READ
It works pretty well and I learned a lot from it. This is my first time doing any BS2 programming, my first time doing any kind of hardware design, my first time doing any circuit board schematics, etc. so please do not be too harsh.
·
I included a picture of what my board looks like with everything in place just in case I messed up the circuit board schematics. Like I said, it was my first time doing this so please let me know if you have any questions.
[noparse]/noparse][b][color=blue]EDIT[/color][/b
I almost forogt... I wanted to use a bi-color LED instead of using two seperate ones, but I don't have one at the moment. This would be easy to change so feel free·
Sincerely,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Post Edited (JamesDougherty) : 1/6/2009 3:28:54 AM GMT
Comments
This got me thinking and I knew that I wanted to try a different approach so I fiddled around with the idea of using a PIR sensor. The idea was to leave the RFID Reader in idle mode until motion has been detected. If motion is detected then it will set the RFID Reader to active state. If no tag is detected in the specified amount of time them it will put the RFID Reader back into idle mode. Not only will this save a lot of power consumption, but it is completely automated in changing states. Finally, I have LED’s showing when the system is busy, For instance, I have the PIR sensor go through a warm-up process and during this time the red LED will be light up and when it is finished the green LED will light. Likewise, when the system detects a tag the red LED will light up while the tag data is being processed and then the green LED will light when the processing has completed.
I like the way you think and how you solved your problem
I like your Project and your ··Very Nice first Project
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
@SRLM - I am still learning all of these terms so I don't know what EE means · If you look at the bs2 source I call low/high enabled, which is actually the /enabled pin on the RFID Reader (I don't do it via the DTR pin). The C# is only a wrapper for the serial port with all of the delegates, error handling, etc. and it is only used to read the output buffer (I mentioned it has the ability to write as well, but that is for future projects). I hope I understood you and if not then I appologize. I am still learning about how all of the components work so I would love if you could explain a little more. Any and all suggestions are great. Thank you.
[noparse][[/noparse]EDIT]
On a side note, don't forget to turn off debug mode in the bs2·before running the C# program. If you have debug mode enabled then it will send that output through the serial which will cause garbage and any tag reads will be ignored. Also, you will most likely receive a port error and possibly a pin changed, which you will see in the message box. So a heads up if you run into this problem (it took me a few hours to track that one down).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Post Edited (JamesDougherty) : 1/6/2009 4:33:36 AM GMT
Anyway, the basic circuit would be something like this:
The first half (left side) inverts the signal, since the PIR outputs high when it senses, and the RFID need a low to be active. The second half amplifies the signal. I tried it without the inverter, but I only got 2.8 v from the output. My poor circuit design speaking, or something else? As a side note, the jumper on the PIR allows you to choose a cycle action when it detects: this could be used to save even more power if you're willing to (possibly) hold the card up a little bit longer.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Post Edited (soshimo) : 1/6/2009 7:57:20 PM GMT
The 2N3904 is NPN so it would get triggered when the base is high relative to the emitter. The emitter is always 0 since it is grounded so this transistor should always get triggered anytime motion is detected like you thought (since the PIR put out HIGH like you said). Since the 2N3906 is PNP it will be triggered when the base is low relative to the emitter. So when it gets triggered the emitter will push the +5v needed to the collector, which in turn triggers the RFID.
Like I said, this could be completely wrong since I am still learning, but it works in my mind
@soshimo - I'm on my second pot already and I still can't get with it
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
The circuit works when I don't have the PIR in there: I used a jumper between the PIR input on the left and 5V or Ground. When I did, it worked well. However, when I put the PIR in there, it began to cycle high-low with about a 1 second interval between changes, regardless of local motion. I may fiddle some more later...
Almost forgot... There is a timeout for the RFID reader. If no tags are detected then it will go back to idle mode to help save the consumption. The default was set at two seconds... You could try increasing this and seeing if that helps as well. Like I said, tomorrow I will have some free time so I will try some configurations as well. I need to swing by radio shack tomorrow and get some resistors (like the PN2222, 2N2222, etc.)
Have·a good night SRLM.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
I knew about the jumper, just forgot to check it. I think it's set on the hold high, but I'm not sure (I messed around with it some yesterday). Anyway, the warm up period might be part of the problem. I immediately tried to use it as expected, without giving it the warm up time. That may be the problem.
By the way, this is a completely hardware level solution, so there are no PAUSE statements (no code at all in fact).
I'm not quite sure where you got the RFID reader timeout from. If it's in the code, than that's not an issue here. I looked in the datasheet, and there wasn't anything mentioned. A quick hardware test verified that the RFID reader does not have any built in timeout. Try it: hook up VCC, ground, and tie the enable pin to ground. The red light stays on as long as the power is applied.
I think you mean transistors? [noparse]:)[/noparse]
As a side note, one reason why I'm so interested in this is because the PIR would make a nice simple, hardware type project. I was thinking hooking it up to an LED and battery, and have a simple motion detector. It could also be used (for example) to turn on a light when somebody enters a room (via a relay) with no microcontroller. That part is the interesting bit: by cutting the costs $30 or so, more projects open themselves up. Plus, I just want to practice my soldering...
Thats funny you mention that about the lights because I was wanting to try that as well. ·I have not done much soldering either, but I am going to pick up some copper CAD and some etching liquid while I am at Radio Shack today so I can make a little board so I can A) make my first board and sharpen my soldering skills. It's not that hard at all to created a PCB using the toner transfer method so I figured I would give it a shot.
@soshimo - I was kind of weary about that too. God only knows what I am going to burn down or blow up. However, I have some flood lights on my garage that I was thinking about tearing down and tearing apart just to see how they handled the voltage. Giving power straight to the light bulbs is a no brainer, but there has to be some kind of processor in it since it has a timer, the PIR, etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
As I mentioned before, the hardware solution doesn't have timeout, unless you count the emergent behavior when you stay still for a while. So no serin timeout. If you want to implement it, I'd say just stick with code, since I'm guessing hardware timeouts will be a pain (555 timer chip or capacitor probably). Still, I like doing stuff in hardware, since there's less code to worry about getting right (plus, it looks more 'techie' [noparse]:)[/noparse].
I went to Radio Shack today and bought some parts so I can play around with this, but now I just need more time Have you seen this link? Check out the "Time Delay Circuits" section. I think it may have potential if you replace the switch with the PIR output. http://home.cogeco.ca/~rpaisley4/LM555.html#20
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
·Please Keep us posted how your testing going with ....>>>>>>>>>
I like the idea of using the ......>>>>>>PIR to turn the RFID reader on and off.
I would like to do something like this my self
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
To test it I used this (the RFID SOUT is on PIN 0):
What is making this so sensitive? Even after the warmup and zero movement it doesn't help
Is there noise (or other disturbance)·in the line that would cause it? I will have to play around with·a timer or something and see if I can't adjust the sensitivity some how. On the flood lights I have there is a sensitivity knob on it. Do you think there is a timer delay·on it that would be something like "If the PIR outputs high for this amount of time then there is positive movement, otherwise it must be a false positive"? Now all we need to do is figure out the sensitivity...
[noparse]/noparse][b]EDIT[/b
soshimo, do you know those poppers you buy around New Years where you pull the string? You should have one of those inside of a ghost or pumpkin and when it detects someone have it kick on a servo to pull the string. That will surely get their attention (they will probably think you are shooting at them or something so maybe you better not LOL)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Post Edited (JamesDougherty) : 1/8/2009 5:06:10 AM GMT
I think I found the problem: when in normal operation, the PIR outputs about 3.3 volts. When hooked up to my transistor circuit shown above, the PIR outputs about 2.2 volts. My guess is that it's drawing too much current. So, I increased the 2kOhm resistor to 10kOhm. Also, I made sure the jumper was in on the H side. When built like this, the circuit works perfectly.
I found that the PIR requried a warmup of about 30 s, so I placed an open book over the module and sat still. Eventually, it settled at no motion. I then removed the book, and waved my hands: Solid red light on the RFID module! Whoho! Once I sat still for a moment, it turned green for about 1s, turned red for about 1s, and then back to green solid. Further tests with the module continuously on did not duplicate this action, so I'm assuming that the PIR has some sort of built in learning over time.
@Sam:
When I get a chance tomorrow(maybe Friday[noparse]:)[/noparse], I'll solder up a small circuit that will toggle a pair of LEDs and post it with the circuit in the completed projects forum. You should be able to replace the LEDs with whatever you want to drive.
On a slight side note, when measuring a resistor with my multimeter to find its value (10 kOhm listed) I got a perfect score: 10.00. No variance! I think this deserves a drink [noparse]:)[/noparse]
1) It seems to work best when the first 30 seconds or so it is covered with a still object. I noticed that without this 'perfect' warm up the PIR was delayed several seconds when changing states. This tendency may disappear over time.
2) The PIR has built in sensitivity training. It waits a minimum of about 1/2 second (guess) before it changes states (either from LOW to HIGH or HIGH to LOW). This should eliminate the need for a 555 sensitivity timer.
3) The only resistor value that appears to matter is the 10 kOhm on the base of the transistor. The other value I tried at 2kOhm and 220Ohm and it still works (for an LED and buzzer)
I built one of those yesterday. Yup, it's pretty interesting.
A word of warning - there's a dead-end trace (mistake) in the board files provided for that story (it's supposed to go to the diode). I sent them up to BatchPCB (Sparkfun's service), and later got an email from someone there pointing out the problem and asking if I wanted corrected versions. He did send me good working boards, and told me that the person who wrote that tutorial plans to upload corrected versions soon. Of course you could correct it yourself as well.
I am curious though as to what the advantages/disadvantages are to using the transistors and resistors versus just going straight from the output on the PIR? It works both ways that's why I am curious.
I still want to play around with it some to try and come up with a sensitivity setting for it like to lights have. I have a big business meeting/project coming up so I won't be able to play with it till this weekend, but until then I will research it. However, one thing that did cross my mind was the lights... When the PIR detects motion it triggers the RFID Reader to go into active state. When this happens the LED changes to RED which could trigger the sensor into thinking there was motion. I wonder if this could be one of the things causing the PIR to "toggle" the output. I wonder if it would help to put something in between the PIR and the RFID Reader so·the PIR doesn't see the light.
I did a quick little google and I found a PIR·Controller Chip that has a pin just for sensitivity. The·chip is the KC778B·and you can buy the chip and PIR separately, but they also have a board with the chip already in place.
Take a look here: http://www.electronics123.com/s.nl/it.A/id.72/.f
Here is the board: http://www.electronics123.com/s.nl/it.A/id.408/.f
Do you know if Parallax has any chips like this?
[noparse]/noparse][b]EDIT[/b This is interesting... I took a look at the data sheet for that chip and there is an anti-alias on it to filter the noise like (kind of what I was thinking).·Here is the datasheet for it http://www.electronics123.net/amazon/datasheet/kc778b.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Post Edited (JamesDougherty) : 1/8/2009 2:24:15 PM GMT
This would be great Thanks
@Sam:
When I get a chance tomorrow(maybe Friday[noparse]:)[/noparse], I'll solder up a small circuit that will toggle a pair of LEDs and post it with the circuit in the completed projects forum. You should be able to replace the LEDs with whatever you want to drive.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (soshimo) : 1/9/2009 6:32:08 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
Indeed. I should have posted the link to it, sorry.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Manetheren