Hatstall Harry Potter
This project consists of implementing elements that we've learned this first part of the course, such as sensors, engines, leds, and then implementing it in a creative design within the Halloween theme.
We've chosen to make a prototype of the picker hat that appears in Harry Potter's first film, Harry Potter and the Philosophical Stone. We've managed to do this using different materials, like plastic for 3D printing, filter to get the hat effect.
And as regards the issue of the Arduino programming and code, it has been sought and modified according to our criteria and needs.
Supplies
The electronic parts we have used for our project have been as follows:
- Two servos engines, one to move the top of the hat and the other to simulate the movement of the mouth.
- A proximity sensor, to detect the head's proximity when putting it on and starting to start all moves.
- A mini-protoboard.
- An Arduino plate, or in our case Elego.
- An SD card, where the part of the audio we want to be played will be recorded.
https://www.fnac.es/Tarjeta-SDHC-SanDisk-Ultra-16GB-Tarjeta-de-memoria-Tarjeta-SD/a1170697
- A port for the SD card.
- A loudspeaker, to amplify the audio stored on the SD.
The program we've used to program the code has been the Arduino program, although we've had to download an extra supplement so we can connect our plate that's not from the standard Arduino mark but from Elego.
PROTOTYPE
The physical part of our prototype has been first modeled on 3D by Solidworks software and then printed both parts (the mouth and body) with plan, a thermoplastic made from renewable resources such as wheat emmidon, tapioca roots or sugarcane. And the base used 9 mm cardboard.
To forge the hat and thus achieve the effect of the hat in question, it has been made with felt cloth, a fabric that is used to make coats and is therefore somewhat thicker and to paste it has been done so much sewing to achieve better effect and to be more resistant, so sabater glue has also been used.
CODE
Then we'll put our hat code on it.
#include <Servo.h> //include de library for the arduino to recognize one the servo 1
//#include <Servo.h> //include de library for the arduino to recognize one the servo 1
#include "SoftwareSerial.h" //include de library for the arduino to to allow serial communication on other digital pins of the Arduino
#include <DFRobotDFPlayerMini.h> //include de library for the arduino to recognize de DFplayer
Servo boca; //initialize variable for servo one
Servo punta; //initialize variable for servo two
SoftwareSerial softwareSerial(3, 2); //recognize the pins of the gps RX-2 , pin 3, and TX-3, pin 2, of the dfPlayer
int cm=0; // initialize variable for cm
long distancia,duracion; //long are decimals values for the distance and the duration of the ultrasonic
int posicion1=90; //initialize variable of an enter number for posicion 1 of the servos
int posicion2=-90; //initialize variable of an enter number for posicion 2 of the servos
//We configure the pins of the sensor Trigger and Echo, Trigger will work in output mode and on the other hand Echo will work in input mode.
#define Pecho 6 //Echo pin 6
#define Ptrig 7 //Trig pin 7
//Create the Player object
DFRobotDFPlayerMini player;
bool plays=false; //initialize a boolean for playing the audio
long tstart=millis(); //initialize a variable just to see the timing of the ultrasonic
void setup() {
Serial.begin (9600); //initialize the serial port to 9600 baud
pinMode(Pecho, INPUT); //define pin 6 as input (echo)
pinMode(Ptrig, OUTPUT); //define pin 7 as output (triger)
boca.attach (13); //define pin 13 as the output to drive the servo
punta.attach(12) ; //define pin 13 as the output to drive the servo
//setup DFPlayer
softwareSerial.begin(9600); //We start the serial monitor to show the result
if (!player.begin(softwareSerial)) { //Use softwareSerial to communicate with mp3.
//because de dfplayer need a few seconds to start de connection with the arduino, we use this to be able to see if its going properly
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true){
delay(0); //Code to compatible with ESP8266 watch dog, the objective of this post is to analyse some of the watchdog functions available on the Arduino IDE libraries for the ESP8266.
}
}
player.stop(); //when the code starts, in the setup, we want the sound to be stop
player.volume(30); //Set volume to maximum (0 to 30).
}
void loop() {
digitalWrite (Ptrig,LOW); //we generate a clean pulse setting the trigger to LOW
delayMicroseconds(2);
digitalWrite(Ptrig,HIGH); //generate the triger pulse of 10ms
delayMicroseconds(10);
digitalWrite(Ptrig,LOW); //we turn off the trigger
duracion= pulseIn(Pecho, HIGH); //with this we know how long it was high (HIGH)
distancia =(duracion/2)/29; //calculate distance in centimeters, formula used to convert to cm
Serial.println(distancia); //this is to see the distance that the sensor is reaching
if (distancia <=10 && distancia >=1){ //first loop, if the distance is short
if(plays == false){ //if the sound is off
player.begin(softwareSerial); //start playing the sound
player.play(1); //Play the first MP3 file on the SD card
plays = true; //then the boolean of the sound will be true, beacause the sound is working
}
boca.write(posicion1); //if the distance is less than 10 we also want the servos to move, here we are moving the servo boca to the posicion one 90º
punta.write(posicion1); //moving the servo punta to the posicion one 90º
delay(1000); //is a function that makes the processor wait, so as not to saturate the board, and that it can make the first move with time, before continuing with the code
boca.write(posicion2); //moving the servo boca to the posicion two - 90º
punta.write(posicion2); //moving the servo boca to the posicion two - 90º
delay(1000); //stop for 1ms
}else{ //we put this here because we want one servo to be moving all the time, so if the ditance is not less than 10
if(plays == true){ //and if the sound is working we want to stop the music and make the boolean false
player.stop();
plays = false;
}
punta.write(posicion1); //and the servo punta will be moving when the plays is false and when the plays is true
delay(1000);
punta.write(posicion2);
delay(1000);
}
}
TIKERCAD
We will then attach the code in KiCad format, to make it more understanding.
FLOWDIAGRAM
Flow diagram is a collective term for a diagram representing a flow or set of dynamic relationships in a system and here you can see our flowdiagram.
Downloads
CONCLUSION
This work has helped us to begin to have basic notions in the world of Arduino and begin to leverage this theme, which is a less tangible theme in the other projects we have touched upon, as a new language must be used via computer and achieve a result through electronic elements, such as the two servos we have used, a loudspeaker and a sensor.
It has been very interesting and enriching, as it is the first time we have added movement to a project beyond theory and hypotheses, as the hat has had to be scaled by the weight that our servofrens can move.