Introduction: LightBlueBean+ Music Box

This is a bluetooth connected music box with time tracking on when it is opened and closed. It was made for the Foundations of Wearable & Ubiquitous Computing class I am taking at Rochester Institute of Technology. It logs the time when it is opened or closed, displays the last time it was opened on the screen, plays a song when open, and also sends the time and state data over bluetooth to the computer which sends it to a web server which displays it on a web page in real time.

Step 1: Parts, Tools, and Software



  • 1 Knife (or some sharp object to cut a rectangle in the top of the box)
  • 1 Bluetooth Enabled Computer (I'm using a mac.)


Step 2: Assembly - Preparing the Box

    Trace the outline of the of the LCD onto the top of your box. (Trace only the screen part, not the whole circuit board, we want the board to stay on the inside of the box.)

    Carefully cut along the lines you made using the knife. A scissor might work, but we want the rectangle to be as exact as possible, so we can mount the LCD snugly without having to really secure it.

    Step 3: Assembly - Preparing the Electronics

    Attach a grove cable to each of the grove components.

    Attach the Grove Board to the LightBlueBean+. Make sure attached correctly, the writing on both of them should be facing the same direction. The number of pins on the right and left are different, so if attached incorrectly it will not work.

    Switch the LightBlueBean+'s voltage to 5V instead of 3.3V. There is a small switch for this next to pin A4 and A5. The LCD screen requires 5V to run, so if you forget to switch this the LCD won't work.

    Let's plug in our components!

    The LCD and the RTC should be plugged into I2C ports on the underside of the grove board. These ports allow two way communication between our components and the LightBlueBean+, but they also require us to use libraries to interact with the components.

    The Magnetic Switch should be in port D0/D1, and the Buzzer should be in port D1/D2. These ports allow for one way digital communication. They can be either OUTPUT or INPUT, and they can only read or write 0's (LOW) and 1's (HIGH).


    Put some fun-tak around the edges of the LCD display, and on the backs of the Magnetic Switch and the Buzzer.

    Step 4: Assembly - Setting Up the Box

    Push the LCD display through the hole we made in the top of the box. The fun-tak should help it stay securely. If it feels like it might fall out, find some tape or something to secure it with.

    Put the LightBlueBean+ and the rest of the components and wires into the bottom of the box.

    Take the Magnetic Switch and stick it to the left corner of the box as close to the rim as you can get it. You want the cable side on the bottom so the magnetic sensor is as close to the rim as you can get it. If the fun-tak isn't enough to get it to stay, you might need to get creative.

    Stick the Buzzer somewhere out of the way. (Again get creative if it's not sticking.)

    And you can just leave the RTC hanging out in the bottom of the box.

    Last you need to put some fun-tak on the back of the magnet, and stick it to the lid. You want it to end up being right over the Magnetic Switch when the box is closed, and far away from the Magnetic Switch when the box is open.

    Make sure it all closes and opens easily, and the components feel secure.

    Step 5: Code - Bean Loader and Arduino Setup for Mac

      If you don't already have Arduino and the Bean Loader downloaded, do that. There are links in Step 1.

      Also turn on the Bluetooth on your computer.

      Open the Bean Loader, and when it asks you to Associate with Arduino, make sure you choose Arduino_1.6.8 if you have multiple versions on your computer.

      Open Arduino 1.6.8.

      Set the Board to LightBlue Bean+ (2.0.0).

      Set the Port to /dev/cu.LightBlue-Bean.

      Set the Programmer to Bean Loader.

      (This is a lot more complicated for windows, you can find the instructions on the Bean website.

      Turn your Bean on and connect to it through the Bean Loader. Then double click on the name and change it to something unique.

      Adding Libraries

        Download the Grove - RTC Library.

        Download the Grove - LCD RGB Library.

        Go to Sketch -> Include Library -> Add .ZIP Library and choose the .zip files you downloaded.

        Step 6: Code - RTC Setup

        In Arduino go to File -> Examples -> RTC -> SetTimeAndDisplay.

        It should open an example file.

        In void Setup() change the time and date information to the current time and date. You might want to set the time to a minute ahead because it will take some time to compile and upload to the LightBlueBean+.

        Here is an example of the section of code that you need to change.

        clock.fillByYMD(2016,12,12);//Dec 12,2016<br>clock.fillByHMS(14,30,30);//14:30 30"

        Next click the arrow at the top of the Arduino window to compile and upload your code to the Bean Loader.

        SetTimeAndDisplay should appear in the lower left corner of the Bean Loader as your Available Sketch.

        In the Bean Loader, connect to your Bean+.

        Right click on the name and choose "Program Sketch".

        Go to Tools -> Serial Monitor in Arduino to pen the Serial Monitor, and when the sketch is successfully programmed you should see the Serial Monitor printing out the current date and time, and counting up the seconds.

        The RTC will now remember this time, keep counting even when the Bean is off or it is unplugged, and we will use this information in the main program.

        Step 7: Code - Arduino Code

        Unzip the file and open it in Arduino.

        Upload it to the Bean Loader, and from the Bean Loader to your Bean.

        If it works, you should see the current time and the last time it was opened (or when the program started) on the LCD screen. When you open it, it should play twinkle twinkle little star. And it should be quiet when you close the box.

        Step 8: Code - Javascript Code

        This code connects to the Bean, and receives Scratch data (in server.js) and then sends it to a websocket that updates the information on a web page.

        You need to edit one line of code in server.js before this will work with your Bean.

        On line 60 you need to change the name of the Bean it is searching for to the name you gave your Bean.

        var desiredDevices = ["Your Bean's Name Here"];

        Run the program by navigating into the folder in terminal. Then type 'node server.js' That will start the server and run the program.

        Open the HTML file in a browser, and once it connects to your Bean it will show you the status and keep a running list of the previous reports.

        Step 9: Enjoy!

        I hope you liked my little project. It was fun to make. Feel free to reuse my code and project, but do remember to give me credit if you are gong to use it with very little changes.

        Thanks for reading!