Getting started with 1Sheeld and MKR1000

Arduino MKR

Arduino MKR

 

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 ..

 

 

Before you start …

If you are just getting your 1Sheeld out of the box then go ahead with this 1Sheeld getting started tutorial or simply check the 1Sheeld User’s Manual.

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 😃

 

Step 1: Gather Components

  • 1Sheeld+
  • iOS/Android phone
  • MKR1000 or MKR1010
  • LED
  • Micro servo motor
  • servo support (.STL) 3D part for holding the servo motor
  • Ultrasonic sensor holder (to hold your phone)
  • 7 male-male jumper wires
  • Breadboard

 

Step 2: Build it

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 …

1- Go to the Arduino IoT Cloud website and press on NEW THING.

 

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:

1- Download this “code_files.zip” and unzip it. You will get 5 files:

 

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:

“C:\Users\your-pc-name\Documents\Arduino\libraries”

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:

 

Moreover, you will notice that the code has something new to the 1Sheeld coding; it’s those 2 lines:

Instead of the normal way, like:

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).

Note:

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:

Conclusion ..

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 😉




Related Blogs

Arduino Robotics

Arduino Robotics Series, from a car to a robot arm

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 Robot Arm

How to build an Arduino Robot Arm placed on RC Car

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

How to build an Arduino Line Following Robot using Cardboard

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 …

Arduino Obstacle Avoiding Robot

How to build an Arduino Obstacle Avoiding Robot using Cardboard

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 …

Arduino Bluetooth RC car

How to make an Arduino Bluetooth RC Car using Cardboard

  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

Arduino Security Camera System (Arduino Home Hacks #4)

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 …