Hi. I wonder if someone could help me. My project is very simple. I connected my arduino to a voltage source and it turns off a vibration motor whenever it detects an external voltage and turns it on whenever it doesn't. I use this to remove bubbles from an electrolytic cell. Everything works fine except at the end of the process when I need to safely dismantle the cell (I use hydrofluoric acid as electrolyte) and I need the motor to stop vibrating. The easiest thing to do was just to unplug a jumper from the board but I thought I could do something better and I thought I could add a push button to abort the process whenever I need. I've been searching the internet for solutions and I've seen plenty but none is working for me. The only thing I could get was to send the digitalWrite to a low when I press the button but as soon as I remove my finger it goes back to HIGH. So in short, I just want my current program to send my digitalWrite from HIGH to LOW whenever I press a button but I want it to stay LOW after removing my finger. I hope you can help me. Thank you so much. I'm also attaching a diagram of my set up (not totally accurate) but it might be that I'm not even plugin the button in a proper way?.
const int boton = 2;
float entrada;
const int motor = 9;
int estado_boton = 0;
void setup() {
pinMode(motor, OUTPUT);
pinMode(boton, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
entrada = analogRead(A0);
estado_boton = digitalRead(boton);
if(entrada > 100 || estado_boton == HIGH) {
Serial.println(entrada);
digitalWrite(motor, LOW);
}
else if (entrada < 200) {
Serial.println(entrada);
digitalWrite(motor, HIGH);
}
}