I have my Arduino UNO set up to digitally control when a magnetic lock is enabled or disabled through digital pins.
I have a digital pin going through a 1M resistor, which lets me have the maglock off while the digital pin is set to OUTPUT, LOW. If it turns to INPUT, HIGH, the maglock will enable. But if I change it from INPUT, HIGH to OUTPUT, LOW, it still holds the charge and won't disable.
groundFungus:
Please post a schematic of your connections and a data sheet for the maglock.
I'm not the best with all the proper names for these things, so hopefully this pic will help.
The mag lock is a 12v with 110mA.
EDIT: Okay, that pic looks like a garbage tangled mess... Hah, sorry. I'm not sure what else to do there.
Essentially I'm powering an 8ch relay with a 12v powersource and the mag lock with a 12v power source. I have ground from one power source going to arduino and the relay. The maglock is connected to the 8th spot with power and ground, with power and ground from a 12v power source as well. The digital pin from Aruidno is going to into the breadboard with a 1M resistor connecting another pin to the relay.
jremington:
Posting the picture was a waste of time. A schematic (hand drawn is OK) is required for us to make sense of your wiring.
Post a link to the magnetic lock.
I don't understand the schematic drawings, which is the problem.
Mag locks we have:
aarg:
The 1M resistor sounds totally wrong. Where did you get that idea?
I just tried different ones until one shut off the lock on the lowest setting, but then it quit working the way I had it, so I'm back to trying different (multiples) ones until it works. But now various digital pins will work and some won't. I miiiight have broke something.
Obviously new and scrambling to understand this type of thing.
I don't understand the schematic drawings, which is the problem.
How hard is it to draw boxes, with pin labels (like digital pins D7 and D8 on the Arduino) and connect the pins with pencil lines? Include lines to POWER and GROUND. A resistor is drawn with a symbol like "_////_".
And post the code to go with the schematic would help, dropping (unlocking) a mag lock is simple - remove voltage, lock releases - apply appropriate voltage lock energises and secures door (or whatever it attaches to)
Does the relay change states when output is low?
Input High or low is only relevant if coded correctly.
JohnLincoln:
Most relay boards are designed to connect directly to an Arduino, without any intermediate components.
Why do you think that an additional 1MΩ (or any other value) resistor is required?
Have you tried a direct connection with no resistor?
I tried a direct connection and whenever I would upload new code changing digitalWrite and/or pinMode for the digital pins under void setup, nothing would happen. But when I added resistors, I could get the lock to turn on from off, just not vice versa.
Everyone else, attempt at schematics incoming.
The code I'm currently using is a simple
void setup(){
Serial.begin(9600);
pinMode(11, INPUT);
digitalWrite(11, LOW);
}
and changing it to OUTPUT/HIGH turns on the mag lock.
That is a pretty poor drawing in general since no pins are specified, but it does show one key problem- that being the logic signal should NEVER go to the switched contacts of the relay. The way you have it drawn (no pin names) has D11? going to the C pin of the relay, which gets switched between 12V and Gnd. Either one will wipe out the arduino, which you might have already done.
My suggestion is to get the relay to operate correctly, effectively cutting your problems in half and generally being safer on the Uno. NO WIRES should be connected to the NC,C,NO pins (Block connector) to do this. After that is working correctly, only then attach the maglock, which will ONLY connect to the block connector. (C,NO terminals). The 12V supply used for the maglock should NOT be connected to the 5V supply for the UNO/relay.
Go to the relay website and look how to hook it up. You will need 3 wires for 1 relay, and one additional wire for every other relay you add in beyond that.
Not 100% sure this is an accurate representation..
I am 100% sure it is rubbish.
This is like trying to ask for advice in Chinese without knowing a word of it.
Look at the LED blink example and use that to turn the relay on and off. You are actually enabling and disabling the 30K internal pull up resistor in that code which is just crazy.
Why are you using INPUT to switch off the lock? Not OUTPUT, LOW? That would at least make sure the port is actually pulled low.
Writing HIGH or LOW to a port that's set to INPUT has no effect whatsoever. It's an input, it's almost as if it's completely disconnected, having little to no effect on what it's connected to.
To be able to toggle a port HIGH or LOW it's got to be an OUTPUT. Just never set it to INPUT when you want to use it as an OUTPUT, which is what you are doing.
Surprised on-one picked up on that yet. It's just odd. That 1M resistor also doesn't sound necessary, and with such a large resistance probably gets in the way of things working well.
I second the other posters about circuit diagrams. Learn how they work, how to read them and how to write them. Without it you have little chance to ever get correct wiring the moment your circuit becomes more complex than a switch, and even in that case it often proves helpful, especially if after a year you look at your project again wondering "how the heck is that wired??".
It has become abundantly clear that you are learning, but don't be discouraged - at least you are asking questions.
While the answers may not solve your problems - they do in fact point you to areas where you should look - and increase your knowledge.
If you don't understand the 'hint', ask a more specific question - that will help you to lean how to ask meaningful questions and get the most from them.
Schematics (not Fritzing) are an absolute fundamental to planning your developments - and to record it for future repairs or expansion.
Just to add a curve to the original solenoid/lock proposition. Don't try this yet until you have figured out the basics...
You can save a lot of power by NOT using a relay to drive the lock.
Use a logic level FET arrangement instead - on a PWM (analog) output, then use 100% drive to 'pull' the lock in for a few mS, and as little as 10% to hold the lock 'on'. Your power supply will thank you!