Project tutorial
JMoon MakerSpace Automation System

JMoon MakerSpace Automation System © CC BY-NC-SA

Control JMoon MakerSpace entrance and lights with 1Sheeld.

  • 2,046 views
  • 1 comment
  • 21 respects

Components and supplies

About this project

This project is for the 1sheeld Makerspaces Competition.
The project automates 3 main things at the JMoon MakerSpace:

  1. Door Lock
  2. Lights
  3. Noise


For the code to work perfectly, Go to Arduino -> libraries -> OneSheeld -> "VoiceRecognitionShield.h" and add the following line to the public function declarations –

void clearCommand();

Then go to Arduino -> libraries -> OneSheeld -> "VoiceRecognitionShield.cpp" and add this function at the end of the file –
void VoiceRecognitionShield::clearCommand(){voice = NULL;}

This function makes sure that once a Voice command has been executed, it is no longer stored. If you do not add this function, the previous Voice command will keep on executing, till a new Voice command is spoken.

This project uses the following sensors of the phone-

  1. GPS (GPS should be turned on)
  2. TEXT TO SPEECH
  3. ORIENTATION SENSOR
  4. VOICE RECOGNIZER (Needs Internet Access)
  5. MIC
  6. CAMERA

and DATA LOGGER is used to store csv data in the phone.

The project requires 2 passwords- 1 for entering the makerspace, and 1 for locking up at the end of the day.

The commands for turning light on/off or taking photos can also be setaccording to the user.

A relay module (Active LOW) is used to control the bulb/lamp. When a HIGH signal is sent to the module, the switch controlling the light is turned off. A DC motor mounted at the end of a glue-stick (hollowed out) to create an electronic linear lock.

When the app is turned on, the phone makes sure that it is at the location of JMoon MakerSpace (Long:77.0769698, Lat: 28.6274036). If not, then the user is requested to go to the location. If it is at the right location, the user is asked to enter the password to open the lock.

The lock is opened after 2 steps.
1. The phone must have the right orientation, once that is confirmed, the user is asked for
2. Entry password. You need to press the voice recognition before speaking the password.

Orientation is only required again if you lock up the makerspace.

If the password is confirmed, the electronic linear lock is opened, and the entry time is logged.

After this, Voice Recognition is activated automatically so you can speak a command any time. These commands can be- switching on the light, switching off the light, taking pictures with front and rear camera, detecting noise level, locking up the makerspace (which involves, switching off the lights, closing the electronic linear lock and logging in the exit time).

After locking up, to enter makerspace again, you have to start from the orientation check (while the app is turned on). If you are connecting to the 1sheeld again (after losing connection or turning off app) then the code will start with checking the GPS coordinates.


What the project can do-


Complete Video



Code

Untitled fileArduino
//***** JMoon MakerSpace Automation System *****
// Dated: 11th May 2015
// Built at JMoon MakerSpace http://JMoonMaker.space
// For OneSheeld Makerspace Contest http://1sheeld.com/makerspaces
// JMoon MakerSpace Automation System by JMoon Technologies Pvt. Ltd. is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// Requirements: Arduino/Mega, OneSheeld, Android Phone with 1Sheeld app Installed, Door with Electronic Linear Lock System, Relay Switch

// For this code to work perfectly, Go to Arduino -> libraries -> OneSheeld -> VoiceRecognitionShield.h
// and add the following line to the public function declarations-
// void clearCommand();
// Then go to Arduino -> libraries -> OneSheeld -> VoiceRecognitionShield.cpp
// and add this function at the end of the file-
/* void VoiceRecognitionShield::clearCommand(){
     voice = NULL;
  }
*/
// This function makes sure that once a Voice command has been executed, it is no longer stored.
// If you do not add this function, the previous Voice command will keep on executing, till a new Voice command is spoken.

