Kitty Yeung
Published © CC BY-SA

Mother and Child - DFRobot Bluno Beetle

A pair of Bluetooth connected flower brooches sends alert to mother when the child is out of proximity. When close by, both light up.

IntermediateFull instructions provided24 hours3,013
Mother and Child - DFRobot Bluno Beetle

Things used in this project

Hardware components

Beetle - The Smallest Arduino
DFRobot Beetle - The Smallest Arduino
×2
Solar Cockroach Vibrating Disc Motor
Brown Dog Gadgets Solar Cockroach Vibrating Disc Motor
×1
LilyPad Rainbow LED (6 Colors)
SparkFun LilyPad Rainbow LED (6 Colors)
×2
LilyPad Coin Cell Battery Holder - Switched - 20mm
SparkFun LilyPad Coin Cell Battery Holder - Switched - 20mm
×4
Coin Cell Battery CR2032
Coin Cell Battery CR2032
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Central and Peripheral schematics

Code

Central code

Arduino
#include <SoftwareSerial.h>
//#include <LiquidCrystal_I2C.h>

//LiquidCrystal_I2C lcd(0x20,16,2);
SoftwareSerial mySerial(0, 1); // RX, TX

const int ledBLE1 = 2;
const int ledBLE2 = 3;
const int ledBLE3 = 4;
typedef enum {START, WAIT_AT, WAIT_RSSI, WAIT_EXIT, MODE_AT} state_type;

state_type state = MODE_AT;
char chr;
String buffer, rssi, data;
bool reading = false;
void mode_at();
void  wait_rssi();
void wait_exit();
void setup() {
   mySerial.begin(115200);
   Serial.begin(115200);      //Initiate the Serial comm
   pinMode(ledBLE1, OUTPUT);
   pinMode(ledBLE2, OUTPUT);
   pinMode(ledBLE3, OUTPUT);
   state = MODE_AT;
  // lcd.init();                      // initialize the lcd 
   //lcd.backlight();
  
 }

void loop() {
   if(state==MODE_AT){
   mySerial.println(1);
    mode_at();
     delay(3000);
  }else if(state == START) {
      delay(100);
      start();
  }else if(state == WAIT_AT) {
    delay(100);
    wait_at();}
  else if(state == WAIT_RSSI) {
    delay(100);
    wait_rssi();
  }else if (state == WAIT_EXIT) {
    wait_exit();
    delay(3000);
  }
}

void start() {
  delay(10);
  Serial.print("+++");
  state = WAIT_AT;
}

void wait_at() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == 'E') {
         reading = true;
         buffer = "";
      }
      if (chr == 'O'&&buffer!="ERR") {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;
      }
      if (reading && buffer == "ERROR CMD\r\n") {
        reading = false;
        state = START;
      }
      if (reading && buffer == "Enter AT Mode\r\n") {
         Serial.println("AT+RSSI=?");
         Serial.flush();
         reading = false;
         state = WAIT_RSSI;}
          if (reading && buffer == "OK\r\n") {
         Serial.println("AT+RSSI=?");
         Serial.flush();
         reading = false;
         state = WAIT_RSSI;}
   }
 }


void wait_rssi() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == '-') {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;       
      }
      if (buffer.length() == 4) {
         rssi = buffer;
         //lcd.clear();
          //lcd.setCursor(0, 0);
          // lcd.print("dBm=");
          //lcd.print(rssi);
         // mySerial.println(rssi);
           //mySerial.println(5);  
         reading = false;
         if (rssi < "-040") {
            digitalWrite(ledBLE1, HIGH);
            digitalWrite(ledBLE2, LOW);
            digitalWrite(ledBLE3, LOW); 
            }
            else if (rssi >= "-040"&&rssi<"-070") {
                digitalWrite(ledBLE1, LOW);
                digitalWrite(ledBLE2, HIGH);
                digitalWrite(ledBLE3, LOW);
            }
            else if (rssi >= "-070") {
                digitalWrite(ledBLE1, LOW);
                digitalWrite(ledBLE2, LOW);
                digitalWrite(ledBLE3, HIGH);
            }
             state = WAIT_EXIT; 
      }
   }
   Serial.println("AT+EXIT");
   Serial.flush();
  
}

void wait_exit(){
  while (Serial.available() > 0) {
    chr = Serial.read();
    if (chr == 'O'&&buffer!="ERR") {
      reading = true;
      buffer = "";
    }
    if (chr == 'E') {
      reading = true;
      buffer = "";
    }
    if (reading) {
      buffer += chr;
    }
    mySerial.println(buffer);
    if (reading && buffer == "ERROR CMD\r\n") {
      reading = false;
      state = WAIT_RSSI;}
    if (buffer == "OK\r\n") {
      reading = false;
      state = START;
    }
  }
}

