Arduino boards with wifi and cloud-enabled are reaching the stars in this era, like the ESP8266 board which was so popular due to its wifi capability which allowed makers and developers to quickly create their IoT and cloud-based applications .. with no time!
1Sheeld didn’t miss this tech trend out as I have made a tutorial that explains how to get the ESP8266 working with 1Sheeld.
And today .. I am going to play around with another popular Arduino board that also has its own wifi and cloud-based connectivity; the MKR1010! And yes, I will connect it with the 1Sheeld and the Arduino IoT Cloud.
Briefly, in this tutorial, you will build a quick project to connect MKR1010 or MKR1000 (both are the same steps) to the Arduino IoT Cloud to enable you to control a moving camera in your home, capturing photos to your home area and send them to your email. Thanks to the 1Sheeld board that has two awesome shields called Camera Shield and Email Shield which you are going to use in this tutorial ..
And please get your hands dirty with this MKR1010 getting started tutorial or if you have the MKR1000 then check this MKR1000 getting started tutorial till you install the MKR kit drivers and get the blink example working .. Note that starting from “Tutorials” subheading and below isn’t important for you.
Now .. you are ready to go ahead with 1Sheeld and MKR1000 tutorial!
How 1Sheeld will work with Arduino MKR board
Let’s understand first how 1Sheeld works with the Arduino. When you plug 1Sheeld over your Arduino then you end up with these connections, internally:
Tx pin of 1Sheeld (pin 0) with >> Rx pin of Arduino (pin 0)
Rx pin of 1Sheeld (pin 1) with >> Tx pin of Arduino (pin 1)
5v pin of 1Sheeld with >> 5v pin of Arduino
GND pin of 1Sheeld with >> GND pin of Arduino
And that’s how 1Sheeld is powered on and makes the communication with the Arduino. Also, that means if you unplugged the 1Sheeld and connect its previously mentioned pins to the Arduino manually with jumper wires then it should work, right? Yes .. it will definitely work and here’s the key to get it to work with the Arduino MKR boardsm whether MKR1000 or MKR1010 😃
It’s just simple .. the only thing you are going to build is the servo motor and the camera holders. Firstly, download this servo support (.STL) file which is a ready-to-print 3D part. It’s just like this:
Then fix the micro servo motor inside it like this:
Instead of designing another part for holding the phone, I just used that popular ultrasonic holder 😄 .. Just attach the ultrasonic holder to the servo motor holder with a tiny screw:
Now the moving camera mechanism is ready to attach a camera to it which is actually, just your phone with double face tape:
That’s it .. let’s move to the hardware connections …
Step 3: Hardware Connections
Get the 1Sheeld connected with the Arduino MKR board and other components like that:
Tx pin of 1Sheeld (pin 0) with >> Rx pin of Arduino MKR board
Rx pin of 1Sheeld (pin 1) with >> Tx pin of Arduino MKR board
5v pin of 1Sheeld with >> 5v pin of Arduino MKR board
GND pin of 1Sheeld with >> GND pin of Arduino MKR board
Servo signal pin with >> pin7 of Arduino MKR board
Servo GND pin with >> GND pin of Arduino MKR board
Servo 5v pin with >> 5v pin of Arduino MKR board
LED anode pin with >> pin6 of Arduino MKR board
LED GND pin with >> GND pin of Arduino MKR board
You should end up with the hardware connected like that:
And feel free to change the LED & Servo pins with any others from the MKR1010 pinout:
Or if you have the MKR1000:
In addition, here is what your project should really look like:
Step 3: Configuring the Arduino IoT Cloud
Once you get your circuit connected, let’s make it cloud-enabled by creating a Thing. A thing is just another name for the cloud-connected object/hardware that you want to connect to the Arduino IoT Cloud platform. But prior to that, you are going to configure your MKR board to enable it to communicate with the cloud.
Now, you are finished with the board configuration, let’s move to the IoT Arduino Cloud …
2- I chose the name of SecurityCamera to represent the project but you can choose whatever you want.
You will also choose your MKR kit version, MKR1000 or MKR1010 .. then press on Create
3- Now you got this window .. press on the + to create a property. A property is just a button, slider or any object that will let you communicate with your cloud-connected devices.
4- The first property you will create is a button to capture photos. You need to copy and paste this name cameraButton as it is to the name field. Be careful, since changing any capital or small letter will not make your project work. Then select the Type to be ON/OFF Boolean and press on Create
5- And here’s your button created. Press on + again to add another property.
6- The second property you will create is a slider to control the camera movements. You need to copy and paste this name servoCameraAngel as it is to the name field. Be careful, since changing any capital or small letter will not make your project work. Then select the Type to be Int and the min & max value to be 0 & 4 respectively then press Create.
7- Your cloud platform is ready now. Press EDIT CODE to go for the auto-generated Arduino code.
Step 4: Code optimization
You need to edit this code you got from the Arduino IoT Cloud to add the camera, servo and email functionality and here comes the most ridiculous and annoying part, only if you are going to compile and upload the code from this Arduino web editor! Yes, that’s what made me struggle for days till I figure out that it’s a waste of time to use the Arduino Web Editor instead of the Arduino IDE.
The problem is you have to add the OneSheeld library to this auto-generated Arduino web editor code and I did .. But it didn’t compile .. that wasn’t the issue though, but the real problem is that there are no compilation errors in the verbose! .. that means you will never what the error is so that you can fix it .. Arduino web editor tells you that you have JUST AN ERROR, DUDE!
Here’s what I mean ..
And that’s why I had to download the generated code to my disk drive and add the OneSheeld code edits to it by using the traditional and lovely Arduino IDE.
So, I have made all these edits for you and came up with the Arduino code you are going to upload to the MKR board. Just follow these steps:
2- When you compile the code the Arduino will ask you for these libraries but instead of downloading them I did it for you and you just need to download the “Lib.zip” file and unzip it. You will get these libraries folders. Copy and paste these folders to Arduino library folder which its path will look like this:
Note: If the oneSheeld library folder already exists and you were asked to replace it .. then do replace it since I have edited the CameraShield.h file the oneSheeld library included in the “Lib.zip” as it has some conflicts with the Arduino Cloud libraries.
3- Open the “thingProperties.h” tab from the auto-generated code and copy the THING_ID
Then paste it in the THING_ID field in the “thingProperties.h” file that’s included in unzipped “code_files.zip”
4- Also, open the “arduino_secrets.h” file and write your wifi router SSID & PASS
And here is the full code:
/* Include the shields */
/* Include 1Sheeld library. */
/* include Servo library */
/* include Arduino cloud libraries */
/* define servo pin */
/* define trigger pin */
/* get a servo object */
// Initialize serial and wait for port to open:
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
/* Start communication. */
/* attach servo pin */
/* initiate the servoCameraAngel to 2 */
// led for button status showing
// servo testing
// LED testing
// always upload and receive data to the cloud
Serial.println("camera button changed");
// trigger the button status on the led as on/off
/* Take a photo for that stranger using the phone's front camera */
/* delay for the camera */
/* Send an email with the last picture in OneSheeld folder. */
Email.attachLastPicture("[email protected]","Security Camera!","Hi, Here's a photo for your home",0);
/* delay for the email */
// do nothing
Serial.println("servo angel changed");
/* move servo to the received value from the cloud after mapping it to a certain servo degree */
Moreover, you will notice that the code has something new to the 1Sheeld coding; it’s those 2 lines:
/* Start communication. */
Instead of the normal way, like:
/* Start communication. */
And that’s necessary to get the 1Sheeld working properly with the MKR1010 board. The explanation is that the 1Sheeld in its hidden deep library code depends on “Serial.begin();” function to make the communication with the Arduino rx, tx pins. And since the rx, tx pins of the MKR1010 (also with the MKR1000) aren’t used with the “Serial.begin();” as “Serial.begin();” is used for code uploading only, then you will use the serial1 as it’s the serial line that’s connected to the rx, tx pins of the MKR1010 which is initiated by using the “Serial1.begin();” function.
Step 5: Code uploading
Open the “SecurityCamera_mar06a.ino” file
Connect the MKR1010 board via your PC using Micro USB cable.
Switch the 1Sheeld power to operate on 3.3v (Not the 5v).
MKR boards board take USB 5v and convert it to 3.3v to power its chip and you should adjust 1Sheeld’s 5v/3.3v to the 3.3v notation so the voltage level between the MKR board & 1Sheeld is the same and no damage would occur to your MKR board.
Press on the Uploading Arrow on the Arduino IDE to upload your code.
Note: 1Sheeld has 2 modes: Uploading mode and Operating mode. You can switch between them using the switch close to the Digital pins and is called “SERIAL SWITCH”.
But in this case, the MKR1010 doesn’t conflict the Uploading as it uses a different serial for uploading code “Serial.begin()” than the serial for communication with 1Sheeld “Serial1.begin()” as we explained above. So, just keep the 1Sheeld serial switch on the Operating mode (“HW” notation), always And upload the code to the MKR1010.
Run it …
Once finished, open your 1Sheeld App and connect it to the 1Sheeld board then select the Camera & Email shields. After that, go to the Arduino IoT Cloud page that has the auto-generated code and press on GO TO IOT CLOUD
then press on the Eye shape button to open your IoT cloud panel .. yeaaah .. that’s it, now you have access to your camera from any browser 😃
Just have fun with the slider moving right & left positions and watch the magic happens to the servo motor while at any position you can slide the on/off switch to on to take a photo .. Where to see it? just check your email after a few seconds and you will get it sent to you.
Also, you can monitor the connection to the internet and the IoT Cloud or even trigger the variable changes over the cloud from the serial monitor, like that:
That was a quick tutorial for how to use the MKR1000 with the Arduino IoT Cloud and 1Sheeld for making an IoT-based home security camera.
You may have noticed that using MKR1010 to connect to the cloud is somehow not easy to do because Arduino forces you to use their web editor which leaks many helping features available in the Arduino IDE.
Just imagine that you want to use it in more complex IoT projects where you will have to add some sensors and shields libraries where it’s possible to get many compilation errors which Arduino web editor will prevent you from understanding what’s going on!
Anyway, I am not a big fan of this type of compiling and uploading code online and prefer the classic steady method of using the Arduino IDE. Agree with me or not, this is much easier and that’s the common between most of the makers and developers.
The good news is, 1Sheeld has an IoT shield that will make it much easier for you to make this project and other complex IoT projects. To know how to use 1Sheeld with the popular Arduino Uno for any IoT project, please check this tutorial.
Even more, this project was just a small part of a bigger one I have made months ago on Hackster where I managed to control home light, air conditioner, security camera, and more .. just check it here.
That’s it for the Arduino MKR tutorial, Guys .. if you have any comment please let me know below and stay tuned for the upcoming tutorials 😉
Arduino keeps standing out from the crowd of all-around development boards due too its ease of use and budget price. As a result, this has enabled almost anyone to get his own idea into life no matter how crazy or even useless to the whole world it was, except for its maker! Also, it has …
Arduino robots are always funny and definitely more enjoyable when combined with robotic arm! And today, I will walk you through the making of a simple Arduino Robot Arm that’s made of cardboard and how you can attach it over your Arduino Bluetooth RC Car / Robot that you have made so far through this series. …
Arduino Line Following Robot is one of the easiest and most well-known projects that anyone can make to learn the basics of programming, electronics, and mechanics all in one project. It’s known that this project is common for most of the makers and tech students and today I am going to give it a revisit …
Back again with another Arduino Bluetooth RC Car tutorial but with an advanced feature that makes your car autonomous by adding ultrasonic sensors to the RC Car you have made before!. Yeah, I know that you may have seen other tutorials using ultrasonic to make the car/robot avoid obstacles ahead, but I am going to …
Cardboard crafts are one of the most popular and easy to make DIY stuff. Mixing this with the unmatchable enjoyment of RC Cars and the ease of using Arduino, I am going to show you how to make a Cardboard Arduino Bluetooth RC car that you can control via Bluetooth from your smartphone. …
Arduino Security Camera Have you ever wanted to check your home in real time? Afraid that maybe someone has stormed in, don’t remember if you shut the door or not or maybe wanna check if your Hyper-energetic dog has broken any of your dishes AGAIN!! 🙂 Then this is the perfect place for you cause today …