Nous recherchions tous les deux à créer un dispositif qui permettrait d’ouvrir un objet d’une manière « innovante » : par un signal vocal et par un signal de fréquence. Nous avons donc choisi de travailler ensemble afin de concevoir un meuble sécurisé.
- Bouton poussoir
- LED (1 verte, une orange, une rouge)
- Résistance (10 kiloohms, 220 Ohms, 1megaohm)
- Condensateur 100 uF
- Breadboard
- Servomoteur
- Buzzer piézo
- Connecteur mâle (3 broches)
- Micro CZN-15E
- Résisance 2.2 Kiloohm, 10 ohm, 100 Kiloohm, 10 Megaohm
- Servomoteur
- AOP LM358N (mode non inverseur)
- Arduino uno
- Condensateurs 100 microF, 47 nF
#include <Servo.h> #include "arduinoFFT.h"
#define SAMPLES 128 #define SAMPLING_FREQUENCY 1000
arduinoFFT FFT = arduinoFFT();
unsigned int sampling_period_us;
unsigned long microseconds;
double vReal[SAMPLES];
double vImag[SAMPLES];
Servo myServo;
const int greenLED = 4 ; const int redLED = 3 ;
int button = 13;
int cpt = 0; int resetCpt = 0; int resetCptMax = 4;
void setup() {
Serial.begin(9600);
pinMode(greenLED, OUTPUT); pinMode(redLED, OUTPUT); pinMode(button, INPUT);
myServo.attach(9);
myServo.write(0);
Serial.println("porte bloquée");
sampling_period_us = round(1000000*(1.0/SAMPLING_FREQUENCY));
}
void loop() {
for(int i=0; i<SAMPLES; i++)
{
microseconds = micros();
vReal[i] = analogRead(A0);
vImag[i] = 0;
while(micros() < (microseconds + sampling_period_us)){
}
}
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(vReal, vImag, SAMPLES); double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
Serial.println(peak);
for(int i=0; i<(SAMPLES/2); i++)
{
/*View all these three lines in serial terminal to see which frequencies has which amplitudes*/
Serial.print((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1);
Serial.print(" ");
Serial.println(vReal[i], 1); //View only this line in serial plotter to visualize the bins
}
delay(500);
/* "LA = 440Hz" */
if ((cpt == 0) && (440 <= peak) && (peak <= 450)) {
cpt = 1; }
/* "RE = 292.7Hz" */
if (cpt == 1) {
if ((288.0 <= peak) && (peak <= 299.0)) {
cpt = 2;
}
else
{
resetCpt ++;
if (resetCpt > resetCptMax) {
cpt = 0;
}
}
}
/* "SOL = 392.0Hz" */
if (cpt == 2) {
if ((392.0 <= peak) && (peak <= 402.0)) {
cpt = 3;
}
else {
resetCpt ++;
if (resetCpt > resetCptMax) {
cpt = 0;
}
}
}
if (cpt == 3){
myServo.write(180);
Serial.println("porte ouvert");
}
Serial.println(cpt);
if (cpt == 0) {
resetCpt = 0;
}
}