This Arduino Solenoid Tutorial shows how to control a solenoid using pushbuttons and a relay with your Arduino compatible controller. Solenoids are electromagnetically driven actuators. When voltage is applied to the solenoid coil the electromagnetic force pulls the center plunger in. It is an excellent mechanical solution for all kinds of DIY projects requiring short quick linear actuation. Solenoids are most often found in latching and trigger-like mechanisms, such as door locking systems, paintball guns, pinball machines, dot matrix printers, and fuel injectors. Let's get started. Show Step 2: WiringWire everything as shown in the diagram. The photograph shows the correct wiring of one solenoid. All the solenoids will be wired the same. If you only have one solenoid, match the pushbutton and relay numbers when plugging into a pin on the sensor shield (if you plug the pushbutton in on pin 2, plug the relay in on pin 8, 4 - 12, 7 - 13). Step 3: Demonstration Code 1You can find this Demonstration Code in the RobotGeek Libraries and Tools under:
This code simply activates a solenoid while a button is being pressed, and deactivates it once the button is released. This is great for quickly testing your solenoid, but doesn't have much real world application beyond that. Load this code to your arduino with the power to the solenoids unplugged. During the upload, the data transfer can sometimes cause the relays to fire, which can be dangerous if the power to the solenoid is connected. Once the code is uploaded, connect the 6V power supply to the arduino and the 12V power supply to the barrel jacks between the relays and the solenoids.
Step 4: Demonstration Code 2You can find this Demonstration Code in the RobotGeek Libraries and Tools under:
This code activates each relay for a different amount of time. This is the most common way to create a latch or locking mechanism for doors and containers, as it gives the user a set amount of time to react to the latch being unlocked, and then returns to locked position. Load this code to your arduino with the power to the solenoids unplugged. During the upload, the data transfer can sometimes cause the relays to fire, which can be dangerous if the power to the solenoid is connected. Once the code is uploaded, connect the 6V power supply to the arduino and the 12V power supply to the barrel jacks between the relays and the solenoids.
Step 5: So what can you do with a solenoid?The video here shows off the abilities of the large solenoid at different voltage levels. Keep this in mind when designing your project. The small and medium solenoids cannot handle 24V. Please also keep in mind that these solenoids are intended for intermittent use - leaving the solenoid on for extended periods will cause the coil to heat up and possibly damage itself. Do not overtighten bolts in the solenoid frame. While the solenoid is a sturdy device overall, bolts can damage the coil, leaving the solenoid useless. Make sure the bolts do not come into contact with the coil (coil is contained in the black fabric sheath within the metal solenoid frame). We're huge fans of using solenoids in conjunction with RFID. We made a Lock Box kit that has everything you need to get started with that. There are also Solenoid Valves that work on the same principles as our regular solenoids that you can use in a project like the ShotBot to select a liquid source while utilizing a single pump. We hope this has been helpful, and we'd love to hear what you use your solenoids for! |