Hi,
my overall goal is to make a platform controlled by 2 solenoids (product: https://www.adafruit.com/products/412) on a timer (one pushes, holds for 5min pulls back, and then another pushes and holds, comes back) all controlled by one button when turned on. My solenoid uses a 12V DC external wall converter plugged into the barrel jack.
However, im having an issue with the large 12V solenoid I am using. Im using this schematic i’ve drawn up and attached here. It works completely fine when i use a USB cable for 5V on a tiny 5V solenoid (product: Mini Push-Pull Solenoid - 5V : ID 2776 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits). the solenoid pushes out when i hit the button, and comes back when i hit the button again. works like a charm. But when i try using my big 12V solenoid with the external power supply, its like the button doesnt fully function. I press it, the solenoid goes out sometimes, or it doesnt come back, or it flickers in and out. its not functioning the right way. Any ideas? my guess is that im using wrong resistors or something but im not sure whats going on.
DISCLAIMER: my schematic is not drawn perfectly. Im using a TIP120 transistor, 1N004 diode, 10k resistor for the button, 1k resistor for the solenoid, and NO 9V BATTERY. either USB or 12V DC depending on the size solenoid. THis works good for the 5V small one, not the 12V big one.
// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int solenoidPin = 13; // the number of the LED pin// Variables will change:
int solenoidState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin// the following variables are long’s because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 20; // the debounce time; increase if the output flickersvoid setup() {
pinMode(buttonPin, INPUT);
pinMode(solenoidPin, OUTPUT);// set initial LED state
digitalWrite(solenoidPin, solenoidState);
}void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you’ve waited
// long enough since the last press to ignore any noise:// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it’s been there for longer
// than the debounce delay, so take it as the actual current state:// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
solenoidState = !solenoidState;
}
}
}// set the LED:
digitalWrite(solenoidPin, solenoidState);// save the reading. Next time through the loop,
// it’ll be the lastButtonState:
lastButtonState = reading;
}