//Defining all the sensor shields which will be used
#define CUSTOM_SETTINGS
#define INCLUDE_GPS_SHIELD
#define INCLUDE_TEXT_TO_SPEECH_SHIELD
#define INCLUDE_ORIENTATION_SENSOR_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#define INCLUDE_MIC_SHIELD
#define INCLUDE_DATA_LOGGER_SHIELD
#define INCLUDE_CAMERA_SHIELD

#include<OneSheeld.h>

String openpass = "password"; //Password for Opening Main Door of Makerspace
String lockpass = "alrighty then"; //Password for Locking Main Door of Makerspace
String lighton = "light on"; //Turn Light ON
String lightoff = "light off"; //Turn Light OFF
String picture = "selfie"; //Take Photos
// String love = "i love you" // For Fun and Testing.

int Light = 22; //Relay for Light Bulb
int LockMotor1 = 24; //Motor Pin1 (When this is HIGH, Lock Closes)
int LockMotor2 = 25; // Motor Pin2 (When this is LOW, Lock Closes)
float longitude, latitude; // GPS location
int lock = 0; //0=closed, 1= open
int orientation=0; //Check Phone Orientation. 1 = orientation confirmed.

void setup()
{
  OneSheeld.begin();
  pinMode(Light, OUTPUT);
  digitalWrite(Light, HIGH); //Relay is Active LOW (HIGH = Light is off Initially)
  pinMode(LockMotor1, OUTPUT);
  pinMode(LockMotor2, OUTPUT);
  digitalWrite(LockMotor1, LOW); // Motor is initially off
  digitalWrite(LockMotor2, LOW);
  delay(2000);
  Logger.stop(); 
}

