This circuit is designed for a miniature golf course project featuring interactive elements. It includes a stepper motor to rotate a windmill obstacle, two IR sensors to detect the presence of a golf ball, two LED strips for visual effects, an MP3 player for sound effects, and a power supply system. The ESP32 microcontroller serves as the central processing unit, controlling the stepper motor, reading sensor inputs, driving the LED strips, and communicating with the MP3 player.
/*
* Miniature Golf Course Project
* This Arduino Sketch controls a miniature golf course with interactive features
* including LED runway lights, a rotating windmill obstacle, and sound effects.
* Hardware Components:
* - ESP32 microcontroller
* - Stepper motor and driver
* - Two IR sensors
* - Two LED strips
* - MP3 player
* - Power supply
* - 3D-printed windmill rotor
*/
#include <Adafruit_NeoPixel.h>
#include <Stepper.h>
#include <DFPlayerMini_Fast.h>
#define DIR_PIN 12 // Direction pin connected to ESP32 D12
#define STEP_PIN 13 // Step pin connected to ESP32 D13
#define IR_SENSOR1_PIN 15 // IR sensor 1 connected to ESP32 D15
#define IR_SENSOR2_PIN 2 // IR sensor 2 connected to ESP32 D2
#define LED_STRIP1_PIN 5 // LED strip 1 connected to ESP32 D5
#define LED_STRIP2_PIN 18 // LED strip 2 connected to ESP32 D18
#define MP3_RX_PIN 16 // MP3 RX pin connected to ESP32 RX2
#define MP3_TX_PIN 17 // MP3 TX pin connected to ESP32 TX2
#define NUM_LEDS 30 // Number of LEDs in each strip
bool ROTATING_ACTIVE = false;
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LEDS, LED_STRIP1_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS, LED_STRIP2_PIN, NEO_GRB + NEO_KHZ800);
DFPlayerMini_Fast myMP3;
void setup() {
pinMode(DIR_PIN, OUTPUT); // Set direction pin as output
pinMode(STEP_PIN, OUTPUT); // Set step pin as output
pinMode(IR_SENSOR1_PIN, INPUT); // Set IR sensor 1 pin as input
pinMode(IR_SENSOR2_PIN, INPUT); // Set IR sensor 2 pin as input
strip1.begin(); // Initialize LED strip 1
strip2.begin(); // Initialize LED strip 2
strip1.show(); // Initialize all pixels to 'off'
strip2.show(); // Initialize all pixels to 'off'
Serial.begin(9600);
myMP3.begin(Serial2, MP3_RX_PIN, MP3_TX_PIN);
myMP3.volume(30); // Set volume to max (0 to 30)
}
void loop() {
if (playerAtStart()) {
runwayLights();
} else {
solidBlueLights();
}
if (!ROTATING_ACTIVE) {
rotateWindmill();
}
if (ballInHole()) {
playSoundEffect();
flashLights();
}
}
void runwayLights() {
for (int i = 0; i < NUM_LEDS; i++) {
strip1.setPixelColor(i, strip1.Color(0, 0, 255)); // Blue color
strip2.setPixelColor(i, strip2.Color(0, 0, 255)); // Blue color
strip1.show();
strip2.show();
delay(50);
strip1.setPixelColor(i, strip1.Color(0, 0, 0)); // Turn off
strip2.setPixelColor(i, strip2.Color(0, 0, 0)); // Turn off
}
}
void solidBlueLights() {
for (int i = 0; i < NUM_LEDS; i++) {
strip1.setPixelColor(i, strip1.Color(0, 0, 255)); // Blue color
strip2.setPixelColor(i, strip2.Color(0,