You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Create a Puzzle Box with the help of the Arduino Cloud!**
24
24
25
-
Keeping your valuable items away from prying eyes can be hard sometimes, unless you put it in a big safe or something similar... but who has room for that? Instead, create your own puzzle box using the components from the IoT Bundle and some cardboard! We can't guarantee the safety of your belongings, but at least it will be a fun deterrent for potential thieves. Of course, we advise you to stash your candy in there... not actual valuables.
25
+
Keeping your valuable items away from prying eyes can be hard sometimes unless you put them in a big safe or something similar... but who has room for that? Instead, create your own puzzle box using the components from the IoT Bundle and some cardboard! We can't guarantee the safety of your belongings, but at least it will be a fun deterrent for potential thieves. Of course, we advise you to stash your candy in there... not actual valuables.
26
26
27
27
### In a Nutshell
28
28
29
-
In order to open the box, which is held closed with a servo motor, you will have to turn the potentiometers until you get the right combination. The combination can be set through the dashboard on the Arduino Cloud. An LED will help you guess, giving you colour feedbacks: the closer you are, the warmer the color. When the right combination is guessed, the box will open and a victorious melody will start playing, revealing whatever you have locked inside. In order to create our puzzle box we will need the following components:
29
+
In order to open the box, which is held closed with a servo motor, you will have to turn the potentiometers until you get the right combination. The combination can be set through the dashboard on the Arduino Cloud. An LED will help you guess, giving you color feedback: the closer you are, the warmer the color. When the right combination is guessed, the box will open and a victorious melody will start playing, revealing whatever you have locked inside. To create our puzzle box we will need the following components:
30
30
31
31
* Buzzer
32
32
* RGB LED
@@ -76,7 +76,13 @@ We will start by setting up the Arduino Cloud by following the steps below:
We will use the RGB LED as a feedback to help people guessing the combination, the closer they get to the right value the warmer the colour of the LED, spanning from blue, aqua, yellow and red.
385
+
We will use the RGB LED as feedback to help people guess the combination, the closer they get to the right value the warmer the color of the LED, spanning from blue, aqua, yellow and red.
Now we are starting to put things together: we have connected the potentiometers to unlock the box, created two dashboards for setting the combination and seeing your current position, as well as installed a RGB which will tell you how close you are to the right combination.
508
+
Now we are starting to put things together: we have connected the potentiometers to unlock the box, created two dashboards for setting the combination and seeing your current position, as well as installed an RGB which will tell you how close you are to the right combination.
503
509
504
510
- Note that we will use the function `giveColorFeedback()` to set the color of the RGB LED when the absolute value of each potentiometer is closer than a certain threshold to the correct combination.
505
511
@@ -509,7 +515,7 @@ void giveColorFeedback(int PotOne, int PotTwo, int PotThree){...}
509
515
510
516
- Note that the initial value is set to 1, it will change only if you modify the values of the sliders on the Cloud dashboard. If you reset the board the combination will be back to the default value.
511
517
512
-
A boolean variable **bool start = true;** is used to detect when the combination has already been guessed, so to avoid reopening the the box at every loop.
518
+
A boolean variable **bool start = true;** is used to detect when the combination has already been guessed, to avoid reopening the the box at every loop.
513
519
514
520
Upload this example sketch and turn the potentiometers to see it in action.
515
521
@@ -661,7 +667,7 @@ We will use the buzzer to play a melody when the box is opened. Connect the buzz
Now, navigate into the Arduino Web Editor through **Thing > Sketch tab > open full editor**. This will open up our automatically generated sketch in the full Arduino Web Editor. Next we need to add an extra tab containing all the necessary notes to play the song. Click the arrow on the right side to add a new tab called `"Melody.h"` and add the code below.
670
+
Now, navigate into the Arduino Web Editor through **Thing > Sketch tab > open full editor**. This will open up our automatically generated sketch in the full Arduino Web Editor. Next we need to add an extra tab containing all the necessary notes to play the song. Click the arrow on the right side to add a new tab called `"melody.h"` and add the code below.
665
671
666
672
```
667
673
#define NOTE_B0 31
@@ -778,13 +784,13 @@ void playMelody() {
778
784
}
779
785
```
780
786
781
-
Now, we need to go back to our main sketch to play the melody. In order to use the notes we need to add " **#include "Melody.h"** " at the top of our code and inside **setup()** we need to add our **buzzerPin** as **Output.** To test our melody we can call **playMelody()** inside **loop()** if the combination has been set right.
787
+
Now, we need to go back to our main sketch to play the melody. In order to use the notes we need to add " **#include "melody.h"** " at the top of our code and inside **setup()** we need to add our **buzzerPin** as **Output.** To test our melody we can call **playMelody()** inside **loop()** if the combination has been set right.
782
788
783
789
```
784
790
#include "LiquidCrystal.h"
785
791
#include "SPI.h"
786
792
#include "thingProperties.h"
787
-
#include "Melody.h"
793
+
#include "melody.h"
788
794
/* RGB LED pins */
789
795
int redPin = 6;
790
796
int greenPin = 8;
@@ -941,19 +947,19 @@ void onDisplayChange() {
941
947
942
948
> **Note:** for the servo motor you will need a 9V battery which is not included in the IoT Bundle! Alternatively you can use another external power supply such as a phone charger with open ended cables.
943
949
944
-
The servo motor is the lock of our box, we will need it to turn 90 degrees when the combination is correct, so that the box will open. Connecting the servo only requires three wires though you will need a 9V battery to power the servo motor. Connect **9V**, **GND** and **pin9** as shown below.
950
+
The servo motor is the lock of our box, we will need it to turn 90 degrees when the combination is correct so that the box will open. Connecting the servo only requires three wires though you will need a 9V battery to power the servo motor. Connect **9V**, **GND** and **pin9** as shown below.
To use the servo motor we need to `#include "Servo.h"` at the top of our code as well as set starting position to 0 and include the `Servo myservo` object. Now we can create two functions, one for opening the box and one for closing it.
956
+
To use the servo motor we need to `#include "Servo.h"` at the top of our code as well as set the starting position to 0 and include the `Servo myservo` object. Now we can create two functions, one for opening the box and one for closing it.
951
957
952
958
```arduino
953
959
#include "LiquidCrystal.h"
954
960
#include "SPI.h"
955
961
#include "thingProperties.h"
956
-
#include "Melody.h"
962
+
#include "melody.h"
957
963
#include "Servo.h"
958
964
int pos = 0;
959
965
Servo myservo;
@@ -1110,7 +1116,7 @@ void onDisplayChange() {
1110
1116
}
1111
1117
```
1112
1118
1113
-
Note that in order to turn the servo back and close the box all you'll have to do is to turn all potentiometer to 0.
1119
+
Note that in order to turn the servo back and close the box all you'll have to do is to turn all potentiometers to 0.
1114
1120
1115
1121
### Build Your Puzzle Box
1116
1122
@@ -1127,4 +1133,184 @@ This tutorial is part of a series of experiments that familiarize you with the A
0 commit comments