Taking Basic Electronics to the Internet (IoT)




After experimenting and having fun with IoT using a Spark Core, I realized I could add a series of tutorials up on Instructables. So this instructable is the first of a series of instructables, in which I'm going to show you how to connect your everyday electronics to the internet. The micro-controller I'm using for almost all of the tutorials is the Spark Core as it is fairly easy to setup and cheap in cost. The tutorials will feature taking everyday electronics like LEDs, LDRs, ultrasonic sensors, relays, etc, up on the internet so you can control or monitor them on a web browser which is pretty cool.

This the first of the series and I'm going to show you how to setup your Spark Core and how to connect your web browser to the spark cloud API. I'm trying to keep this as simple as possible so that even people new to electronics will be able to build it.

Check out the second instrucatble of the series.

Check out the third instructable of the series , which is an Internet Controlled Fish Food Feeder.

So lets get started...

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Tools and Components

In this instructable all I'm going to show you is how to setup the spark core and end up with connecting an LED to the internet. So here is a list of things required to get started -

No soldering skills are required to get started, but it will help if you know soldering for the future instructables in this series. You can get an Arduino and a WIFI module to get started, but that's a lot more costlier and bigger in size compared to the Spark Core (or particle core as they now call it).

Note- You can also get a photon form the particle store for $19 all the code and the setup of this series will remain unchanged.

Step 2: Getting Started

Now that you have your core lets get it connected to the internet or the Spark Cloud API. First get the core out of the box and connect the spark core to the computer via the micro USB cable. Now you should get the spark core blinking blue color.

Time to set up your android or Iphone to configure your core -

  • First download and install the respective app - Android or IPhone
  • Next sign up for a free account using valid details

Time to Connect the Core to the Cloud -

