My electronic knowledge is very minimum. Got confuse with this simple circuit and don't know how to fix it.
When using short wire (before connected to door bolt), everything is fine. If wire 1 and wire 2 connected then LED will be turn on very bright and GPIO 39 turn HIGH. When wire 1 and wire 2 disconnect, then LED will be turn off and GPIO 39 turn LOW.
Problem start when using long wire (around 5 meter) to connect to door bolt. Although wire 1 and wire 2 doesn't connect, but LED always turn on (only dim, not very bright as when wire 1 and wire 2 connected) and GPIO 39 always turn HIGH.
Southpark:
Please define or show 'wire 1' and 'wire 2'. After typing your post - please read through it, and make sure that all the details are clear. Also - I assume that GPIO 39 is going to be used as an input, right?
The details of wire 1 and wire 2 are very clear in the image attached above (red arrow with number 1 and 2).
You are right, GPIO 39 used as an input. Please see the image attached above, I draw all the details on that image.
The long wire effectively acts as an antenna. I would try two things:
Twist as much of the "long wires" together as is practical. This may be accomplished by stretching equal lengths of the wires, putting one end in a drill, and spinning the drill until there is one complete turn of the wire every 2 cm or less. The potential issue this addresses is the long wire loop acting as an antenna picking up magnetic fields. Twisting the wires together makes the wire less antenna-like.
Use a lower value resistor for R1, say 1k Ohm. The lower value resistor will dissipate more random energy that the long wire picks up so that it doesn't go through the LED.
As an aside, while the schematic in the original post is a bit unconventional, it is clear and nicely done. Using the Door Bolt as a switch is an interesting idea.
wieb:
The details of wire 1 and wire 2 are very clear in the image attached above (red arrow with number 1 and 2).
You are right, GPIO 39 used as an input. Please see the image attached above, I draw all the details on that image.
Thanks. The details were there, it is true. But it wasn't immediately clear until I had a closer look, after I eventually noticed the numbers '1' and '2' there.
Also - your code. Please post your code. Are you using - pinMode(39, INPUT); ?
MrMark:
The long wire effectively acts as an antenna. I would try two things:
Twist as much of the "long wires" together as is practical. This may be accomplished by stretching equal lengths of the wires, putting one end in a drill, and spinning the drill until there is one complete turn of the wire every 2 cm or less. The potential issue this addresses is the long wire loop acting as an antenna picking up magnetic fields. Twisting the wires together makes the wire less antenna-like.
Use a lower value resistor for R1, say 1k Ohm. The lower value resistor will dissipate more random energy that the long wire picks up so that it doesn't go through the LED.
As an aside, while the schematic in the original post is a bit unconventional, it is clear and nicely done. Using the Door Bolt as a switch is an interesting idea.
Thank you very much MrMark for the suggestion, I will try change R1 with 1K or less ASAP.
Southpark:
Thanks. The details were there, it is true. But it wasn't immediately clear until I had a closer look, after I eventually noticed the numbers '1' and '2' there.
Also - your code. Please post your code. Are you using - pinMode(39, INPUT); ?
Hello,
The door bolts that I have seen are coated with a
substance to keep the finish bright and shiny. That
is probably an insulator. Also, a door bolt is not an
electrical switch, so there is no guarantee that it
will ever function as one.
Herb
herbschwarz:
Hello,
The door bolts that I have seen are coated with a
substance to keep the finish bright and shiny. That
is probably an insulator. Also, a door bolt is not an
electrical switch, so there is no guarantee that it
will ever function as one.
Herb
Thank you herbschwarz for the answer.
You are right, the door bolts are coated with a substance to keep the finish bright and shiny. But the substance is not insulator.
I am already try connected the wire with door bolt. And the door bolt works perfectly as an electrical switch. When bolt in locked condition then LED will turn on very bright.
The problem is when in unlocked condition, LED still turn on (only dim, not very bright as when in locked condition) and GPIO 39 always HIGH (never turn LOW because using long wires and too big pull down resistor R1 10K). Will try ASAP change R1 with smaller 1K or less pull down resistor, hope it will be solve this issue.
While I agree that long wires are more of a design challenge it should not stop you from using them if the application requires them.
Two suggestions (actually both the same)
What gauge are your wires?
To prove if the length is a resistance or interference based:
Coil you wires up tightly and operate your circuit with the deadbolt. If the "antenna" effect is your problem it should go away (or at least be minimal) with he wires all coiled up. If you want to be really sure the coiled wire is not picking up something, wrap them in aluminum foil and ground the foil.
As a general rule, you should protect inputs from voltage spikes (esd etc) a 0.1µF across the 10K and a 5k in series with the input pin (at the board) will help also.
It would be good to know what voltage is on wire 2. If you don't have a Digital Voltmeter, get one. You can get one from Banggood for less than $10.
What material is the door bolt attached to? Could it be slightly conductive? Physically remove Wire 1 OR Wire 2 from the door bolt. Does the LED go off? If Yes, then the material the door bolt is attached to may be slightly conductive.
Personally, I would use an analog input. If the wire length is the problem and the digital input is too low to be reliable due to the wire resistance, you can use the analog input to detect if the bolt is closed.
However, I have never used this board, but if your wiring diagram is accurate, then it shouldn't work at all. The pin that you labeled as 5V is GPIO12, GND is Vin, and your label GPIO39 is GPIO17.