Sensor Sw420 and Esp32

felipehorion
Posts: 1
Joined: Thu Jul 04, 2019 1:07 am

Sensor Sw420 and Esp32

Postby felipehorion » Thu Jul 04, 2019 1:22 am

How do I connect a Sw420 vibration sensor to an esp32? Something is wrong, because when you turn on the card paar to read the code. Am I calling wrong? My idea is to do a fall detector, where if the object falls a message is sent via iftt.

Code: Select all

#include <ESP32WiFi.h>
#include "IFTTTWebhook.h"

#define WIFI_SSID "your SSID here"
#define  WIFI_PASSWORD "your password here"

#define IFTTT_API_KEY "your key here"
#define IFTTT_EVENT_NAME "your event name here"

#define pinoSensor 2 // pino que o sensor esta conectado
int ctd = 0;
int tempo = 10000;

void setup() {
  pinMode(pinoSensor, INPUT);
  Serial.begin(9600);

  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  IFTTTWebhook wh(IFTTT_API_KEY, IFTTT_EVENT_NAME);
}

void loop() {
if(ctd > 10){
  ifttt();
} else 
if(digitalRead(pinoSensor) == HIGH)// lê a porta digital 7 e verfica a se o valor é alto
{
  Serial.println("Lido");
  delay(tempo);
digitalWrite(pinoLed, HIGH); // acende o led no pino 8
ctd++;
}
else
{
  Serial.println("Não lido");
  delay(tempo);
digitalWrite(pinoLed, LOW); // apaga o led no pino 8
ctd--;
}
Serial.println(ctd);
}

ifttt(){
  wh.trigger("Nome da pessoa", "Mensagem", "Comentário");
}

Who is online

Users browsing this forum: No registered users and 82 guests