void mode_at() {
   Serial.println("AT\n\n");
   Serial.flush();
  while (Serial.available() > 0){
    chr = Serial.read();
    if (chr == 'O'&&buffer!="ERR") {
      reading = true;
      buffer = "";}
    if (chr == 'E'){
      reading = true;
      buffer = "";}
    if (reading) {
      buffer += chr;}
      mySerial.println(buffer);
    if (reading && buffer == "ERROR CMD\r\n") {
      reading = false;
      state=MODE_AT;}
      if(buffer == "OK\r\n") {
         reading = false;
         state = WAIT_AT;}
    }
    state = START;  
  }

Peripheral code

Arduino
#include <SoftwareSerial.h>
//#include <LiquidCrystal_I2C.h>

//LiquidCrystal_I2C lcd(0x20,16,2);
SoftwareSerial mySerial(0, 1); // RX, TX

const int ledBLE1 = 5;

typedef enum {START, WAIT_AT, WAIT_RSSI, WAIT_EXIT, MODE_AT} state_type;

state_type state = MODE_AT;
char chr;
String buffer, rssi, data;
bool reading = false;
void mode_at();
void  wait_rssi();
void wait_exit();
void setup() {
   mySerial.begin(115200);
   Serial.begin(115200);      //Initiate the Serial comm
   pinMode(ledBLE1, OUTPUT);

   state = MODE_AT;
  // lcd.init();                      // initialize the lcd 
   //lcd.backlight();
  
 }

void loop() {
   if(state==MODE_AT){
   mySerial.println(1);
    mode_at();
     delay(3000);
  }else if(state == START) {
      delay(100);
      start();
  }else if(state == WAIT_AT) {
    delay(100);
    wait_at();}
  else if(state == WAIT_RSSI) {
    delay(100);
    wait_rssi();
  }else if (state == WAIT_EXIT) {
    wait_exit();
    delay(3000);
  }
}

void start() {
  delay(10);
  Serial.print("+++");
  state = WAIT_AT;
}

void wait_at() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == 'E') {
         reading = true;
         buffer = "";
      }
      if (chr == 'O'&&buffer!="ERR") {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;
      }
      if (reading && buffer == "ERROR CMD\r\n") {
        reading = false;
        state = START;
      }
      if (reading && buffer == "Enter AT Mode\r\n") {
         Serial.println("AT+RSSI=?");
         Serial.flush();
         reading = false;
         state = WAIT_RSSI;}
          if (reading && buffer == "OK\r\n") {
         Serial.println("AT+RSSI=?");
         Serial.flush();
         reading = false;
         state = WAIT_RSSI;}
   }
 }


void wait_rssi() {
   while (Serial.available() > 0) {
      chr = Serial.read();
      if (chr == '-') {
         reading = true;
         buffer = "";
      }
      if (reading) {
         buffer += chr;       
      }
      if (buffer.length() == 4) {
         rssi = buffer;
         //lcd.clear();
          //lcd.setCursor(0, 0);
          // lcd.print("dBm=");
          //lcd.print(rssi);
         // mySerial.println(rssi);
           //mySerial.println(5);  
         reading = false;
         if (rssi < "-040") {
            digitalWrite(ledBLE1, LOW);

            }
            else if (rssi >= "-040"&&rssi<"-070") {
                digitalWrite(ledBLE1, HIGH);

            }
            else if (rssi >= "-070") {
                digitalWrite(ledBLE1, LOW);

            }
             state = WAIT_EXIT; 
      }
   }
   Serial.println("AT+EXIT");
   Serial.flush();
  
}

void wait_exit(){
  while (Serial.available() > 0) {
    chr = Serial.read();
    if (chr == 'O'&&buffer!="ERR") {
      reading = true;
      buffer = "";
    }
    if (chr == 'E') {
      reading = true;
      buffer = "";
    }
    if (reading) {
      buffer += chr;
    }
    mySerial.println(buffer);
    if (reading && buffer == "ERROR CMD\r\n") {
      reading = false;
      state = WAIT_RSSI;}
    if (buffer == "OK\r\n") {
      reading = false;
      state = START;
    }
  }
}

void mode_at() {
   Serial.println("AT\n\n");
   Serial.flush();
  while (Serial.available() > 0){
    chr = Serial.read();
    if (chr == 'O'&&buffer!="ERR") {
      reading = true;
      buffer = "";}
    if (chr == 'E'){
      reading = true;
      buffer = "";}
    if (reading) {
      buffer += chr;}
      mySerial.println(buffer);
    if (reading && buffer == "ERROR CMD\r\n") {
      reading = false;
      state=MODE_AT;}
      if(buffer == "OK\r\n") {
         reading = false;
         state = WAIT_AT;}
    }
    state = START;  
  }

Credits

Kitty Yeung

Kitty Yeung

19 projects • 184 followers
Physicist/Artist/Musician/Fashion Designer/Engineer www.kittyyeung.com
Thanks to Pearl.

Comments