3 easy to build projects using the Sensor Kit and Uno WiFi board from Arduino.
BUILD TIME: 2 HOURS
DIFFICULTY RATING: BEGINNER
If you’ve been looking for a hands-on way of getting into electronics projects without any fuss, we’ll show you how to use the Arduino Sensor Kit and Arduino Uno WiFi to build some custom electronic gadgets!
In addition, we show you how easy it is to make your Arduino projects using the Arduino web editor, and how to send sensor data from the Arduino to your Smartphone.
Pakronics has this Arduino Sensor Kit available as a bundle with two different boards. We got to play with the Arduino WiFi Rev2 bundle.
INTRODUCING THE ARDUINO SENSOR KIT
Around the internet today is a variety of Arduino-based sensor packs, including wires, boards and Arduino microcontrollers for easy experimentation. What many don’t provide is a simple and versatile platform for beginners to quickly get set up in electronics. Thanks to our friends at Pakronics, we recently got our hands on the official Arduino Sensor Kit board, a board system built in collaboration with Seeed and Arduino.
A little while back, Seeed released their Grove Beginners Kit, an all-in-one Arduino-compatible board that allows those entering the world of DIY electronics to experiment with sensors on a single board. Want to build a project with individual sensors? The sensors can be popped out from the circuit board and used separately with the Seeduino Lotus - the board with a grid of white grove connectors in the centre.
The new Arduino Sensor Kit is an official collaboration between Seeed and Arduino. With a combination of 10 sensors and outputs to play with, it’s a great start to understanding how many of the essential components used in electronics products are used. Each sensor can be popped out and connected to the Grove shield with the included connectors.
While they might look and function mostly the same, the new Arduino Sensor Kit no longer operates by itself with an inbuilt processor – which means you need an Arduino Uno (or an Arduino-compatible board in the shape of one) to add onto it as a shield. This opens up more flexibility for beginners – you can now completely remove your Arduino from the bottom of the Sensor Kit and operate it separately for use with other circuits or systems!
If that wasn't enough, the extra space on the board is utilised to include additional analog and digital pins, and two more I2C pins. That means you can hook up more sensors than the original Grove Beginners Kit. Handy!
Pakronics has this Arduino Sensor Kit available as a bundle with two different boards – the Arduino Uno R3 and the Arduino WiFi Rev2. We’ll be using the WiFi Rev2 today, a board with all the bells and whistles of the Uno but with integrated WiFi and Bluetooth compatibility, a brand new processor and the same form factor as the original Uno. It’s compatible with the same WiFi Arduino libraries already available so it’s a highly functional alternative to popular boards like the ESP8266.
We could talk all day about how this Arduino Sensor Kit is a great way of introducing electronics, but we’re going to prove it by building some projects with some cool features! This will be beginner-friendly as possible, so don’t worry if you aren’t an expert with code.
ARDUINO ONLINE EDITOR
Regular readers of DIYODE will know we love the Arduino IDE (Integrated Development Environment) for coding – it includes library support, easy access to changing board settings and even live serial output so we can check what our Arduino is doing. However, not everybody is in a situation where they can install programs, drivers and libraries on computers, especially in educational environments. Many of those on the go or who are using other people’s computer hardware often don’t have the freedom of installing whatever they would like. Additionally, the continual increase in popularity of cloud-based apps such as Google Drive has meant many are transitioning their workflow online – so it’s only logical that us makers should do so too. The online Arduino Editor is a super simple way to develop code on the go, get introduced to coding concepts and then easily upload your code to test it right away!
To get started with the online editor, you’ll need to head over to https://create.arduino.cc/getting-started/plugin and install the Arduino Create Plugin on your computer. This acts as an interface between the Arduino plugged into your USB port and the online editor. After you’ve installed this, there isn’t any other installation required on your computer – all other library and board management is done online!
Clap-Activated Light:
We can do better than “Hello World”! To get started with our Arduino Sensor Kit, we’re going to use the sound sensor and light to create a clap-activated light. We admit, the LED might not be capable of lighting up a room, but it’s a cool project to learn how you can use some of the gadgets on the sensor kit. If you’d prefer to skip all this and just use the completed code, we’ve provided the code in the project files on our website.
To set up our project, we need to create a new sketch within the Online Editor and import the sensor kit library. This makes it super easy to use all of the functionality of the sensor kit, without having to deal with importing individual libraries. This is what the “#include” line does in the following code.
After that, we need to add some variables to control our program. The first one we added is called “is_light_lit” and – spoiler alert! - it helps us track in our program whether the light is lit. Because it is of a “bool” type, it only can have two values: true or false. The other variable “wait_delay” is a number that helps stabilise our light – we’ll explain this more shortly. It is a constant integer, which means it’s a number that can’t change after we’ve uploaded our program.
#include "Arduino_SensorKit.h"
bool is_light_lit = false;
const int wait_delay = 400;
Alright, next up we need to write our setup function. The setup function is run whenever our Arduino board starts up, and only once.
void setup() {
pinMode(A0, INPUT);
pinMode(A2, INPUT);
pinMode(6, OUTPUT);
Serial.begin(9600);
}
You’ll notice we are using a function called “pinMode” – this function sets a certain pin on the Arduino to behave a certain way. The first thing we do is set the pin “A0” to the input mode – this is the potentiometer knob on the sensor board. If you ever are confused about which pins are connected to what, the sensor board shows it on the circuit board. You may be wondering what are we using the potentiometer for? Because the Arduino is very sensitive, environmental noise is enough to set off our clap-activated light. So, we need to use a “sensitivity” which can be adjusted by hand with the potentiometer. Now, it’ll only turn on or off the light when a sound of sufficient volume is detected.
We need to set up the other pins too. The sound sensor is on pin A2 and the LED is on pin D6 (we don’t write the D in Arduino programs). Since of course we are outputting something to the LED, it needs to be set up as an output instead.
Finally, we start up our serial monitor which will help us debug programs. The 9600 is our transmission rate, but this isn’t important for our project.
void loop() {
int soundLoudness = analogRead(A2);
//Sensitivity we set from the potentiometer knob
int sensitivity = analogRead(A0);
if(soundLoudness > sensitivity) {
Serial.println("Triggered the light!");
is_light_lit = !is_light_lit;
digitalWrite(6, (PinStatus)is_light_lit);
delay(wait_delay);
}
}
Finally, we get to the bread and butter of our operation - this code will handle turning on and off our light! The loop() function in Arduino programs continuously runs over and over again, which makes it great for checking sensors. To begin with, we need to read the potentiometer and the sound sensor to collect what values they are reading. This is why we use the “analogRead” function, which gives back a value between 0 and 1023. Next, we compare these values with our “if” conditional – this checks which one is higher. If the value of our sound sensor is higher than our potentiometer, we can register it as a “clap”. First, we print to our serial monitor that we triggered the light, which will help with debugging. We can then toggle our light! This is why we used the “is_light_lit” variable, because we need to remember what we last set the light to. The exclamation mark inverts a Boolean variable, so it turns a True into False or a False into True – toggling! Finally, we write the variable to the LED, which turns it on or off.
The delay() function after this slows down the checking of the sound sensor – if we just registered a clap, when we check the sound sensor again it may still be reading a high value, which toggles the LED again! So, we need to wait for a short amount of time – we set our “wait_delay” variable to 400 milliseconds.
And that’s it! Before uploading, you’ll need to make sure that the WiFi Arduino Board is selected in the drop-down menu at the top of the page. If you have the create plugin installed, it should automatically detect it and select the settings you need. Then, just hit the right arrow on the page to save the sketch and upload it to your Arduino. After a couple of seconds, the sketch should be uploaded. Your Arduino should be running now! Twist the potentiometer knob until you find a sensitivity that works well when you clap. A sensitivity that is too low won’t respond to clapping at all, while a sensitivity that is too high will cause the LED to continually blink on and off.
If you’re having problems, head over to the Serial Monitor on the left side of the screen and check that our serial message is appearing whenever you clap. If the messages are coming up but the LED isn’t lighting, check you have the right pins selected in the setup function.
With any luck, you now have your own working clap-activated light! There are a ton of other inventions you could make with some small modifications to the code we wrote. A “flickering candle” LED that extinguishes when you blow on it would be a fun avenue to go down from here.
Tilt Keyboard:
In this project, we’re going to be experimenting with the OLED screen, buzzer, accelerometer and button to build a tiltable musical keyboard! By just tilting the sensor kit, we can generate a changing pitch from the buzzer when we press the button. This is a great introduction to some more of the sensors available for experimenting with. This code is a bit more advanced, but remember you can just download the code we wrote and experiment with the values in it.
The OLED display included with the sensor kit is one of the most versatile components on board – it allows you to display easily readable text on a very clear screen. We’re going to use it to display live values from the accelerometer. This program is a new sketch, which means it’s separate from the Clap-Activated light – just click on the New Sketch button in the Arduino Editor to create one.
#include "Arduino_SensorKit.h"
void setup() {
Serial.begin(9600);
Oled.begin();
Oled.setFlipMode(true);
Oled.setFont(u8x8_font_chroma48medium8_r);
Accelerometer.begin();
pinMode(4, INPUT);
pinMode(5, OUTPUT);
}
As usual, we’re importing the Sensor Kit library to give us access to the gadgets on board. In our setup function, we’re getting our OLED display set up to display characters. We need to set it to flip mode for it to be the right way up, and we then select a font – there are many fonts available. We then start up our accelerometer and run pinMode to set our buzzer (Pin D5) as an output and our button (Pin D4) as an input. The pins we’re using here aren’t random, the Sensor Kit includes labels for each of the pins showing what sensors are connected to which pins.
void loop() {
Oled.setCursor(0, 0);
Oled.println("X:" + (String)Accelerometer.readX());
Oled.println("Y:" + (String)Accelerometer.readY());
Oled.println("Z:" + (String)Accelerometer.readZ());
//INSERT TILT KEYBOARD CODE HERE
Oled.refreshDisplay();
delay(10);
}
Since we want to experiment with the accelerometer before making our musical keyboard, we’re printing the accelerometer values onto the OLED screen. Our accelerometer detects acceleration on each of the three axes, which means X (forward/back), Y (left/right) and Z (up/down) when looking from the front of the Sensor Kit. When you see values printed to the OLED screen, you’ll notice the Z sits at around 1 – this is detecting the gravity directly downwards! As you tilt the sensor kit, the values on the X, Y and Z axes will change according to which way the sensor is orientated.
Alright, now we can get to adding the code to make the tilt keyboard work. The code below needs to be inserted where we’ve added a comment in the code above. The sensor kit has a buzzer inbuilt, which means we can generate a tone and play a sound of any pitch we want. Arduino includes a tone() function that generates a frequency, where higher frequencies are higher in pitch. So, all we need to do is convert our accelerometer reading to a pitch. We’re using the map() function to convert the acceleration range of -1 to 1 to frequencies 100Hz to 500Hz. The reason we multiply the accelerometer reading by 1000 is that the map() function doesn’t work with fractions of numbers (e.g. 0.75) so we have to convert them to whole numbers first.
Then, if we’re holding down the button on the Sensor Kit (Pin 4), we play the tone on the buzzer pin with the value we created between 100 and 500. At the same time, we want to display the frequency of the note we’re playing on the OLED display. When we use println() in Arduino programs, it automatically inserts a newline character that does the equivalent of pressing “Enter” – it moves the cursor down to the next line for writing more text.
When we aren’t holding the button, we need to make sure we aren’t playing any sound with the noTone() function and clearing the display by printing a bunch of spaces on the display to overwrite the old ones.
int mappedValue = map(-Accelerometer.readY()*1000, -1000, 1000, 100, 500);
if(digitalRead(4)) {
tone(5, mappedValue);
Oled.println("---------");
Oled.println("TONE: " +
(String)mappedValue + "hz");
} else {
Oled.println(" ");
Oled.println(" ");
noTone(5);
}
A NOTE FROM THE EDITOR: Picking up the Arduino Uno WiFi Rev2 and the Sensor Kit requires soldering if you wish to use the accelerometer and pressure sensor. Since the Uno WiFi Rev2 does not have its I2C pins connected to pins A4 and A5 unlike the original Uno R3, some sensors will not work. You need to use a soldering iron to join the two small pads next to pins A4 and A5 on the sensor kit, or manually connect them with jumper wires. Alternatively, Pakronics also sells the Arduino Sensor Kit and the genuine Arduino Uno R3 if you don’t want to worry about this, however you won’t have WiFi capability!
Weather Station:
You should now be comfortable with coding a variety of gadgets with the sensor kit. As a final project, we wanted to put the Uno WiFi to good use and build a weather station capable of relaying data to a smartphone! Our plan is to source real-time weather data with Temperature, Pressure and Humidity and relay it to a smart device using the notification service Pushsafer.
Every set number of hours, we want to tell the sensor board to source weather data and then send a push notification to our smart device with the details.
PUSHSAFER
Pushsafer is an online service that handles sending notifications to your favourite smart devices on Android, iOS and Windows. You can hook up your WiFi connected Arduino (or any other IoT Device) to Pushsafer with their web API and send up your own custom notifications.
Head on over to https://www.pushsafer.com/ and sign up, you’ll be given up to 50 free API calls (i.e. notifications) and after that you’ll have to pay a small fee for additional requests. If you’ve never experimented with APIs before, they’re a great way to implement functionality to our Arduino WiFi and connect our sensors to the internet. By providing a web POST request – usually used for forms containing user data - we can interface with the service. While we could set up our own web server to do what Pushsafer does, it is much easier to use the convenient API they’ve designed.
On your Pushsafer dashboard there will be an API key that is much like a password – this allows you (and you only) to access the features of the API you are using. You must provide the key with all requests you submit, otherwise they won’t be acknowledged. Don’t give the API key to others as that means they can use your requests quota!
At this point, download the Pushsafer app from the app store of your smart device you’d like to receive notifications on. Once you’ve signed in and registered your device with your account, you can go to the dashboard and test sending a notification. If that all works, we can start programming our new weather station.
#include <Arduino_SensorKit.h>
#include <SPI.h>
#include <WiFiNINA.h>
char ssid[] = "YOUR_WIFI_SSID";
char pass[] = " YOUR_WIFI_PASSWORD";
String api_key = "YOUR_API_KEY";
int status = WL_IDLE_STATUS;
WiFiClient client;
char server[] = "www.pushsafer.com";
unsigned long lastConnectionTime = 0;
This code is used for setting up our weather station. There are a couple libraries (the “include” lines) to import since we need to use both the WiFi module and the sensor kit. If you are working with the offline Arduino IDE, or are finding the WiFiNINA library can’t be imported, you may need to search in the library manager to download and include it. The variables “ssid”, “pass”, and “api_key” all need to be filled out with your own information: The SSID is your WiFi network name, the password is your WiFi logon password and your api_key is the Pushsafer API key.
The only other variable you may wish to change is the length of the delay between sending weather reports to your smart device. The “weatherReportDelay” variable is in milliseconds, which is why we multiply it by 1000 on the end. For example, we have used 600L * 1000L milliseconds (totalling 10 minutes), but if you wanted a report every six hours, you could set the variable to 6L * 3600L * 1000L. The “L” is there to specify these values are “long”, meaning a larger maximum for multiple days if necessary.
STARTING SENSORS AND WIFI
Alright, now we can get the ball rolling. We first need to start up the sensors we are using. There are two weather-related sensors on the Arduino Sensor Kit, the DHT11 and the BMP280. The DHT11 is a simple sensor that can detect temperature and air humidity, but to whole numbers only. The BMP280 is a more accurate sensor, capable of two decimal points of precision, but doesn’t detect the humidity in the air. So, we’re going to use the temperature and pressure readings of the BMP280 (the Pressure sensor in the Arduino Editor) and the humidity reading of the DHT11 (the Environment sensor in the Arduino Editor).
void setup() {
Serial.begin(9600);
Serial.println("Initializing BMP280...");
Pressure.begin();
Serial.println("Initializing DHT11...");
Environment.begin();
String fv = WiFi.firmwareVersion();
while (status != WL_CONNECTED) {
Serial.print
("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
}
printWifiStatus();
sendWeatherData();
}
GETTING THE DATA
Here is the code we’re using to gather pressure, temperature and humidity data. Nothing special here. We’re using functions to handle getting information for our weather data to help keep it clean – getPressure, getTemperature, and getHumidity. We also need to divide the pressure reading by 100 since it returns its reading in pascals, not hectopascals as we’re used to seeing online and in weather reports.
float getPressure() {
return Pressure.readPressure() / (float)100;
}
float getTemperature() {
return Pressure.readTemperature();
}
int getHumidity() {
return Environment.readHumidity();
}
Sending Request
void sendWeatherData() {
client.stop();
//Closing any previous connections
//we might’ve had
if (client.connect(server, 80)) {
Serial.println("connecting...");
String data = "k=" + api_key;
data += "&m=";
data += getTemperature();
data += "C | ";
data += getHumidity();
data += "% | ";
data += getPressure();
data += "hPa";
data += "&t=Sensor Kit Weather Report";
data += "&i=65";
client.println("POST /api HTTP/1.1");
client.println("Host: www.pushsafer.com");
client.println("Accept: */*");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("User-Agent: ArduinoWiFi/1.1");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
} else {
Serial.println("Connection failed - WiFi.");
}
}
Woah, that’s a lot of code! While this looks a bit crazy, what we’re essentially doing is sending a request to Pushsafer, and specifying the details of what data we want to send. The first thing we do in this code is set up the data string – this is basically a large “sentence” of characters to send along with the request containing how we want to set up our notification.
Initially we need to specify is our API key. As we’ve mentioned, this is retrieved from your dashboard page and is unique to you. It is prefixed with “k=” to let Pushsafer know we’re giving the API key. The next thing we do is start adding things onto this string with the “+=” operator – this just stacks stuff on the end of your string. So, we add the temperature, the humidity and the pressure, including their relevant symbols. Since this is the message, we prefix it with “m=”. We do the same thing with title (“t=”) and the icon display (“i=”) – all of the different icons can be found on the Pushsafer website.
When it’s all been added together, it might look something like this:
Next we actually send our request. All of the “client.println()” calls aren’t too important to discuss for the scope of this review, but we’re simply telling the Pushsafer server what type and amount of data to expect. That way, when our weather data reaches the Pushsafer API, it knows what’s transmitting to it and can handle it properly.
Finally, if we didn’t end up successfully connecting and sending our data, we report the problem to the serial monitor.
The serial monitor is our friend here. If you haven’t used it before, click on the Serial Monitor tab on the left side of the Arduino Editor and make sure the baud rate is set to 9600 (or whatever speed you set it to in your setup function). As the WiFi board turns on and connects, it will tell us exactly what it’s doing and report any errors detected.
If all goes well and the Pushsafer app is installed on your smart device, you should see a notification pop up like this:
And there we go, we’ve made a custom weather station! Feel free to change the code to display more information from other sensors, add a customised message or change the icon. If you’ve gotten this far, you’ll likely have some ideas of how to make it better or add your own features.
WHERE TO FROM HERE?
With the amount of sensors and gadgets on the Sensor Kit, there’s virtually unlimited possibilities with what you can do!
Combined with the Arduino WiFi Rev2, this bundle isn’t just a beginners kit, it’s an expandable kit that’s compatible with a huge variety of both Grove sensors and regular Arduino sensors available across the Internet.
There’s tonnes of electronics projects available on the Arduino Project Hub, many of which are either compatible or require only minor tweaking to get them working with the Sensor Kit and Wifi Rev2 boards. We encourage you to get creative and either write your own programs or experiment with ones already available. Check out our videos on our social media to see ours in action!
Shopping List
The Arduino Sensor Kit and Arduino Uno board bundles are available from Pakronics: https://pakronics.com.au
- Arduino® Sensor Kit - Base SS103030375 $44.78
- Arduino® Sensor Kit bundled with Arduino® UNO WIFI REV2 (Includes USB A to B Cable) PAKR-K1191 $126.48
- Arduino® Sensor Kit bundled with Arduino® UNO REV3 (Includes USB A to B Cable) PAKR-K1192 $92.63