Ehsan Aerabi
Published © GPL3+

Kids Tracker for Smart Houses

This system can be installed on dangerous locations in a smart house (like oven). It quickly reacts when a baby moving toward the danger.

IntermediateWork in progressOver 1 day410
Kids Tracker for Smart Houses

Things used in this project

Hardware components

SIM800L Module
GSM Modem
×1
RDM6300
RFID reader
×1
DFPlayer mini
MP3 Player. You need a micro SD memory
×1
Breadboard (generic)
Breadboard (generic)
×2

Story

Read more

Schematics

Circuit for the central system

Code

MCU Arduino Code for the proximity system

Arduino
#include <SoftwareSerial.h>
#include "RDM6300.h"
SoftwareSerial RFID(2, 3); // RX and TX

int Led=13;
uint8_t Payload[6]; // used for read comparisons

RDM6300 RDM6300(Payload);

void setup()
{
  pinMode(Led, OUTPUT);
  RFID.begin(9600);    // start serial to RFID reader
  Serial.begin(9600);  // start serial to PC 
  Serial1.begin(57600); // Start serial to 7688
}

void loop()
{
  while (RFID.available() > 0) 
  {
    digitalWrite(Led, HIGH);
    uint8_t c = RFID.read();
    //Serial.print(c,HEX);
    if (RDM6300.decode(c)) {
      Serial1.write("Baby is in danger!\r\n");
      for (int i=0; i < 5; i++){
        Serial.print(Payload[i], HEX);
        Serial.print(" ");
      } 
      Serial.println();
    }  
  }
  Serial1.write("Baby is safe.\r\n");
  digitalWrite(Led, LOW);   
  delay(100);
}

MPU 7688 Code for the proximity system

Python
import socket
import serial
import time


s = None

def setup():
    # open serial COM port to /dev/ttyS0, which maps to UART0(D0/D1)
    # the baudrate is set to 57600 and should be the same as the one
    # specified in the Arduino sketch uploaded to ATMega32U4.
    ToMCU = serial.Serial("/dev/ttyS0", 9600)
	


def loop():
	line = ser.readline()	
	clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	clientsocket.connect(('TheCentralSystem', 8089))
	clientsocket.send(line)

if __name__ == '__main__':
    setup()
    while True:
        loop()

MCU Arduino Code for the Central System

Arduino
  //#include <Esplora.h>
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(2, 3); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void setup() {
  
                     pinMode(13, OUTPUT); // Pin 13 connected to an LED. We use it to indicate error on the MP3 Player
                     Serial1.begin(9600); // Serial to Connect to the MPU
                     Serial.begin(115200); // Serial Connected to the PC
                     mySoftwareSerial.begin(9600); // Software serial (on pins 2 and 3) to connect to the DFPlayer (Mp3 Player)
                     digitalWrite(13, 0);
                     delay(1000);
                     digitalWrite(13, 1);
                     if (myDFPlayer.available()) {
                      printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
                     }
                     if (!myDFPlayer.begin(mySoftwareSerial))
                        {
                        while(true){ // infinite fast blinking indicates MP3 player failure                        
                        delay(200);
                        digitalWrite(13, 0);
                        delay(200);
                        digitalWrite(13, 1);
                          }
                        }
                        else
                        {
                        delay(1000); // 3 times blikning with 2-second interval indicates that MP3 player is operating well.
                        digitalWrite(13, 0);
                        delay(1000);
                        digitalWrite(13, 1);
                        delay(1000);
                        digitalWrite(13, 0);
                        delay(1000);
                        digitalWrite(13, 1);
                        delay(1000);
                        digitalWrite(13, 0);
                        myDFPlayer.volume(10);  //Set volume value. From 0 to 30
                        //myDFPlayer.play(1);  //Play the first mp3
  
                        }

}
void loop() {
    //            myDFPlayer.volume(10);  //Set volume value. From 0 to 30
    //              myDFPlayer.play(1);  //Play the first mp3

  

  int c = Serial1.read();      // read from MT7688
              if (c != -1) {
                    switch(c) {
                          case '0':                // Stop Mp3 player when receiving "0"
                          myDFPlayer.pause();
                          break;
                          case '1':                //  Start Mp3 player when receiving "1"
                          myDFPlayer.play(1);  //Play the first mp3
                          break;
                    }
         }
}
void printDetail(uint8_t type, int value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }

}

MPU 7688 Code for the central system

Python
import serial
import time
import socket


s = None
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def setup():
    # open serial COM port to /dev/ttyS0, which maps to UART0(D0/D1)
    # the baudrate is set to 57600 and should be the same as the one
    # specified in the Arduino sketch uploaded to ATMega32U4.
    global s
#    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.bind(('localhost', 8089))
    serversocket.listen(5) # become a server socket, maximum 5 connections
    ToMPU = serial.Serial("/dev/ttyS0", 9600)
    ToGSM = serial.Serial("/dev/ttyS2", 9600)
	


def loop():
    connection, address = serversocket.accept()
    buf = connection.recv(64)
    if len(buf) > 0:
        print buf
	if buf == "Baby is in danger!":
			ToMPU.write("1") # signal the MCU (mega32U4) to initiate the mp3 palyer
			ToGSM.write("ATD123456789\r\n") # make a call to the number '123456789'
			# You can send Text Message by the following lines od code:
			# ToGSM.write("AT+CMGF=1\r\n")
			#sleep(1);  // Delay of 1000 milli seconds or 1 second
			#ToGSM.write("AT+CMGS=\"+91xxxxxxxxxx\"\r\n"); // Replace x with mobile number
			#sleep(1);
			#ToGSM.write("I am SMS from GSM Module\r\n");// The SMS text you want to send
			#sleep(1);
			#ToGSM.write((char)26);// ASCII code of CTRL+Z
			#sleep(1);
	elif buf == "Baby is safe.": 
			ToMPU.write("0") # signal the MCU (mega32U4) to initiate the mp3 palyer

        #break    

	# send "1" to the Arduino sketch on ATMega32U4.
    # the sketch will turn on the LED attached to D13 on the board
    #s.write("1")
    #time.sleep(1)
    # send "0" to the sketch to turn off the LED
    #s.write("0")
    #time.sleep(1)


if __name__ == '__main__':
    setup()
    while True:
        loop()

Credits

Ehsan Aerabi

Ehsan Aerabi

18 projects • 60 followers
Researcher on IoT and Embedded Systems

Comments