Jasmeet Singh
Published © CC BY-NC-SA

JMoon MakerSpace Automation System

Control JMoon MakerSpace entrance and lights with 1Sheeld.

IntermediateFull instructions provided3,006
JMoon MakerSpace Automation System

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
1Sheeld
1Sheeld
×1
2 Channel Relay Module
×1
Bo Motor - L Shaped
×1

Story

Read more

Code

Untitled file

Arduino
//***** 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.

Credits

Jasmeet Singh

Jasmeet Singh

2 projects • 10 followers
I am the founder of JMoon Technologies(http://JMoon.co), RoboRium(http://RoboRium.com) and JMoon L.A.B.S. & MakerSpace (http://JMoonLabs.com/MakerSpace)

Comments