Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Controlled Miniature Golf Course with Interactive Features

Image of ESP32-Controlled Miniature Golf Course with Interactive Features

Circuit Documentation

Summary

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.

Component List

DRV 8825

  • Description: Stepper motor driver module.
  • Pins: EN, M0, M1, M2, RST, SLP, STEP, DIR, VMOT, GND MOTOR, B2, B1, A1, A2, FAULT, GND LOGIC.

12v Power Supply

  • Description: Provides power to the circuit.
  • Pins: + (positive), - (negative).

Electrolytic Capacitor

  • Description: Used for power supply filtering.
  • Properties: Capacitance: 1 µF (microfarads).

Nema 17 42-STH48

  • Description: Stepper motor used for the windmill rotation.
  • Pins: A2 (black), A1 (green), B2 (red), B1 (blue).

Buck Converter

  • Description: Steps down voltage from the power supply.
  • Pins: IN+, IN-, OUT+, OUT-.

ESP32 (30 pin)

  • Description: Microcontroller used to control the circuit.
  • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3.

IR Sensor

  • Description: Detects the presence of the golf ball.
  • Pins: out, gnd, vcc.

Speaker

  • Description: Outputs sound effects.
  • Pins: +, -.

DFPlayer MINI

  • Description: MP3 player module for playing sound effects.
  • Pins: VCC, BUSY, RX, USB -, TX, USB +, DAC_R, K2/ADC_KEY, DAC_L, K1/ADC_KEY, SPK1, IO 2, GND, SPK2, IO 1.

WS2812 RGB LED Strip

  • Description: LED strip for visual effects.
  • Pins: DIN, 5V, GND, DO.

Wiring Details

DRV 8825

  • VMOT connected to the positive terminal of the 12v power supply.
  • GND MOTOR connected to the negative terminal of the 12v power supply and GND LOGIC to the ground net.
  • RST and SLP connected together.
  • STEP connected to ESP32 pin D13.
  • DIR connected to ESP32 pin D12.
  • Motor pins A1, A2, B1, B2 connected to corresponding pins on the Nema 17 stepper motor.

12v Power Supply

  • Positive terminal connected to VMOT on DRV 8825 and IN+ on Buck Converter.
  • Negative terminal connected to the ground net.

Electrolytic Capacitors

  • One capacitor's positive pin connected to GND MOTOR on DRV 8825, negative pin to VMOT on DRV 8825.
  • The other capacitor's positive pin connected to the ground net, negative pin to RST and SLP on DRV 8825.

Nema 17 42-STH48

  • Connected to DRV 8825 motor output pins.

Buck Converter

  • IN+ connected to the positive terminal of the 12v power supply.
  • IN- connected to the ground net.
  • OUT+ connected to the 5V net.
  • OUT- connected to the ground net.

ESP32 (30 pin)

  • GND connected to the ground net.
  • Vin connected to the 5V net.
  • D13 connected to STEP on DRV 8825.
  • D12 connected to DIR on DRV 8825.
  • D15 connected to the output of one IR sensor.
  • D2 connected to the output of the other IR sensor.
  • D18 connected to DIN on one WS2812 RGB LED strip.
  • D5 connected to DIN on the other WS2812 RGB LED strip.
  • TX2 connected to RX on DFPlayer MINI.
  • RX2 connected to TX on DFPlayer MINI.

IR Sensors

  • Out of one sensor connected to ESP32 pin D15.
  • Out of the other sensor connected to ESP32 pin D2.
  • Both sensors' gnd pins connected to the ground net.
  • Both sensors' vcc pins connected to the 5V net.

Speaker

  • Positive pin connected to SPK2 on DFPlayer MINI.
  • Negative pin connected to SPK1 on DFPlayer MINI.

DFPlayer MINI

  • VCC connected to the 5V net.
  • GND connected to the ground net.
  • RX connected to TX2 on ESP32.
  • TX connected to RX2 on ESP32.
  • SPK1 and SPK2 connected to the speaker.

WS2812 RGB LED Strips

  • DIN of one strip connected to ESP32 pin D18.
  • DIN of the other strip connected to ESP32 pin D5.
  • Both strips' 5V pins connected to the 5V net.
  • Both strips' GND pins connected to the ground net.

Documented Code

/*
 * 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,