Hello there! I am trying to make a solenoid open and close on a press of a button, but it only does something when the button is in the off state, when I press it, it doesn't do anything. I have tested the buttons and solenoid separately and they seem to work fine. I'm thinking that the problem is that I'm not getting enough power, but I don't want to buy anything before I make sure that it's the case.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int buttonPinUp = 11;
int buttonPinLeft = 10;
int buttonPinDown = 9;
int buttonPinRight = 6;
int solenoidPin = 7;
void setup()
{
pinMode(buttonPinUp, INPUT_PULLUP);
pinMode(buttonPinLeft, INPUT_PULLUP);
pinMode(buttonPinDown, INPUT_PULLUP);
pinMode(buttonPinRight, INPUT_PULLUP);
pinMode(solenoidPin, OUTPUT);
int buttonValueUp = digitalRead(buttonPinUp);
int buttonValueLeft = digitalRead(buttonPinLeft);
int buttonValueDown = digitalRead(buttonPinDown);
int buttonValueRight = digitalRead(buttonPinRight);
lcd.init();
lcd.init();
}
void loop()
{
int buttonValueUp = digitalRead(buttonPinUp);
int buttonValueLeft = digitalRead(buttonPinLeft);
int buttonValueDown = digitalRead(buttonPinDown);
int buttonValueRight = digitalRead(buttonPinRight);
if (buttonValueDown = HIGH)
{
digitalWrite(solenoidPin, HIGH);
delay(200);
} else {
delay(200);
digitalWrite(solenoidPin, LOW);
}
}