Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
phpoc_manIoT_lover
Published © GPL3+

If Button Is Pressed, Make Sound Notification on Smartphone

Make sound notification on smart phone when button is pressed.

BeginnerFull instructions provided1 hour4,799
If Button Is Pressed, Make Sound Notification on Smartphone

Things used in this project

Story

Read more

Schematics

20191216_173810_Hq3YzTssOJ.jpg

Code

ArduinoCode

Arduino
#include <Phpoc.h>
#include <ezButton.h>

String IFTTT_WEBHOOKS_KEY = "xxxxxxxxxxxxxxxxxxxxxx"; // change your webhooks key here
char server_name[] = "maker.ifttt.com";

PhpocClient client;
ezButton button(7);  // create Button object that attach to pin 7;

void sendNotification()
{
  // connect to web server on port 443:
  if(client.connectSSL(server_name, 443)) {
    // if connected:
    Serial.println("Connected to server");

    // make a HTTP request:
    client.println("GET /trigger/button/with/key/" + IFTTT_WEBHOOKS_KEY + " HTTP/1.1");
    client.println("Host: maker.ifttt.com");
    client.println("Connection: close");
    client.println();
  }

  while(client.connected()) {
    if(client.available()) {
      char c = client.read();
      Serial.write(c);
    }
  }

  Serial.println();
  Serial.println("disconnecting from server.");
  client.stop();
}

void setup() {
  Serial.begin(9600);

  // initialize PHPoC [WiFi] Shield:
  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);

  button.setDebounceTime(100); // set debounce time to 100 milliseconds
}

void loop() {
  button.loop(); // MUST call the loop() function first

  if(button.isPressed()) { 
    Serial.println("sending notification");
    sendNotification();
  }
}

Credits

phpoc_man
62 projects • 408 followers
Contact
IoT_lover
10 projects • 192 followers
Contact

Comments

Please log in or sign up to comment.