Hi everyone,
I am doing a vending machine project and have been trying to program the complete codes for it. Everything seems to work fine with the codes except for the solenoid. I am using 3 12V/300mA solenoids controlled by a relay module connected to a UNO Arduino board. My main purpose for using the solenoids is to simply turn them on and off with a little delay time in between those states when the machine "knows" whether if there is a $2, $1 or 25cent is inserted in. My first assumption is to use the "delay" function in between to have it remained activated for 2 seconds and deactivate it.
I am only trying connecting 1 solenoid to the circuit at a time. When I tested it, it only "flinched" for a split second, not fully extended nor remained extended for 2 seconds. It confused me because when I tested the solenoid separately with a short, simple code turning it on and off with delay function and it worked as expected. But, when assembled it with the rest of the code, the delay function was just simply being ignored and the solenoid only "flinched" a bit. There might be some silly, clumsy newbies programming errors that I made in the code since I am not an expert in programming.
I only post a piece of code contains the solenoid control part in it since the whole program is very long and eye-tiring to read. I will post more codes if requested for further discussion. I have also provided links below to the solenoids and relay module that I am using for this project for more information.
All help and responses are greatly appreciated. Thank you.
else if((36 < delta_T) && (delta_T < 50) && (y == 3)) // If calculated delta time falls in 36ms - 50ms range
{
Serial.print("25c slot open"); // Then prints out "25c slot open" to Serial monitor
Serial.println();
Serial.println();
digitalWrite(slot_25c, HIGH); // Activate 25c solenoid to open the slot
delay(2000); // Wait for 2s for the coin to fall into the slot
digitalWrite(slot_25c, LOW); // Deactivate 25c solenoid
lcd.clear(); // Print out on LCD how much money has been inserted
lcd.setCursor(0,0);
lcd.print("$");
lcd.setCursor(1,0);
lcd.print(total);
lcd.setCursor(6,0);
lcd.print("Inserted");
total = total + 0.25; // Calculate the total money has been inserted
y = 1; // Reset the condition
delay(500);
}