Advertisement
microrobotics

DIY Flux Capacitor

Apr 26th, 2023 (edited)
1,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's a complete guide to creating a decorative replica of the flux capacitor with a web server interface to control the LED sequence and play simple sound effects using an ESP32:
  3.  
  4. Project Requirements:
  5.  
  6. ESP32 development board
  7. WS2812B RGB LEDs (x17)
  8. Breadboard or custom PCB
  9. Jumper wires
  10. Speaker or buzzer
  11. Power supply (5V, 2A recommended)
  12. Software Requirements:
  13.  
  14. Arduino IDE with ESP32 support
  15. FastLED library for LED control
  16. ESPAsyncWebServer library for web server support
  17. AsyncTCP library for web server support
  18. Steps:
  19.  
  20. Set up the Arduino IDE with ESP32 support by following the instructions here: https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
  21. Install the FastLED library in the Arduino IDE by going to Sketch > Include Library > Manage Libraries... and searching for "FastLED". Install the latest version.
  22. Install the ESPAsyncWebServer and AsyncTCP libraries by following the instructions here: https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
  23. Connect the components as follows:
  24. Connect the data pin of the first WS2812B LED to pin 14 of the ESP32.
  25. Connect the speaker or buzzer to pin 27 of the ESP32.
  26. Connect the 5V power supply to the 5V and GND pins of the ESP32, the WS2812B LEDs, and the speaker/buzzer as required.
  27. Connect the data out pin of each LED to the data in pin of the next LED to form a chain of 17 LEDs.
  28.  
  29. Once you have accessed the web server using the "/toggle_leds" URL, the ESP32 will toggle the 17 RGB LEDs in sequence and play simple sound effects using the connected speaker or buzzer. You can customize the LED colors and sound effects in the code as needed.
  30.  
  31. Please note that the provided code plays simple tones as sound effects. If you would like to play more complex sound effects, consider using a dedicated audio playback module such as the DFPlayer Mini in combination with the ESP32.
  32.  
  33. This project gives you a basic setup to create a decorative replica of the flux capacitor with a web server interface. You can further enhance the project by adding features like customizable LED colors, sound effects, or even integrating it into a custom enclosure to make it look more like the flux capacitor from the "Back to the Future" movies.
  34.  
  35. Upload the following code to the ESP32 using the Arduino IDE:
  36.  
  37.  
  38. */
  39.  
  40. #include <FastLED.h>
  41. #include <WiFi.h>
  42. #include <AsyncTCP.h>
  43. #include <ESPAsyncWebServer.h>
  44.  
  45. const int LED_PIN = 14;
  46. const int SPEAKER_PIN = 27;
  47. const int NUM_LEDS = 17;
  48.  
  49. const char* ssid = "your_SSID";
  50. const char* password = "your_PASSWORD";
  51.  
  52. CRGB leds[NUM_LEDS];
  53. AsyncWebServer server(80);
  54.  
  55. void setup() {
  56.   // ...
  57.   while (WiFi.status() != WL_CONNECTED) {
  58.     delay(1000);
  59.   }
  60.  
  61.   Serial.begin(115200);
  62.   Serial.print("IP address: ");
  63.   Serial.println(WiFi.localIP());
  64.  
  65.   setupServer();
  66.   server.begin();
  67. }
  68.  
  69.  
  70. void setupServer() {
  71.   server.on("/toggle_leds", HTTP_GET, [](AsyncWebServerRequest *request) {
  72.     // Change the LED sequence
  73.     for (int i = 0; i < NUM_LEDS; i++) {
  74.       leds[i] = CRGB::White;
  75.       FastLED.show();
  76.       delay(100);
  77.       leds[i] = CRGB::Black;
  78.     }
  79.  
  80.     // Play the sound effect (simple tones)
  81.     for (int i = 0; i < 3; i++) {
  82.       tone(SPEAKER_PIN, 1000, 100);
  83.       delay(200);
  84.     }
  85.  
  86.     request->send(200, "text/plain", "OK");
  87.   });
  88.  
  89.   server.onNotFound([](AsyncWebServerRequest *request) {
  90.     request->send(404, "text/plain", "Not found");
  91.   });
  92. }
  93.  
  94. void loop() {
  95.   // Nothing to do here
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement