Create a spooky Halloween pumpkin using a UNO R4 WiFi, Modulinos, an mp3 module and an 8 ohm speaker.
Devices and components
40 colorful male-male connection wires
Arduino® UNO R4 Wi-Fi
Box 525 Resistors precision 1% - 17 values
Arduino plug and make kit
DFPlayer - A mini MP3 player
Powerbank
Diode 1N4007 1A 1000V
Mini bread board - White
3 ohm 0.5 W speaker
Micro SD card module (generic)
Software and tools
Arduino Cloud Editor
Project description
Project description
Circuit
220 Ohm resistance for TX line.
10K Ohm resistor for A0 line.
Connect the diode with the silver strip to the resistor.
Code model
Download audio
Dashboard
References
Halloween
The code uses the Arduino Cloud functionality.
1#include "thingProperties.h"
2#include "DFRobotDFPlayerMini.h"
3#include <Modulino.h>
4#define MP3_SERIAL Serial1
5ModulinoPixels leds;
6ModulinoDistance distance;
7DFRobotDFPlayerMini player;
8bool playCooldown = false;
9int distanceNow = 0;
10unsigned long lastPlay = 0;
11unsigned long lastChecked = 0;
12void setup() {
13 Modulino.begin();
14 distance.begin();
15 leds.begin();
16 MP3_SERIAL.begin(9600); // DFPlayer Mini expected baud rate
17 Serial.begin(9600);
18 delay(1500);
19 pinMode(A0,INPUT);
20 if (player.begin(MP3_SERIAL)) {
21 Serial.println("OK");
22 player.volume(30);
23 } else {
24 Serial.println("Connecting to DFPlayer Mini failed!");
25 }
26 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
27 delay(1500);
28 // Defined in thingProperties.h
29 initProperties();
30 // Connect to Arduino IoT Cloud
31 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
32 setDebugMessageLevel(2);
33 ArduinoCloud.printDebugInfo();
34}
35void loop() {
36 ArduinoCloud.update();
37 delay(25);
38 // Your code here
39 if(playCooldown && lastPlay+7000<=millis())
40 {
41 playCooldown = false;
42 Serial.println("Cooldown ended");
43 }
44 distanceNow = CheckDistance();
45 Serial.println(distanceNow);
46 if(!playCooldown && distanceNow > 20){
47 player.play(laugh_sound);
48 people_scared++;
49 playCooldown = true;
50 lastPlay = millis();
51 Serial.println("Cooldown started");
52 }
53 if(playCooldown)
54 {
55 int brightness = map(analogRead(A0), 0, 1023, 0, 240);
56 for (int i = 0; i < 8; i++) {
57 leds.set(i, RED, brightness); // Set the first eye
58 leds.show();
59 }
60 }
61}
62int CheckDistance (){
63 if (distance.available()) {
64 int measure = distance.get();
65 return measure;
66 }
67 else{
68 int measure = 0;
69 return measure;
70 }
71}
72void onLaughSoundChange() {
73 // Add your code here to act upon LaughSound change
74}
75/*
76 Since LaughTrigger is READ_WRITE variable, onLaughTriggerChange() is
77 executed every time a new value is received from IoT Cloud.
78*/
79void onLaughTriggerChange() {
80 if(!playCooldown){
81 player.play(laugh_sound);
82 people_scared++;
83 playCooldown = true;
84 lastPlay = millis();
85 Serial.println("Cooldown started");
86 }
87}
Downloadable files
Halloween Sounds
Download these files to your micro SD card
halloween_sounds.zip
Pumpkin Collection by Joek Design
3D print your own pumpkin
https://www.printables.com/model/616802-pumpkin-collection
Halloween pumpkin pattern
Follow the pattern instructions
https://app.arduino.cc/templates/halloween-pumpkin
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.