Project showcase
Clap Control for Christmas Tree

Clap Control for Christmas Tree © CC BY

Use your Arduino Uno to control your Christmas tree! A little example what you can do with Arduino and some free time.

  • 803 views
  • 0 comments
  • 6 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
sound sensor module
Digital Output
×1
Relay Module (Generic)
×1
Vishay semiconductor ild74 image 75px
Opto-Isolator
×1
4415447 jg5sklyzsj
Resistor 220 ohm
×1
11026 02
Jumper wires (generic)
×1
Christmas Tree
×1
Christmas led strip
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Here, our Christmas Tree is controlled with claps! I turn it on, turn it off with my clapping mode.

In this video, I'll show you how to use the Arduino to make your Christmas tree smart.

If you don't know me. I'm Flávio Guimarães, a programming language and robotics specialist!

This is my first post on Hackster.io. I hope it helps you!

Code

ArvoreNatal.inoArduino
Sketch for Arduino Uno
/*
 *   Q0405
 *   AUTOR:   BrincandoComIdeias
 *   LINK:    https://www.youtube.com/brincandocomideias ; https://cursodearduino.net/
 *   COMPRE:  https://www.arducore.com.br/
 *   SKETCH:  Arvore de Natal com Arduino
 *   DATA:    05/12/2018
*/

#define pinSom 3
#define pinRele 12
#define pinAcop 2

#define tempoEntrePalmas 150 //milisegundos
#define tempoMaximoEntrePalmas 1000 //milisegundos

// DECLARAO DE VARIVEIS
int contaPalmas = 0;
unsigned long tempoEspera = 0;
unsigned long tempoEsperaEntrePalmas = 0;

// DECLARAO DE FUNO
void executarAcao();

void setup() {

  Serial.begin(9600);

  // DEFININDO MODO DOS PINOS
  pinMode(pinSom, INPUT);
  pinMode(pinRele, OUTPUT);
  pinMode(pinAcop, OUTPUT);

  // INICIANDO COM O PINO DO RELE E DO FOTOACOPLADOR DESLIGADOS
  digitalWrite(pinRele, LOW);
  digitalWrite(pinAcop, LOW);

  Serial.println("Setup Concludo");
}

void loop() {
  //VERIFICA O ESTADO DO SENSOR, AO BATER PALMA O SINAL VAI PARA HIGH
  static int sensorSomAnt;
  int sensorSom = digitalRead(pinSom);

  //SE O SENSOR DETECTAR MUDANA DO ESTADO LOW PARA HIGH
  if ((sensorSom == HIGH) && (sensorSomAnt == LOW)) {
    Serial.print("detectou");

    //CALCULA O TEMPO DA ULTIMA MUDANA PARA NAO DETECTAR ECO DA MESMA PALMA
    if ((millis() - tempoEspera) > tempoEntrePalmas) {
      tempoEspera = millis(); // ATUALIZA O TEMPO PARA CONTROLE DE ECO
      tempoEsperaEntrePalmas = millis(); // ATUALIZA O TEMPO PARA CONTROLE DA CONTAGEM
      contaPalmas++;
    }
  }
  sensorSomAnt = sensorSom;

  // CASO EXCEDA O TEMPO DE CONTROLE DA CONTAGEM, EXECUTA A AO E ZERA A CONTAGEM
  if ( (contaPalmas != 0) && ((millis() - tempoEsperaEntrePalmas) > tempoMaximoEntrePalmas) ) {
    executarAcao();
    contaPalmas = 0;
    tempoEsperaEntrePalmas = millis();
  }

}


void executarAcao() {

  switch (contaPalmas) {
    case 2:
      digitalWrite(pinAcop, HIGH);
      delay(200);
      digitalWrite(pinAcop, LOW);
      Serial.println("Duas Palmas, trocando modo do pisca");
      break;
    case 3:
      digitalWrite(pinRele, !digitalRead(pinRele));
      Serial.println("Tres Palmas, trocando estado do rele");
      break;
    default:
      Serial.print("A quantidade de palmas foi de:");
      Serial.println(contaPalmas);
  }
}

Schematics

Schematics
Esquematico bb kde8hq0urk

Comments

Similar projects you might like

IoT Christmas Tree Topper

Project tutorial by Balázs Simon

  • 2,108 views
  • 0 comments
  • 10 respects

Wooden LED Christmas Tree

Project showcase by Arduino_Jarod

  • 1,413 views
  • 0 comments
  • 7 respects

Christmas Tree with 150 Digital LED Pixels

Project tutorial by Martino Ghisleni

  • 5,551 views
  • 0 comments
  • 12 respects

Christmas Tree With Arduino

Project showcase by FLORICA Tudor-Nicusor

  • 3,433 views
  • 0 comments
  • 6 respects

Control Christmas Lights with Voice Commands using Arduino

Project tutorial by ahmed ismail

  • 2,934 views
  • 2 comments
  • 14 respects

3D Printed Christmas Tree with Animation

Project tutorial by TheTNR

  • 1,275 views
  • 2 comments
  • 6 respects
Add projectSign up / Login