Project tutorial

Baby-Pram Monitoring System © LGPL

Real time monitoring variables like temperature, X-Y-Z acceleration, sound and light intensity for baby-pram.

  • 6,973 views
  • 4 comments
  • 13 respects

Components and supplies

MMA7260
×1
LM92
×1
12002 04
Breadboard (generic)
×1
Electret microphone
×1
Abx00004 iso both
Arduino MKR1000
×1
max4236
×1
Photocell
×1

Apps and online services

About this project

It is common to see a baby sleeping outside in winter time in Scandinavian countries, it is part of the culture.

Attaching this system to the pram and monitors different variables like: temperature, sound, acceleration, light, etc in order to see the status of our baby wherever he is (at our garden, balcony, kindergarten, on a trip with the nanny).

ThingSpeak IoT cloud was using to visualize the data capture by the sensors as can be seen in the following picture and also in the public channel: 

https://thingspeak.com/chann

Sensors interfaces:

Sound: Inverted Op Amp with gain 47 connected to ADC A2.

Accelerometer: It is connected to ADC A4, A5 and A6. An RC low pass filter is filtering to the outputs. MMA7260 Sleep mode is manage by Genuino pin 7.

Thermometer: LM92 provides the information by I2C bus with 1K pull up resistors.

Photocell: Connected to A1 by a divider resistor fed by pin 6. 

Power: All circuit are 3.3V. A portable charger provides the 5V for Genuino MKR1000.

Serial Monitor debugging:

As can be seen in the source code, the sensors values are coma separated printed in order to see the real time sensors output changes.

Improvements:

Some good improvements are listed below:

Data analysis: This system is just monitoring, would be nice to analyze the data, take decisions, and inform by different levels alerts.

Sound: Add a next amp stage and filter to have a more sensitive detector and a clean signal.

More sensors: UV level and GPS.

Code

Source CodeC/C++
#include <WiFi101.h>    
//#include <WiFiClient.h>
//#include <WiFiServer.h>
//#include <WiFiSSLClient.h>
//#include <WiFiUdp.h>

#include <Wire.h>
#include <SPI.h>

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

char lm92address = 0x48; //A1 A0 are grounded
char buffer[2];
int tempcode;
float tempf;
int tempi;
int tempcode2;

int lighti;

int status = WL_IDLE_STATUS;
WiFiServer server(80);

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String APIKey = "WWWWWWWWWWWWWW";             // enter your channel's Write API Key
const int updateThingSpeakInterval = 20 * 1000; // 20 second interval at which to update ThingSpeak

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;

// Temperature and ligth measurement every 1 min
unsigned long previousMillis = 0;
int interval_1m = 1 * 60 * 1000;     // 1 min

// Initialize Arduino Ethernet Client
WiFiClient client;




//############################## INIT - SETUP ##########################################
void setup() {

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  // Start Serial for debugging on the Serial Monitor
  Wire.begin();
  Serial.begin(9600);

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();
}



//################################## MAIN LOOP #######################################
void loop() {
  // read values from pins and store as strings
  //String temp   = String(10); //Just to have a defaul value
  //String light  = String(20); //Just to have a defaul value
  //String sound  = String(30); //Just to have a defaul value
  //String accelX = String(40); //Just to have a defaul value
  //String accelY = String(50); //Just to have a defaul value
  //String accelZ = String(60); //Just to have a defaul value



  //*************** ACCEL A4 A5 A6 *****************
  digitalWrite(7, HIGH);  // Disable SLEEP MOODE
  delay(10);
  String accelX = String(analogRead(A4), DEC); // read X acceleration
  delay(10);
  String accelY = String(analogRead(A5), DEC); // read X acceleration
  delay(10);
  String accelZ = String(analogRead(A6), DEC); // read X acceleration
  delay(10);
  String sound = String(analogRead(A2), DEC); // read mic
  digitalWrite(7, LOW);   // Enable SLEEP MOODE


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TASK every interval_1m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Measurement of temperature and light %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unsigned long currentMillis = millis();
 
if(currentMillis - previousMillis > interval_1m) {
    previousMillis = currentMillis;   


//**************** Temperature I2C LM92 ******************      
  Wire.requestFrom(lm92address, 2);
  if (Wire.available())
  {
    for (int i = 0; i < 2; i++) {
      buffer[i] = Wire.read();
            tempcode2=buffer[i];
            //Serial.print("Byte ");
            //Serial.print(i);
            //Serial.print(": ");
           //Serial.print(tempcode2);
            //Serial.println();
    }
    tempcode = ((buffer[0] << 8) + buffer[1]) >> 3;
    tempf = tempcode * 0.0625;
    tempi = int(tempf);
    Serial.println(tempf);
    Serial.println(tempi);
  }
//********************************************************


//****************** Photocell ADC A1 ********************
  digitalWrite(6, HIGH);
  delay(10);
  lighti = analogRead(A1); // read light value
  digitalWrite(6, LOW);
//*******************************************************
  
  }
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

String temp   = String(tempi);
String light = String(lighti);

  //Print Update Response to Serial Monitor
  if (client.available()) {
    char c = client.read();
    //    Serial.print(c);
  }
  // Disconnect from ThingSpeak
  if (!client.connected() && lastConnected) {
    Serial.println("...disconnected");
    Serial.println();
    client.stop();
  }
  

// Just for debugging porpose
Serial.print(light);
    Serial.print(",");
    Serial.print(temp);
    Serial.print(",");
    Serial.print(sound);
    Serial.print(",");
    Serial.print(accelX);
    Serial.print(",");
    Serial.print(accelY);
    Serial.print(",");
    Serial.println(accelZ);

  
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TASK every updateThingSpeakInterval 20 sec %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Update ThingSpeak Channel %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) {
    updateThingSpeak("field1=" + light + "&field2=" + temp + "&field3=" + sound + "&field4=" + accelX + "&field5=" + accelY + "&field6=" + accelZ);

//    Serial.print(light);
//    Serial.print(",");
//    Serial.print(temp);
//    Serial.print(",");
//    Serial.print(sound);
//    Serial.print(",");
//    Serial.print(accelX);
//    Serial.print(",");
//    Serial.print(accelY);
//    Serial.print(",");
//    Serial.println(accelZ);

  }
  lastConnected = client.connected();
  delay(10);
}
//################################## END MAIN LOOP #######################################





//****************************** Function updateThingSpeak *******************************
void updateThingSpeak(String tsData) {
  if (client.connect(thingSpeakAddress, 80)) {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);
    lastConnectionTime = millis();

    if (client.connected()) {
      Serial.println("Connecting to ThingSpeak...");
      Serial.println();
    }
  }
}
//***************************************************************************************




//****************************** Function printWifiStatus *******************************
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
//***************************************************************************************

Schematics

Breadboard
Msbp board

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 454,659 views
  • 42 comments
  • 236 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,510 views
  • 95 comments
  • 671 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,298 views
  • 38 comments
  • 236 respects

OpenCat

Project in progress by Team Petoi

  • 195,878 views
  • 154 comments
  • 1,360 respects
Add projectSign up / Login