Make sure your phone is connected to the WiFi you want to use (it'll show up in the SSID blank on the app), then enter your password and click CONNECT!

The core would start blinking the following colors -

  • Blinking blue: Listening for Wi-Fi credentials
  • Solid blue: Getting Wi-Fi info from app
  • Blinking green: Connecting to the Wi-Fi network
  • Blinking cyan: Connecting to the Particle Cloud
  • Blinking magenta: Updating to the newest firmware
  • Breathing cyan: Connected!

Once you got the core Breathing cyan everything went fine and it's time to proceed to the next step.

Step 3: Blink

Once you got the core setup, it's time to upload the first program to it, the default program is tinker and it listens to commands from your android phone. The uploading process is wireless, go the Particle Build IDE and have a look at the interface this is where we type and upload the programs to the core.

Create a new app and paste this program in the editor

int led1 = D0; // Instead of writing D0 over and over again, we'll write led1
// You'll need to wire an LED to this one to see it blink.

int led2 = D7; // Instead of writing D7 over and over again, we'll write led2 // This one is the little blue LED on your board. On the Photon it is next to D7, and on the Core it is next to the USB jack.

// Having declared these variables, let's move on to the setup function. // The setup function is a standard part of any microcontroller program. // It runs only once when the device boots up or is reset.

void setup() {

// We are going to tell our device that D0 and D7 (which we named led1 and led2 respectively) are going to be output // (That means that we will be sending voltage to them, rather than monitoring voltage that comes from them)

// It's important you do this here, inside the setup() function rather than outside it or in the loop function.

pinMode(led1, OUTPUT); pinMode(led2, OUTPUT);


// Next we have the loop function, the other essential part of a microcontroller program. // This routine gets repeated over and over, as quickly as possible and as many times as possible, after the setup function is called. // Note: Code that blocks for too long (like more than 5 seconds), can make weird things happen (like dropping the network connection). The built-in delay function shown below safely interleaves required background activity, so arbitrarily long delays can safely be done if you need them.

void loop() { // To blink the LED, first we'll turn it on... digitalWrite(led1, HIGH); digitalWrite(led2, HIGH);

// We'll leave it on for 1 second... delay(1000);

// Then we'll turn it off... digitalWrite(led1, LOW); digitalWrite(led2, LOW);

// Wait 1 second... delay(1000);

// And repeat! }

Then upload the program by clicking the flash button on the top left of the screen.

The core will blink magenta and then turn cyan indicating a successful flash. Now you should see the LED at digital pin 7 blinking.

Step 4: Controlling Via Internet

Now its time control the led via a web browser, the web browser connects to the Spark Cloud API, the the spark cloud connects to the core and the data transferred is encrypted (128bit) so all the data shared is safe.

Let's start with uploading the program to the core -

<p>int led1 = D0;</p><p>void setup()
{</p><p>   pinMode(led1, OUTPUT);</p><p>   Spark.function("led",ledToggle);</p><p>   digitalWrite(led1, LOW);</p><p>}</p><p>void loop()
   // Nothing to do here
}</p><p>int ledToggle(String command) {</p><p>    if (command=="on") {
        return 1;
    else if (command=="off") {
        return 0;
    else {
        return -1;

Then upload the program by clicking the flash button on the top left of the screen.
The core will blink magenta and then turn cyan indicating a successful flash. Now you should see the LED at digital pin 7 blinking.

Step 5: Webpage

You can control the core using your browser and this step shows you just how to do that. All you have to do is download the file, add your access token and core ID in the places where it says "your-access-token-goes-here" and "your-device-ID-goes-here". And that's all that you have to do now open the file using an web browser, click on to turn on the led and off to turn it off.

The second html file "spark_core2.html" is a cleaner interface and you don't have to edit any code and directly run it in your browser and enter the access token and core ID in the webpage.

On the success of the script you would get a return message with 1 or 0, if anything went wrong on the hardware side you would get a -1.

If you encounter any error feel free to leave a comment below.

Step 6: Whats Next

Hope you had fun with controlling the LED form the internet or via a web browser. This tutorial serves as a basics of controlling your house lights via the internet which I will demonstrate in a future instructable.

The next instructable will take things a little further and show how to monitor sensor values on a webpage and how to control a servo via the internet.



    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    23 Discussions


    3 years ago on Introduction

    Can a laptop be used instead of a smartphone? Thank you.


    4 years ago on Introduction

    great tutorial!

    can you buy two of those and control one with the other, without an internet page?

    4 replies

    Reply 4 years ago on Introduction

    You can have these interchange a limited amount of data between cores. Check out the documentation for Spark.publish and Spark.subscribe. For this to work both cores need to be connected to the internet but they do not need to be in the same location.


    Reply 4 years ago on Introduction

    Disabling the internet, is sort of going off the the topic considering this is internet controlled Electronics or IoTs, but these microcontrollers are not capable to talk to each other over WiFi (they can do it over Bluetooth). You could setup a raspberry pi as a local cloud and a make the core talk to that instead, but the downside is you still need internet to upload programs to it.


    4 years ago on Introduction

    When I right-click on the html files, all I get is:
    "Failed - server error". When you see an error message that says "Server Error," this means there's something wrong with the server you were trying to download the file from.

    I'm no rookie at this; I know computers very well!

    Thanks very much,
    Ed in Columbus, Ohio

    2 replies

    Reply 4 years ago on Introduction

    Hey sorry about that I just checked it out, definitely a server error, instrutables for some reason have changed the file permissions. I get a 403 error when I try accessing the file, I will start a forum topic on this. In the mean while I uploaded the HTML files in a zip file, that seems to download fine.


    Reply 4 years ago on Introduction

    Thanks a million for the help. I appreciate the articles and intend on building all of your projects! Ed in Columbus, OH


    4 years ago on Introduction

    What sort of range do these units have ?

    Am building a small solar powered unit with 12v marine battery backup that provides web cam snapshots using a PIR as a trigger. Would be nice to have an event counter attached. Maybe even have it upload to my server.

    5 replies

    Reply 4 years ago on Introduction

    Have you thought about using a cheap android phone for that project, they have camera modem computer WiFi all built in. Use Tasked or Task bomb to control it. Get the PIR input via Bluetooth.


    Reply 4 years ago on Introduction

    Phone is overkill and more expensive for what I want to do.
    Besides which I already have most of the parts set up apart from wireless comms and I still have spare I/O available for further expansion with my current system


    Reply 4 years ago on Introduction

    I can buy a prepaid smart phone for $30-50 , with that I get a 3G modem,Wi-Fi,bluetooth, 32bit micro with a Tcpip stack ready for FTP Telnet, 5M pixel camera, battery. doesn't sound expensive to me. Overkil yes, but when a RPi in a case costs $50 I know where I'm going for remote cameras.


    Reply 4 years ago on Introduction

    A smart phone won't let you communicate to each other or a server, letting you create a home automation device. You could used two Cores one with the PIR sensor and other to control the lighting and make them talk to each other. lt would also be hard to control your house lighting with an android phone.


    Reply 4 years ago on Introduction

    Thanks for a very nice tutorial. The only problem I'm having is the two html downloads give me an error when I click on them: Unauthorized access. Can you post the actual html code?

    Thanks much,

    Ed in Columbus, OH


    4 years ago on Introduction

    Just to clarify, the setup in this instructable can be applied to a PHOTON on an ARDUINO Shield with no modifications??


    4 years ago on Introduction

    Looks like
    a great device. Can’t wait to read the tutorial for home lights and for the
    Photon to become available (19$ seem a bit more reasonable than the 39$ for the
    core).I was also
    hoping to see how one can use the app to switch on and off lights etc. from a
    smartphone app/widget instead of a web browser.

    Thanks for
    the nice instructable.