I had a solenoid from a 24 V relay.
The resistance was 300 ohms, meaning that it would draw less than the 40 mA an Arduino can deliver.
It is an inductive load, so a reverse biased diode must not be forgotten, lest you want to fry your pin!
It is mounted on a stick, hanging over an appropriate edge. Write how many minutes delay you want, upload the code and place your key ring on the magnet.
(If the code is loaded, and the Arduino is powered up, you just push the reset-button to reset the timer)
Once time is up, it drops.
And a bit of code:
Code: Select all
/*
Drop!
Energize an electromagnet for some time, then switch it off to
drop whatever is hanging from it.
Remember to put a free wheeling diode on the coil, and do not power it directly
from the Arduino before making sure, that it will draw less than 40 mA!
(He who ignores this, has deserved to fry his pin!)
Sir Cumference October 2014
*/
const int time = 1; //give time in minutes here
const int finishLED = 8; // to show time is up
const int coilLED = 10; // light when coil is energized
const int coil = 7; // Power for the coil
// the setup routine runs once when you press reset. In this case,
// we just want to run the important parts once, and thus put them in setup.
void setup() {
// initialize the digital pins as an output.
pinMode(finishLED, OUTPUT);
pinMode(coilLED, OUTPUT);
pinMode (coil, OUTPUT);
// coil on, LED on, WAIT, coil off, LED off.
digitalWrite (coil, HIGH);
digitalWrite (coilLED, HIGH);
delay (time * 60000);
digitalWrite (coil, LOW);
digitalWrite (coilLED, LOW);
}
//Loop to say that time is up. I like blinking LEDs.... but it could be empty!
void loop() {
digitalWrite(finishLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a moment
digitalWrite(finishLED, LOW); // turn the LED off by making the voltage LOW
delay(250); // wait for a moment
}
The very important diode!
Safety:
No system is fool proof! Somewhere out there, a new and improved fool is lurking!
- If the power fails, the coil will loose power and drop the key.
- If you power the Arduino from batteries, they will run down, and the key will drop.
(Do the math based on your coil, measurement and battery, then test it to see, if the numbers were right)
- If you power it from a computer, and it enters power save mode, the key will drop... unless you have one of the "always powered"-USB ports.
But strings can tangle, keys drop out of reach, fingers become numb and locks can get stuck. Remember a reliable back-up!