IOT Sensor platform (Baby / weather monitor )

Using sensors to collect data such as weather and motion into a dashboard and alert users through text/email when important events occur.

IntermediateFull instructions provided7,764
IOT Sensor platform (Baby / weather monitor )

Things used in this project

Hardware components

TI Launchpad TM4C123GXL Microcontroller
×2
CC3100BOOST SimpleLink CC3100 Wi-Fi BoosterPack
Texas Instruments CC3100BOOST SimpleLink CC3100 Wi-Fi BoosterPack
×2
Esquilo Air
Esquilo Air
×1
Sharp 2Y0A02 IR Distance sensor
To detect baby escape
×1
Freescale FRDM-STBC-AGM01 Gyro/Accelerometer
×1
SparkFun Weather Shield
SparkFun Weather Shield
×1

Story

Read more

Code

DweetDemov2jh.ino

C/C++
General publishing of data to Dweet.io then consumed by freeboard.io
// Libraries
#include <SPI.h>
#include <WiFi.h>
#include <WifiIPStack.h>
#include <WiFiClient.h>


// WiFi Client
WiFiClient client;

// Your network name also called SSID
char ssid[] = "211";
// your network password
char password[] = "2getonline";
// your network key Index number (needed only for WEP)
int keyIndex = 0;

// Dweet parameters
char * server_name = "www.dweet.io";
#define thing_name  "jhthing"

void setup() {

  Serial.begin(115200);      // Initialize serial communication

  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid); 
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
  }
  
  // Pin for the PIR sensor
  pinMode(8,INPUT_PULLDOWN);
  
  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");
  
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }

}


void loop() {
    
  // Measure motion
  int motion = digitalRead(8);
  float temperature = analogRead(23);
  float humidity = analogRead(24);
  float AI25 = analogRead(25);
  float AI26 = analogRead(26);
  float AI27 = analogRead(27);
  
  Serial.println(motion);
  
  // Measure temperature & humidity  

  //if (dht::readFloatData(10, &temperature, &humidity, false) == 0)
  //{
  //  Serial.print("T: ");
  //  Serial.print(temperature);
  //  Serial.print(" H: ");
  //  Serial.println(humidity);    
  //}
  
  // Send data to server
  if (client.connect(server_name, 80)) {
    Serial.println("Connected");
    
    Serial.print(F("Sending request... "));
    
    client.print(F("GET /dweet/for/"));
    client.print(thing_name);
    client.print(F("?temperature="));
    client.print(temperature);
    client.print(F("&humidity="));
    client.print(humidity);
    client.print(F("&motion="));
    client.print(motion);
    client.print(F("&AI25="));
    client.print(AI25);    
    client.print(F("&AI26="));
    client.print(AI26);    
    client.print(F("&AI27="));
    client.print(AI27);    
    
    client.println(F(" HTTP/1.1"));
    
    client.println(F("Host: dweet.io"));
    client.println(F("Connection: close"));
    client.println(F(""));
    
    Serial.println(F("done."));
  }
 
 // if (client.connect(server_name, 80)) {
 //   Serial.println("Connected");  
 //   Serial.print(F("Sending Alert... "));
   
 //   client.print(F("GET /dweet/for/"));
 //   client.print(thing_name);
 //   client.print(F("?motion="));
 //   client.print(motion);
   
 //   client.println(F(" HTTP/1.1"));
    
 //   client.println(F("Host: dweet.io"));
 //   client.println(F("Connection: close"));
 //   client.println(F(""));
    
 //  Serial.println(F("done."));
 //    https://dweet.io/alert/me@mydohmain.com/when/my_thing/dweet.donut_qty<=0?key=abc123
 // }
  
 
  
  
  // Read answer
  Serial.println(F("Reading answer..."));
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
  Serial.println(F(""));
  
  // Close connection
  client.stop();
  Serial.println(F("Closing connection"));
  Serial.println(F(""));
  
 
 delay (300);
}

Baby monitor sketch

C/C++
#include <SPI.h>
#include <WiFi.h>
#include <WifiIPStack.h>
#include <WiFiClient.h>

#include <Temboo.h>
//#include "TembooAccount.h" // Contains Temboo account information
#define TEMBOO_ACCOUNT ""  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME ""  // Your Temboo app name
#define TEMBOO_APP_KEY ""  // Your Temboo app key

// WiFi Client
WiFiClient client;

// Your network name also called SSID
char ssid[] = "";
// your network password
char password[] = "";
// your network key Index number (needed only for WEP)
int keyIndex = 0;

// Dweet parameters
char * server_name = "www.dweet.io";
#define thing_name  ""

int sensorPin = A0;
int sensorValue = 0;
int sensorReadCount = 0;
int sensorValues[5];

bool textSent = false;

void setup()
{
  // put your setup code here, to run once
  Serial.begin(115200);
  
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
  }
  
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }
  
  Serial.println("Connected");
  
  delay(2000);
}

void loop()
{
  // put your main code here, to run repeatedly:
  sensorValue = analogRead(sensorPin);
//  Serial.println(sensorValue);

  sensorValues[sensorReadCount % 5] = sensorValue;
  
  if (sensorReadCount > 4) {
    float average = (sensorValues[0] + sensorValues[1] + sensorValues[2] + sensorValues[3] + sensorValues[4]) / 5.0f;
    if (sensorValue - average > 200 || sensorValue - average < -200) {
      sendAlert(true, sensorValue);
    }
    else {
      sendAlert(false, sensorValue);
    }
  }
  
  sensorReadCount++;
  delay(250); 
}

void sendAlert(boolean redAlert, int distance) {
  
  // Send data to server
  if (client.connect(server_name, 80)) {
    Serial.print(".");
    if (redAlert) Serial.println("");
    
    client.print(F("GET /dweet/for/"));
    client.print(thing_name);
    client.print(F("?redAlert="));
    client.print(redAlert);
    client.print(F("&distance="));
    client.print(distance);
    client.println(F(" HTTP/1.1"));
    
    client.println(F("Host: dweet.io"));
    client.println(F("Connection: close"));
    client.println(F(""));
    
    client.stop();
    
//    Serial.println(F("done."));
  }
  
  if (redAlert) textAlert();
}

void textAlert() {
  
  if (!textSent) {
    TembooChoreo SendSMSChoreo(client);

    // Invoke the Temboo client
    SendSMSChoreo.begin();

    // Set Temboo account credentials
    SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
    SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);

    // Set Choreo inputs
    String AuthTokenValue = "";
    SendSMSChoreo.addInput("AuthToken", AuthTokenValue);
    String BodyValue = "BodyText";
    SendSMSChoreo.addInput("Body", BodyValue);
    String ToValue = "+18008675309";
    SendSMSChoreo.addInput("To", ToValue);
    String AccountSIDValue = "";
    SendSMSChoreo.addInput("AccountSID", AccountSIDValue);
    String FromValue = "+13035559090";
    SendSMSChoreo.addInput("From", FromValue);

    // Identify the Choreo to run
    SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");

    // Run the Choreo; when results are available, print them to serial
    SendSMSChoreo.run();

    while(SendSMSChoreo.available()) {
      char c = SendSMSChoreo.read();
      Serial.print(c);
    }
    SendSMSChoreo.close(); 
    
    textSent = true;
  }
}

Credits

Johnathan Hottell

Johnathan Hottell

11 projects • 110 followers
my website http://electronhacks.com
J Sherwood

J Sherwood

1 project • 7 followers
Minjie Zheng

Minjie Zheng

1 project • 13 followers

Comments