Project in progress
Raindrop Notification

Raindrop Notification © GPL3+

This is a project based on Arduino MKR GSM 1400 that will send a text notification when it senses rain drops.

  • 84 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

This project is intended to be used for motorcycles. Check out the blog post: https://www.motoiot.us/blog/motorcycle-rain-sensor-and-notification

Code

mkr1400Arduino
/****************************************
Auhtor: Jerico Cruz
*****************************************/

// libraries
#include <MKRGSM.h>
#include "settings.h"

// APN data
String HOLOGRAM_MESSAGE = "";

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// Hologram's Embedded API (https://hologram.io/docs/reference/cloud/embedded/) URL and port
char server[] = "cloudsocket.hologram.io";
int port = 9999;

const int analogPin=A0; //the AO of the module attach to A0
const int digitalPin=7; //D0 attach to pin7
int Astate=0; //store the value of A0
boolean Dstate=0; //store the value of D0
boolean messageSent = false;
time_t flag;

void setup() {
  pinMode(digitalPin,INPUT); //set digitalPin as INPUT
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {  
  Astate=analogRead(analogPin); //read the value of A0
  Dstate=digitalRead(digitalPin); //read the value of D0

  //Once the raindrop sensor threshold for "wet" is reached, send a notification.
  if(Dstate==LOW) 
  {    
    if(! messageSent){
      sendNotification();
    }
    else {
      checkHoursLapsed();  
    }    
  }
  else{
    messageSent = false;
  }  
}

void checkHoursLapsed() {
    if (gsmConnect()){
        time_t diff = gsmAccess.getTime() - flag;

        if ((diff / 3600) >= 1) {
          messageSent = false;
          flag = 0;  
        }
    }
}

void sendNotification() { 
  
  if (gsmConnect()){
    if (client.connect(server, port)) {
      // Send a Message request:
      HOLOGRAM_MESSAGE = "Rain detected.";
      client.println(HOLOGRAM_PROCEDURE_NAME+HOLOGRAM_DEVICE_KEY+HOLOGRAM_DESTINATION_NUMBER+" "+HOLOGRAM_MESSAGE);
      messageSent = true;
      flag = gsmAccess.getTime();
    }
  
    client.stop();
    gsmAccess.shutdown();
  }
}

boolean gsmConnect() {
  boolean connected = false;
  while (!connected) {
    //Serial.println(gsmAccess.begin()); //Uncomment for testing
    
    if ((gsmAccess.begin() == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {

          connected = true;
          digitalWrite(LED_BUILTIN, LOW);       
    }
    else{
        digitalWrite(LED_BUILTIN, HIGH);
    } 
  }

  return connected;
}
settings.hArduino
const String HOLOGRAM_DEVICE_KEY = "[hologram device key goes here.]";
const String HOLOGRAM_DESTINATION_NUMBER = "[Phone number to send notification to]";
const char GPRS_APN[] = "hologram";
const char GPRS_LOGIN[] = " ";
const char GPRS_PASSWORD[] = " ";
const char HOLOGRAM_PROCEDURE_NAME = 'S';

Schematics

Wiring
Raindrop bb alcroruoik

Comments

Similar projects you might like

SmartQ Notification with Azure IOT Hub and Virtual Shields

Project showcase by vincent wong

  • 1,610 views
  • 0 comments
  • 6 respects

Water Quality Monitoring and Notification System

Project showcase by emmanuel ani

  • 59,964 views
  • 47 comments
  • 140 respects

Notification IoT Using NeoPixel and Smartphone

Project showcase by Team Geny Studio

  • 5,261 views
  • 1 comment
  • 8 respects

Intruder Alarm with Text Message Notification

Project tutorial by Matthew Hallberg

  • 28,636 views
  • 13 comments
  • 55 respects

Cellular Wardriving and Other IoT Shenanigans

Project tutorial by Moheeb Zara and benstr ๐Ÿš€

  • 3,379 views
  • 2 comments
  • 20 respects

Aggro-Crag-in-Real-Life-Button and Leader Board

Project tutorial by Sheena Martin and Derrick Wolbert

  • 2,148 views
  • 0 comments
  • 8 respects
Add projectSign up / Login