HOW TO MAKE
Constructing the Sensor
Crafting the brooch
- Felt -visit this tutorial for a more in depth guide for cutting and felt templates!
- Connective thread
- Glue or thread to connect the pieces
- Soldering iron and solder
- Wire strippers
- Clear nail polish
- Safety pin or magnet
Assembling the Device:
*Try to be near a window while you’re testing the device so you can test the UV sensor*
Before sewing and soldering the device, test the connections with alligator clips.
Attach alligator clips to the connections shown above.
Now, it’s time to upload the code to the Flora but before you do that you need to set up the Arduino IDE.
Set Up Arduino:
You’ll need to install the Flora board and set up the following libraries:
- Adafruit IDE – first, download the correct version of Arduino for your system from this link
- Then install the Flora board by going to “Tools-Board-Boards Manager” and searching for the Adafruit Flora. Restart after it’s downloaded.
- Under libraries, install libraries for:
- Adafruit SI1145
- Adafruit Unified Sensor
- Adafruit Bluefruit
Now that you’re all set up, it’s time to see if it’s working.
Test your UV Sensor and Piezo buzzer to see if they’re working.
Copy and paste this Adafruit code into Arduino. Since our Piezo buzzer is plugged into D9, change “int speaker = 1;” to “int speaker = 9;”
So how does the code get from the computer to the board? You have to upload it from Arduino! Plug Flora into your computer using the mini-USB cable it came with. Double check and make sure Flora is selected under “board”.
In Arduino, the arrow icon uploads code to Arduino boards while the checkmark icon verifies the code to check for errors. You should always verify your code before you upload it.
Once you’ve verified your code, click the arrow to upload it.
Since the UV threshold is set to very low in this example, the piezo buzzer should go off immediately.
If the buzzer doesn’t work, double-check all your connections and make sure you updated the speaker var!
Now that we know our UV and Piezo buzzer are working, it’s time to test the Bluefruit!
First, download our code and upload it to the Flora board. You’ll notice it’s not doing anything yet.
After uploading the code to your device, open up the serial monitor. This is found in Arduino under “Tools-Serial Monitor.” The serial monitor is how you monitor what’s going on inside your Flora. The code first checks the UV sensor, and then checks for the Bluefruit.
You’ll notice it says: “Connect to Bluefruit in UART mode” what does this mean? Well, like any other Bluetooth device you can connect your brooch to your phone, but before you do that there are a few other steps to take.
Set up Adafruit IO account & feed for your sun brooch:
- Create an Adafruit account and click “Join Open Beta” on this page
- Under “Your Dashboards” create a new dashboard for your sun brooch
- Get your AIO key. (you’ll need this when you’re setting up the Bluefruit) To do this, click the key button in the upper right-hand side of your dashboard
- Email the key to yourself so you can paste it into the Bluefruit app on your device
Connect to Bluefruit:
- Make sure the Bluefruit is on and connected properly
- Download Bluefruit LE app
- Select your Bluefruit, when it asks which mode to connect to, pick UART
- You may have to download updates when you first connect to the Bluefruit. This may take a while.
- If the UV sensor is working, you should see your levels on the screen
Now that the Bluefruit is connected to your phone, it’s time to connect it to the Adafruit IO account you made.
- Select MQTT in the right-hand corner:
- URT RX:
(your Adafruit IO username- one word)/feeds/(Your feed name-one word)
Username: Your AIO username
Password: Your AIO key (the one you emailed yourself earlier)
- Refresh your feed board to see if the Bluefruit connected
And now it’s working! You have your very own sun tracker.
Right now, the code only works with the Serial Monitor open. Since the serial monitor can only be open when Flora is plugged into the computer, you want to deactivate this feature after you’re done setting up the code in order to make the Brooch portable. To do that, comment out these lines of code under setup:
Now you can plug your battery in and use it without the computer.
*Be sure to turn the Flora when using the battery*
For testing purposes, the UV index is printing to the serial monitor and the Bluefruit instead of the average UV. To fix this, comment out the “UV: UVindex” line and uncomment the line that prints the average to the serial + change the “ble.println” to print the average. It should look like this:
Now that all our code is working, it’s time to put it all together.
Here’s where things get creative. As long as you complete the circuit we’ve outlined above, you can put the brooch together however you like.
To complete the circuit, you can either use conductive thread or soldering. Both have their own pros and cons:
- Pros – no extra equipment required, easier seamless integration into fabric
- Cons – since the thread is made of strands of steel, it is very stringy and finicky to sew with. You must take care to not let stray threads touch other threads because that can cause a short circuit.
- Pros – much quicker than sewing, less likely to cause a short circuit
- Cons – Can be bulky and difficult to integrate into fabric, requires a soldering iron and solder.
If you have never sewn with conductive thread or soldered we highly recommend watching tutorials and practicing before you use either method to connect your device. Here are Adafruit’s tutorials on sewing with conductive thread and soldering.
For our brooch we used a mixture of soldering and conductive thread. However, you definitely don’t need to do both.
The only requirement is that the UV sensor be facing outward so it can sense the sun.
Adjusting the Code:
Now that you’ve assembled your sun tracker, it’s time to adjust the sensor thresholds.
Right now, the code is taking the running average of your UV index and notifying you once that average reaches a certain level.
To change the threshold and the reminder interval, change these two variables:
If you want to track your sun levels but don’t want the piezo buzzer reminder, comment out the “checkUV();” line under “loop.” This is what calls the function that sets off the buzzer once your average exceeds the threshold. Instead of using the buzzer, you can always use an IFTTT recipe.
Changing your feed & making recipes:
Now that all the hard stuff is over, here comes the fun part.
The information from your UV sensor is being sent to the Adafruit IO dashboard, but now we need a way to display that information in the IO dashboard.
To do this, click the plus sign in the upper right-hand corner:
Select the “line chart” at the bottom of the list
Update the Y-axis values to reflect your feed data:
And now you have a line chart of your UV levels over time! Yay!
Since all our sun data is being stored in our Adafruit IO we can now set up recipes with IFTTT (it stands for if this-than-that)
Here you can see some of the Adafruit recipes people have already created.
But we encourage you to make whatever recipe that will help you when your sun-levels are too low (or too high)