
A fun song, “You spin my head right round, right round…” was the inspiration for this Halloween creation that relies on a person coming within 60 centimeters of the “dummy” to trigger the ultrasonic sensor causing the music, lights and stepper motor to kick into action. Many trick-or-treaters enjoyed this creation.
You spin my head round.....
#include <Stepper.h>
int stepsPerRevolution = 2048;
int rpm = 10;
//pin order IN1, IN3, IN2, IN4
Stepper myStepper (stepsPerRevolution, 8, 10, 9, 12);
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 4
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
// mp3 player commands
#include <SoftwareSerial.h>
#define ARDUINO_RX 5//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 6//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
#define NEXT_SONG 0X01
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed 0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
#define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
#define CMD_RESET 0x0C//chip reset
#define STOP_PLAY 0X16
int WHITE = (250, 250, 250);
void setup() {
Serial.begin(9600);
mySerial.begin(9600);//Start our Serial coms for THE MP3
delay(500);//Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
pinMode(7, OUTPUT);
myStepper.setSpeed(rpm);
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
delay(200);//wait for 200ms
}
void loop() {
int sensorValue = analogRead(A4);
Serial.println(sensorValue);
delay(100);
if (sensorValue < 60){
sendCommand(CMD_PLAY_WITHVOLUME, 0X0F01);//play the first song with volume 15 class
strip.fill(200, 0, 24);
strip.show();
delay(4000);//the programm will send the play option each 100 seconds to the catalex chip
for (int i = 0; i < 1; i++){
myStepper.step(stepsPerRevolution);
delay(20);
}
theaterChaseRainbow(20);
myStepper.step(-stepsPerRevolution);
delay(500);
strip.clear();
strip.show();
}
delay(4000);}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 50; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void sendCommand(int8_t command, int16_t dat)
{
delay(20);
Send_buf[0] = 0x7e; //starting byte
Send_buf[1] = 0xff; //version
Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
Send_buf[3] = command; //
Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
Send_buf[5] = (int8_t)(dat >> 8);//datah
Send_buf[6] = (int8_t)(dat); //datal
Send_buf[7] = 0xef; //ending byte
for(uint8_t i=0; i<8; i++)//
{
mySerial.write(Send_buf[i]) ;//send bit to serial mp3
Serial.print(Send_buf[i],HEX);//send bit to serial monitor in pc
}
Serial.println();
}
- Maxbotix EZ ultrasonic sensor
- Arduino UNO
- stepper motor and driver
- Adafruit neopixel ring
- powered speakers
- dressmaker dummy
- styrofoam head
- tripod with wood shelf
- 3D printed attachment from stepper shaft to wheel to spin head