void loop()
{
  // Keep reading GPS till the phone comes to the location of JMoon MakerSpace (Long:77.0769698, Lat: 28.6274036)
  while(1){  
    longitude = GPS.getLongitude();
    latitude = GPS.getLatitude();
    if(longitude>=77.05 && longitude<=77.09 && latitude>=28.60 && latitude<=28.64)
      goto getpass;
    else
      TextToSpeech.say("Take me to J Moon maker space to enable");
    OneSheeld.delay(5000);
  }
  getpass:
  // Keep checking orientation till X & Y have the right values
  TextToSpeech.say("Do the Secret Twist");
  while(orientation==0){
    if((OrientationSensor.getX()>120) && (OrientationSensor.getY()>0))
    {orientation=1;
      break;}
    else
      OneSheeld.delay(2000);
  }
  // Once "orientation" is confirmed, the above loop is not executed, even if the password spoken below is incorrect.
  // It is only executed again if you lock up the space.
  // This is the only time you need to press the button for a Voice command.
  TextToSpeech.say("Speak password to enter");
  OneSheeld.delay(2000);
  if(VoiceRecognition.isNewCommandReceived() && VoiceRecognition.getCommandAsString()==openpass){
    // Open Electronic Linear Lock
    TextToSpeech.say("Opening Lock");
    digitalWrite(LockMotor1, LOW);
    digitalWrite(LockMotor2, HIGH);
    delay(5000);  // It takes roughly 5 seconds for lock to open completely
    digitalWrite(LockMotor1, LOW);
    digitalWrite(LockMotor2, LOW);
    delay(1000);
    lock = 1; // Lock is open
    // Log the open time
    LogData();
    TextToSpeech.say("Welcome to J Moon Maker Space");
    delay(5000);
    OneSheeld.delay(5000);
    while(1){
      VoiceRecognition.start(); // Voice recognition is executed automatically, no need to press the button anymore.
      if(VoiceRecognition.isNewCommandReceived() && VoiceRecognition.getCommandAsString()==lighton){
        // Light On
        TextToSpeech.say("Switching on the Lights");
        delay(1000);
        digitalWrite(Light, LOW);
        VoiceRecognition.clearCommand();
        OneSheeld.delay(5000); // This delay can be increased according to your own requirements
      }

      if(VoiceRecognition.isNewCommandReceived() && VoiceRecognition.getCommandAsString()==lightoff){
        // Light Off
        TextToSpeech.say("Switching off the Lights");
        delay(1000);
        digitalWrite(Light, HIGH);
        VoiceRecognition.clearCommand();
        OneSheeld.delay(5000); // This delay can be increased according to your own requirements
      }

      if(VoiceRecognition.isNewCommandReceived() && VoiceRecognition.getCommandAsString()==lockpass){
        // Lock up JMoon Makerspace
        TextToSpeech.say("Lights off");
        OneSheeld.delay(2000);
        digitalWrite(Light, HIGH);
        OneSheeld.delay(2000);
        // Close Electronic Linear Lock
        TextToSpeech.say("Locking up");
        digitalWrite(LockMotor1, HIGH);
        digitalWrite(LockMotor2, LOW);
        delay(5000); // It takes roughly 5 seconds for lock to close completely
        digitalWrite(LockMotor1, LOW);
        digitalWrite(LockMotor2, LOW);
        delay(1000);
        lock = 0; // Lock is closed
        // Log the close time
        LogData();
        OneSheeld.delay(2000);
        TextToSpeech.say("Locking Complete. Goodbye!");
        VoiceRecognition.clearCommand();
        orientation=0;  // To enter makerspace again, you have to execute the Secret Twist
        goto getpass;
        OneSheeld.delay(5000); // This delay can be increased according to your own requirements
      }

      if(Mic.getValue() >= 80){
        // Too much noise in the makerspace
        TextToSpeech.say("Do not disturb others");
        delay(2000);
        OneSheeld.delay(5000); // This delay can be increased according to your own requirements
      }

      if(VoiceRecognition.isNewCommandReceived() && VoiceRecognition.getCommandAsString()==picture){
        // Take pictures from rear and front camera. (Use rear camera for photo of your project, and front camera for your reaction watching it work like magic!)
        Camera.setFlash(ON);
        TextToSpeech.say("Rear Camera On");
        Camera.rearCapture();
        OneSheeld.delay(1000);
        TextToSpeech.say("Front Camera On");
        Camera.frontCapture();
        delay(2000);
        VoiceRecognition.clearCommand();
        OneSheeld.delay(5000); // This delay can be increased according to your own requirements
      }
      
      /*if(VoiceRecognition.isNewCommandReceived() && VoiceRecognition.getCommandAsString()==love){
        // For Fun and Testing
        TextToSpeech.say("sorry but I love J Moon Maker space"); // *Sound of your heart breaking after this rejection* :D
        VoiceRecognition.clearCommand();
        OneSheeld.delay(5000); // This delay can be increased according to your own requirements
      }*/
     
     else{
       delay(100);
       OneSheeld.delay(5000);
     }
    } // End of Auto Voice Reconition
  } // End of openpass recognition
  else{
    OneSheeld.delay(5000);
    goto getpass; // Speak Password again
  }
} // End of loop()

void LogData()
{
  Logger.stop();
  OneSheeld.delay(500);
  Logger.start("In and Out");
  if(lock == 1){ // Lock has opened
    Logger.add("In/Out", "In");
    Logger.log(); }
  else { // Lock has closed
    Logger.add("In/Out", "Out");
    Logger.log(); }
  Logger.stop();
}
JMoon Makerspace Automation System
Download the code and onesheeld library for Arduino. Read the instructions on the top of the code and make changes accordingly. Make connections and Upload code to Arduino Mega.

Comments

Similar projects you might like

SMS based Home Automation system using 1SHEELD

Project tutorial by Tanishq Jaiswal

  • 27,241 views
  • 11 comments
  • 63 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,825 views
  • 17 comments
  • 75 respects

Control your light system with your voice

Project tutorial by Maha Raafat

  • 34,852 views
  • 22 comments
  • 153 respects

Home Management System - Control your home from a website

Project tutorial by Ahmed El-Hinidy

  • 31,402 views
  • 21 comments
  • 115 respects

Smart Home Automation And Security System Using 1Sheeld

Project tutorial by Team SADEE

  • 5,509 views
  • 3 comments
  • 25 respects
Add projectSign up / Login