Jump to content

Sensor de Som


Perks
 Share

Recommended Posts

como o boxe estava particularmente chato hoje decidi pegar no PC e criar um sensor de Som com o blynk, para evitar hub intermédios e ter notificações, assim como capacidade de as desligar ou ligar remotamente. também como forma de controlo decidi juntar um led que pisca juntamente com o Som, de forma a dar algum alerta visual

Uma pequena amostra, conforme podem ver os LEd's acompanham os sons e depois no telefone quando ligo o botão da notificação, recebo remotamente notificação

 

Este pequeno sensor imo é partucularmente util como sensor para monitorização tipo de quebra de vidros uma vez que o sensor tem uma roda tipo parafuso, que permite regular a intensidade a partir da qual queremos que ele actue

 

Material utilizado
O nodemcu ~2,50EUR
o sensor de som ~0,50EUR
resistência 220 OHM - Lote de 100 - 0,55EUR
LED 1EUR Lote de 50

 

já agora um pequeno aparte, esta placa aguenta com mais do que uma função simultânea, é perfeitamente possível ter por exemplo  o Thermopar do tópico a lado e este a correr simultaneamente, separei por uma questão de visibilidade e porque quero juntar à outra placa algumas funções extra, ou até podem juntar um sensor de movimento, um tilt  ou um sensor de abertura de portas por exemplo

E para finalizar, o código deste

 

 

  • Like 2
Link to comment
Share on other sites

entretanto para verem aquilo que disse de ser dynamic adicionei um TILT Sensor ap Skecth

Este sensor é um SW520-D e só detecta movimento, custa 0,75EUR um lote de 10

este sensor é super pequeno,

Spoiler

ZxhOvi0.jpg

ou seja numa porta, janela ou qualquer parte com moviemntosque queiram monitorizar é

criar um pequena sistema de alarme, com detector de movimentos e de som

 

 

código

 

utilizando o mesmo esquema podemos adicionar um sensor PIR que custa 0,70EUR e a seguir juntar um de proximidade e por aí adiante

 

  • Like 1
Link to comment
Share on other sites

refiz o código de raiz porque resolvi juntar ao thermopar e coloquei uns interrupts para tornar tudo mais eficiente

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - ESP8266 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "token do Blynk";

int soundSensor = D7;
int LED = D6;
int TILT = D5;
int statusSensor;
int statusTilt;
bool notification;
bool soundChanged;
bool tiltChanged;
String value;
BlynkTimer timer;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID da rede Wireless";
char pass[] = "Pw da rede wireless";


BLYNK_CONNECTED() {
  Blynk.syncVirtual(V10);
}


BLYNK_WRITE(V10)
{
    if (param.asInt()) {
        notification = true;
    } else {
       notification = false;
    }
Serial.println(notification);
}

void notify()
{
  Blynk.virtualWrite(V10, LOW);
  Blynk.syncVirtual(V10);
  Blynk.notify( "Alerta de " + value);
}

void checkSound()
{
  //int statusSensor = !digitalRead (soundSensor);
  soundChanged = true;
}

void enableTilt()
{
  attachInterrupt(digitalPinToInterrupt(TILT), checkTilt, CHANGE);
  Serial.println("\n\nInterrupt enabled");
  }

  
void checkTilt()
{
  int statusTilt = digitalRead (TILT);
  tiltChanged = true;
  detachInterrupt(digitalPinToInterrupt(TILT));
  Serial.println("\n\nInterrupt disabled");
  timer.setTimeout(10000L, enableTilt);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  pinMode (soundSensor, INPUT_PULLUP);
  pinMode (TILT, INPUT_PULLUP);
  pinMode (LED, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(soundSensor), checkSound, HIGH);
  attachInterrupt(digitalPinToInterrupt(TILT), checkTilt, CHANGE);
  }

void loop()
{
  Blynk.run();
  timer.run();
  
  if (soundChanged)
  {
    soundChanged = !soundChanged;
    digitalWrite(LED, HIGH);
    digitalWrite(LED_BUILTIN, LOW);
    if (notification){
      value = "Som";
      notify();
    }
  }
  
  else
  {
    digitalWrite(LED, LOW);
    digitalWrite(LED_BUILTIN, HIGH);
  }
  if (tiltChanged)
  {
    tiltChanged = !tiltChanged;
    if (notification){      
      value = "Movimento";
      notify();
    }
  }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.