Devices & Components
40 colored male-male jumper wires
Arduino® UNO R4 WiFi
Box 525 1% precision resistors - 17 values
Arduino Plug and Make Kit
DFPlayer - A Mini MP3 Player
Powerbank
1N4007 1A 1000V Diode
Mini breadboard - White
Speaker 3 Ohm 0.5W
Micro SD Card Module (Generic)
Software & Tools
Arduino Cloud Editor
Project description
Code
Halloween
cpp
The code uses 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
Upload these files to you micro SD card
halloween_sounds.zip
Pumpkin collection by Jopek Design
3D print your own pumpkin
https://www.printables.com/model/616802-pumpkin-collection
Halloween Pumpkin Template
Follow the template instructions
https://app.arduino.cc/templates/halloween-pumpkin
Comments
Only logged in users can leave comments