Just finished a project, a custom made real life game with an object that spits water out of 3 pipes which people need to catch as much as possible in one minute. The water is controlled by solenoids and the script written with great help of ChatGPT. I would like to share
1: The code
2: the movie
3: a drawing from this forum used to make the components on the board. Note: the extra ground is added by me.
Hope to inspire you and feedback is welcome. Quistons and ask for help of your project is also welcome. I am not experienced with electronics, but technically with a lot of knowledge and vision. If you use the information to share outside this platform would be great, but pleas give credits to WaterLeider.nl to keep our community alive
p.s. I used a 12volt battery, very small with 7Ah so the thing can run several days
Blokcitaat
const int solenoidPins[] = {2, 4, 7}; // Pins connected to solenoid valves
const int numValves = 3; // Number of solenoid valves
const long gameDuration = 75000; // Game duration in milliseconds (75 seconds)
const long initialWait = 15000; // Initial wait time before game starts (15 seconds)
void setup() {
for (int i = 0; i < numValves; i++) {
pinMode(solenoidPins[i], OUTPUT);
digitalWrite(solenoidPins[i], LOW); // Ensure solenoids are off initially
}
Serial.begin(9600);
}
void loop() {
Serial.println("Game starting in 15 seconds...");
delay(initialWait); // Initial wait before game starts
unsigned long gameStartTime = millis();
while (millis() - gameStartTime < gameDuration) {
int valveIndex = random(numValves);
int openDuration = random(500, 3001); // Random open duration between 0.5 and 3 seconds
int breakDuration = random(2000, 6001); // Random break duration between 2 and 6 seconds
// Open selected valve
digitalWrite(solenoidPins[valveIndex], HIGH);
delay(openDuration);
// Close the valve
digitalWrite(solenoidPins[valveIndex], LOW);
delay(breakDuration);
}
Serial.println("Game over");
while(true); // Stop the loop after the game is over
}
Blokcitaat
