• 1
    Step 1: Building the Hardware

    Start by gathering all of the hardware listed in the parts list above. We will start with the Keypad and LCD circuit and then move onto the Triggers (Motion sensor, distance sensor, and buzzer) circuit.

    The circuit for the keypad and LCD is very simple. You can use a breadboard to build this circuit, but we found it simpler to attach all components directly to the Builder Base.

    Use 7 MM jumper wires and go from left to right to connect the pins from the keypad to the ports on the builder base. So, the left most pin on the keypad is connected to GP0, the second left most to GP1, and so on and so forth.

    Now, connect the Vcc and GND terminals on the LCD to the 5V and GND ports on the Builder Base, and then connect the SDA and SCL pins on the LCD to the SDA and SCL ports on the Builder Base.

    **On the back of the I2C LCD there should be 6 pins. 4 of which are the 5v, GND, SDA and SCL pins, and the other two are used for brightness. These two pins should come connected together, but if they aren't you need to connect them. Otherwise, your LCD will not illuminate.**

    Use the schematic and breadboard views listed below as a reference.

    Now let's assemble the Triggers circuit. We suggest using a breadboard for this circuit as it makes it easier to power all of the components.

    Take your breadboard and attach the GND and Vcc rails to the GND and 5V ports on your Builder Base respectively.

    Now, let's wire the motion sensor. Connect the VCC and GND pins to the 5V and GND rails on the breadboard. Wire the Data pin to the Builder Base as follows:

    Now, we will wire the buzzer. Connect the GND pin on the Buzzer to the GND rail on the breadboard, and wire the positive pin to the Builder Base as follows:

    Lastly, we will wire up the distance sensor. Again, connect the Vcc and GND pins on the distance sensor to the 5v and GND rails on the breadboard. Now wire the Echo and Trigger pins to the Builder Base as follows:

    Congratulations! All of the circuits needed for the Security system are now complete!

  • 2
    Step 2: Build the Firmware

    Since we use two Builder Bases in this project we will need to build two separate firmware files.

    Start by navigating to the firmware builder and create a new firmware named “Security Keypad”.

    Click on the "+ Add Hardware" button and add a LCD and a 4x3 Keypad.

    Now, click on the LCD device and select the "Generic LCD2004 Display (I2C)" driver from the driver drop down menu.

    Configure the driver as follows:

    I2C Address: 0x27

    Layout: 2x16

    Now, we will configure the 4x3 Keypad. You will notice the 4x3 Keypad has 12 services to configure. You can cycle through these by clicking on the left and right arrows.

    For each service you will have to select the Driver, and the row/column pin for the service. Each service corresponds to a button on the keypad. Follow the table below to configure all 12 services.

    When you have all services configured save your firmware!

    Now, create another firmware file named "Security Triggers".

    Now, click the "+ Add Hardware" button and add a Motion Sensor, a Distance Sensor, and an Analog Out device to your file. Name them as we do.

    For the Motion sensor, select the HC-SR501 driver from the driver dropdown menu.

    Configure the driver as follows:

    Pin: GP0

    Now we will configure the Buzzer. Select the "GPIO" Driver from the driver dropdown menu.

    Now we will configure the driver as follows:

    Pin: GP1

    Now, we will configure the Distance Sensor.

    Select the HC-SR04 driver from the driver dropdown menu.

    Now we will configure the driver as follows:

    Echo Pin: GP3

    Trigger Pin: GP2

    Resolution(I): 1

    **Our system is set to imperial in the settings. If yours is set to metric you will likely want to change your resolution type.**

    That's it, your firmware files for the Security System are now complete. Save and upload your firmware files. The Security Keypad firmware should be uploaded to the Builder Base that the Keypad and LCD are connected to, and the Security Triggers firmware should be uploaded to the Builder Base that the Sensor and Buzzer are connected to.

  • 3
    Step 3: Program the Application

    For this application we will walk you through the basic logic involved. You can follow along and build the application as we describe it, or you can download the application and import it into your applications list.

    Here is the Security System application:

    **Please note that this security system application is in a highly prototypical state and does not function flawlessly. We will be updating this application in the coming months to work more effectively.**

    In this description we will break the Application up into four main parts: 1. Code Set, 2. Code Input/Evaluation, 3. Sensor Input, and 4. Arm Alarm Countdown.

    In its current state, when the app is started you need to set the pin code via the dashboard interface. This occurs here in the Code Set portion of the app.

    The pin is set using two custom code blocks. One converts a dashboard button press to a number and the other stores the number in a global context array.

    Number Convert:

    <i>1 </i>if(trigger === 9){ <i>2</i> return[0, new Date()] <i>3 </i>} <i>4 </i>else{ <i>5 </i>return [trigger+1, new Date()] <i>6 </i>}

    Set Pin:

    Now we will take a look at the code input/evaluation section of the program.

    Here we have a 4x3 Keypad object connected to another number convert custom snippet. This takes the digital output from the 4x3 keypad object and depending on the port it is received and converts it into a number. This number convert custom snippet is identical to the one used above.

    This number is the passed into a custom snippet named "Safe?".

    The “Safe?” snippet takes inputs from three ports. The first port “InNode0” serves as a way to arm the system. We arm the system via used of the “*” key on the keypad If a trigger is received from this port, this code executes:

    <i>1</i>case 0:{

    <i>2</i>globalContext.safe = 0; <i>3</i>


    The second port "inNode1" takes in numbers from the number convert custom snippet and stores them in an enter array. When a value is received through this port, this code executes:

    <i>1</i>case 1:{ <i>2</i>

    <i>3</i> context.entr[context.i] = val2; <i>4</i> context.i++; <i>5</i>

    And lastly, the third port serves as the trigger for code evaluation. The third port is connected to the "#" key on the 4x3 Keypad object. When the ''#' key is pressed it acts as the enter button. You can see the code 


    1 if(globalContext.test.length != context.entr.length){ 2 globalContext.safe = 0; 3 context.entr = []; 4 context.j=0; 5 context.i=0; 6 return[globalContext.safe]; 7 } 8

    9 else{ 10 for(var p = 0; p < globalContext.test.length; p++){ 11 if(globalContext.test[p] != context.entr[p]){ 12 globalContext.safe = 0; 13 context.entr = []; 14 context.j=0; 15 context.i=0; 16 return[globalContext.safe];} 17


    19 } 20 globalContext.safe = 1; 21 context.entr = []; 22 context.j=0; 23 context.i=0; 24 return[globalContext.safe]; 25 }

    This section of the program also sends a “*” to the LCD every time one of the numbers on the 4x3 Keypad is depressed. With every number depressed the “Send *” Data sequence is triggered this then increments a count by one that ranges from [10 → 16]. This count corresponds to the column position on the LCD, so that every time a new number is input a new “*” is input after the last. Also, every time the “#” key is depressed this count is reset. Anyways, this number is sent to the column position port on the LCD object.

    The data sequence then triggers the static string block that contains “*”, and sends it to the string port on the LCD.

    Lastly, the data sequence triggers the “Send to Display” port on the LCD, actually making the new message appear on the LCD.

    We will now take a look at the Sensor Input portion of the program.

    We have an initial trigger connected to a custom snippet named “Set Safe”. When the app is initially started, the system is set to the safe position so that the alarm doesn’t instantly trigger.

    Here is the code:

    1 globalContext.safe = 1;

    The initial trigger also triggers the "Enter Code" Data Sequence. This data sequence triggers Static String of "Enter Code:" and send it to the LCD hardware object.

    We will now take a look at how all of the sensors are used as triggers for the alarm.

    All three sensors, the door contact, Motion Sensor, and Distance Sensor, lead into a 2s timeout object. This timeout object then leads into a custom code snippet named Sound Alarm.

    This custom snippet checks to see if the globalContext.safe variable is set to a 0 or a 1. If it is a 1 the system is safe and nothing happens. However, if the variable is set to 0 the string “Intruder Alert” is sent to the “Access G/D Data Sequence via the port “outNode0”, and a trigger is sent the the “Beep Alarm” Oscillator object via the second port “outNode1”.

    The “Stretch Pulse” Pulse Stretcher is then triggered which in turn activates the buzzer.

    If we are entering a code and trying to disarm the system this route from the “#” key on the 4x3 keypad is taken.

    From the 4x3 Keypad the “Access Granted?” custom snippet is triggered, and if the globalContext.safe variable is set to 1, the string “Access Granted” will be passed to the LCD, and the “Access G/D” data sequence will be triggered.

    Here is the code for the “Access Granted?” custom snippet:

    1if(globalContext.safe ===1){ 2 return["Access Granted",new Date()]; 3}

    Lastly, we will take a look at the Arm Alarm Countdown portion of the app.

    When the “*” key is depressed on the 4x3 Keypad the “Countdown Sequence” object, and a 20 second timeout are triggered. These execute simultaneously. After the 20 second timeout is up, the system will be armed as the “inNode0” on the “safe?” block that we discussed earlier will be triggered.

    The countdown sequence object handles the 20 second count down that appears on the LCD screen. First, the LCD is cleared, and then the String “Alarm Armed:” is sent to the “String Merge” object.

    Next, the number 20 is sent to the value port on the data counter object. This value is then passed to the “String B” port on the Data Counter. The conjoined string of “Alarm Armed:” + “20” is then sent through the any data sequence to the LCD.

    The Oscillate code block is then triggered with the count set to 20 and the interval to 1000ms.

    This then triggers the Data counter 20 times, decrementing the counter once per second until the count of 0 is reached. Every time the count is decremented, a new value is sent to the String Merge object, which then passes the new merged string to the “Any Data Sequence”, which finally passes the new string “Alarm Armed:” + “(some new count)” to the LCD.

    Finally, the timeout block that has been running concurrently finishes its timeout and triggers the “Clear” port on the LCD and the “Enter Code:” sequence. This leaves the system in its armed state ready for a code to be entered to disarm it.

    That’s it for programming the application. Save your app and return to the Applications page.