loading

Ethernet Shields are a lot of fun, but they can be expensive. In this project I will show you how to control your Arduino from any computer that is connected to the internet, without using an Ethernet shield. This project is completely free, assuming you already have an Arduino.

Step 1: Ingredients:

  1. An Arduino with USB cable
  2. Internet Connected Computer
  3. Web Hosting with php support (I use biz.nf for free)
  4. Processing App (Which you can get here https://processing.org/download )

Step 2: Getting Started: Arduino Part

This is where we add the functionality we want to the Arduino. This part is very similar to setting up a simple Arduino project; the difference is the input the arduino receives.

Set up an arduino sketch that does whatever you like upon receiving the input of a certain character from the serial port. This is done by starting the serial conversatin with Serial.begin(9600); in the setup. Then in the loop if (Serial.available() > 0) checks for serial input and Serial.read(); returns a string of input text. The example I will refer to throughout opens and closes my blinds for me. You can see that my Arduino will open my blinds upon receiving the character 2 and will close them upon receiving the character 1.

Step 3: The Internet Side

In this step we will create a webpage that takes user input, and using that input edits a text file on the server.

The website does not not to be complex, it just has to take some input and send it back to the server for processing. The easiest way to do this is with a get request. When making the form to receive the input, define method as "get".

My whole HTML consists of just a form.

The form is submitted back to my page itself, and is handled my the PHP. This is where the magic happens. If it receives a get request, it opens my file Blinds.txt on the server. When it opens the file in the "w" mode it deletes everything in the file and then writes whatever you tell it to on the blank file. I have mine write either a one or two, then replace it with a zero after five seconds. The delay comes from sleep(5);. I have the number, either one or two, written the the file from only five seconds because I am sure that my Processing app can detect the change during that interval. I reset it to zero afterwards because otherwise, if I want to open my shades twice in a row, the second time I updated Blinds.txt my processing app wouldn't see any difference and therefore wouldn't do anything.

Step 4: Put It Together With Processing

Processing is a useful little tool that comes in handy when interfacing the Arduino with the computer (among other times).

The point of the processing app is to retrieve the data from the text file on your server and feed it, through the serial port, to the Arduino. To send the data we need the processing serial library. To start we set up the serial port at the same baud rate as we set the Arduino (9600). In the draw loop we begin by retrieving the data from my text file using loadstrings("url"); which returns an array of strings, each element being a line of text from the document. I then parse the array element into an int so it is a primitive instead of a reference variable, and I can compare its value. After waiting a second I retrieve another value and if they are different I know that something has happened and I need to tell my Arduino, so I send the data using ComPort.write(data);. I also test for nullity throughout so I do not accidentally pass on misread data.

Step 5: Test It Out!

  1. Make sure your Arduino is plugged into your computer
  2. Upload Arduino Sketch (You cannot do this while your processing app is running).
  3. Run Processing app
  4. Go to your website and submit your forms!

<p>Here is the Code(if anybody wants) :D</p><p>Arduino</p><p>&quot;int led =13;</p><p>void setup() {</p><p>Serial.begin(9600);</p><p>pinMode(led,OUTPUT);</p><p>}</p><p>void loop() {</p><p> if (Serial.available()&gt;0){</p><p> int Key=Serial.read();</p><p> if(Key==1)</p><p> Close();</p><p> else if(Key==2)</p><p> Open();}}</p><p>void Open(){</p><p>digitalWrite(led, HIGH);</p><p>delay(200);</p><p>}</p><p>void Close(){</p><p>digitalWrite(led, LOW);</p><p>delay(200);</p><p>}&quot;</p><p>Processing &quot;</p><p>import processing.serial.*;</p><p>Serial ComPort;</p><p>String input[];</p><p>void setup(){</p><p> String portName=Serial.list()[0];</p><p> ComPort = new Serial(this, portName,9600);</p><p> ComPort.bufferUntil('\n');</p><p>}</p><p>void draw(){</p><p>input =loadStrings(&quot;site&quot;);</p><p>if(input!=null){</p><p> String s_last=input[0];</p><p> int last =Integer.parseInt(s_last);</p><p> delay(1000);</p><p>input =loadStrings(&quot;site&quot;);</p><p>if(input.length!=0){</p><p> String s_current=input[0];</p><p> int current =Integer.parseInt(s_current);</p><p> if(current!=last){</p><p> println(current);</p><p> println(last);</p><p> ComPort.write(current);</p><p> }}}</p><p>}&quot;</p><p>HTML + PHP&quot;&lt;?php</p><p> if($_GET[&quot;action&quot;] !=&quot;0&quot;){</p><p> $myfile = fopen(&quot;Blinds.txt&quot;, &quot;w&quot;) or die(&quot;Unable to open file!&quot;);</p><p> if($_GET[&quot;action&quot;] ==&quot;close&quot;){</p><p> fwrite($myfile,&quot;1&quot;);</p><p> }elseif($_GET[&quot;action&quot;] ==&quot;open&quot;){</p><p> fwrite($myfile,&quot;2&quot;);</p><p> }</p><p> fclose($myfile);</p><p> sleep(5);</p><p> $myfile = fopen(&quot;Blinds.txt&quot;, &quot;w&quot;) or (&quot;Unable to open file!&quot;);</p><p> fwrite($myfile,&quot;0&quot;);</p><p> fclose($myfile);</p><p> }</p><p>?&gt;</p><p>&lt;HTML&gt;</p><p>&lt;body&gt;</p><p>&lt;form method=&quot;get&quot;&gt;</p><p>&lt;input type=&quot;radio&quot; name=&quot;action&quot; Value=&quot;open&quot; &gt; open</p><p>&lt;br&gt;</p><p>&lt;input type=&quot;radio&quot; name=&quot;action&quot; Value=&quot;close&quot; &gt; close</p><p>&lt;br&gt;</p><p>&lt;input type=&quot;submit&quot;&gt;</p><p>&lt;/form&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;&quot;</p>
<p>Please be thorough I like your work but it is so hard to follow.</p><p>What codes are for arduino sketches?</p><p>create them and keep them for us.</p><p>What html or whatever php goes to the web host?</p><p>create them and keep it for your fans.</p><p>What code goes to processor?</p><p>Create these files and be explicit on how to set them up.</p><p>do you need a data base or whatever.</p><p>In your displayed codes there are string identifiers that act up during compilation. The quotations mark might not be necessary if not needed in the code don't use them. EVERY ONE DOESN'T UNDERSTAND CODES.</p><p>Thanks when my grandma can use this then I know you have done a good job. </p><p>Thanks again.</p>
<p>processing is giving a error like this can you please help???</p>
hj.html is the place that you are getting the data from. This file should consist of just a number, nothing else. It looks like it contains more than that. Maybe you accidentally have your webpage saved as hj.html.
<p>It looks like the first line of hj.html is &lt;?php which would mean that that file is your webpage. You should have your php in hj.html write the data to a file, say &quot;info.txt&quot; and then your processing would say input = loadStrings&quot;info.txt&quot;. Also don't forget that if your page is on the web you need the whole address (www.mygreatwebsite.com/info.txt)</p>
Thax...
<p>hi i use you code ,,, arduino part was fine but getting error in processing &quot;arrayindexoutofboundsexception-0&quot; will you please helm to solve it</p>
You get this error when the list of serial devices is null - so your Arduino is not being seen. Try resetting it and restarting it, or maybe you have the serial monitor open on your Arduino.
Thanks for this addition! Can anybody point me in the direction of an easy way to share code on Instructables?
Pastebin :)
i need help<br> iam using a teensy 3.2 board and and using this board and a temp ,humidity sensor we have done a task to check the temp an humidity of a room......we have displayed it .......how can i upload it to a web page without using ethernet shield<br>
<p>sorry. noob here. On the Internet side, are those two separate files? an .html file and .php file? I have the form working, but when I submit, the txt file doesn't get updated. I have both files in the same place, and php is running on my server...</p>
<p>I'll challenge christoperq for the noob crown....<br><br>I tried for quite awhile to make this work with the php code inside the html file until I finally realized the html code has to be inside a php file :)</p>
<p>In my example they are the same file. If you have them as different files, the html form should look like &lt;form method=&quot;get&quot; action=&quot;yourPHPfile.php&quot;&gt;</p>
<p>Somehow it doesn't update the Blinds.txt on my server... </p><p>I made a blinds.html and it's running fine. But it seems like it doesn't or is not allowed to rewrite the file.txt.....</p>
<p>change the chmod values for the &quot;Blinds.txt&quot; file in your ftp server</p>
<p>what do you mean by the processing app is it like XAMPP or something different app</p>
<p>i have aproblem with step 3</p><p>please can you help me?</p><p>chat with me on facebook</p><p>Muhannad Maher</p>
<p>Hi!</p><p>When I push the button the file gets updated but it doesn't seam that &quot;Processing&quot; understands it.</p><p>When i open the file manually on my website server and change the number in the text file and save it, it works.</p><p>Someone know how to fix it?</p><p>&lt;3</p>
Thanks for good instructable but I need to know how to to receive from arduino to the webpage .
<p>I have a question: How i do to get a value from arduino on website? A sensor value for example. </p>
<p>I'm trying to do this and connect it to an iOS app to turn an LED on and off can anyone help me out?</p>
<p>If your IOS app can modify a file on a web-connected server then you should be good to go. Just read that file with processing.</p>
<p>If your IOS app can modify a file on a web-connected server then you should be good to go. Just read that file with processing.</p>
<p>If your IOS app can modify a file on a web-connected server then you should be good to go. Just read that file with processing.</p>
<p>I want to make my arduino do something like this, except instead of submitting a form, I want it to change LEDs based on how many people are on my page. Is this possible? I have the code from a Google Analytics account.</p>
<p>I'm not familiar with google Analytics, but if you can get the info about your page in xml or even plain text then you can have processing parse the text to get the number you want and send that to the arduino.</p>
<p>I'm not familiar with google Analytics, but if you can get the info about your page in xml or even plain text then you can have processing parse the text to get the number you want and send that to the arduino.</p>
<p>Finally got this working. Took a while to figure out that the serial port &quot;COM3 (arduino uno)&quot; is called 1 in the processing code. Not 3. It works for me to turn a light on and off from my website, but it seems like after running for a while I get this error &quot;ArrayIndexOutOfBoundsException: 0&quot;</p>
<p>Arduino: 1.6.1 (Mac OS X), Board:&quot;Arduino Uno&quot;</p><p>sketch_mar29a.ino:10:1: error: missing terminating &quot; character</p><p>sketch_mar29a.ino:48:1: error: missing terminating &quot; character</p><p>sketch_mar29a.ino:50:1: error: missing terminating &quot; character</p><p>sketch_mar29a.ino:98:1: error: missing terminating &quot; character</p><p>sketch_mar29a.ino:100:1: error: missing terminating &quot; character</p><p>sketch_mar29a.ino:102:1: error: stray '$' in program</p><p>sketch_mar29a.ino:104:1: error: stray '$' in program</p><p>sketch_mar29a.ino:106:1: error: stray '$' in program</p><p>sketch_mar29a.ino:108:1: error: stray '$' in program</p><p>sketch_mar29a.ino:110:1: error: stray '$' in program</p><p>sketch_mar29a.ino:112:1: error: stray '$' in program</p><p>sketch_mar29a.ino:116:1: error: stray '$' in program</p><p>sketch_mar29a.ino:120:1: error: stray '$' in program</p><p>sketch_mar29a.ino:122:1: error: stray '$' in program</p><p>sketch_mar29a.ino:124:1: error: stray '$' in program</p><p>sketch_mar29a.ino:150:1: error: missing terminating &quot; character</p><p>sketch_mar29a.ino: In function 'void setup()':</p><p>sketch_mar29a.ino:12:6: error: redefinition of 'void setup()'</p><p>sketch_mar29a.ino:1:6: error: 'void setup()' previously defined here</p><p>sketch_mar29a.ino:16:9: error: 'led' was not declared in this scope</p><p>sketch_mar29a.ino: In function 'void loop()':</p><p>sketch_mar29a.ino:20:6: error: redefinition of 'void loop()'</p><p>sketch_mar29a.ino:6:6: error: 'void loop()' previously defined here</p><p>sketch_mar29a.ino:28:7: error: 'Close' was not declared in this scope</p><p>sketch_mar29a.ino:32:6: error: 'Open' was not declared in this scope</p><p>sketch_mar29a.ino: In function 'void Open()':</p><p>sketch_mar29a.ino:36:14: error: 'led' was not declared in this scope</p><p>sketch_mar29a.ino: In function 'void Close()':</p><p>sketch_mar29a.ino:44:14: error: 'led' was not declared in this scope</p><p>sketch_mar29a.ino: At global scope:</p><p>sketch_mar29a.ino:50:1: error: 'Processing' does not name a type</p><p>sketch_mar29a.ino:54:1: error: 'Serial' does not name a type</p><p>sketch_mar29a.ino:56:14: error: array size missing in 'input'</p><p>sketch_mar29a.ino: In function 'void setup()':</p><p>sketch_mar29a.ino:58:6: error: redefinition of 'void setup()'</p><p>sketch_mar29a.ino:1:6: error: 'void setup()' previously defined here</p><p>sketch_mar29a.ino:60:24: error: 'class HardwareSerial' has no member named 'list'</p><p>sketch_mar29a.ino:62:1: error: 'ComPort' was not declared in this scope</p><p>sketch_mar29a.ino:62:15: error: expected type-specifier before 'Serial'</p><p>sketch_mar29a.ino:62:15: error: expected ';' before 'Serial'</p><p>sketch_mar29a.ino: In function 'void draw()':</p><p>sketch_mar29a.ino:70:26: error: 'loadStrings' was not declared in this scope</p><p>sketch_mar29a.ino:72:11: error: 'null' was not declared in this scope</p><p>sketch_mar29a.ino:76:11: error: 'Integer' was not declared in this scope</p><p>sketch_mar29a.ino:82:10: error: request for member 'length' in 'input', which is of non-class type 'String [1]'</p><p>sketch_mar29a.ino:90:16: error: 'println' was not declared in this scope</p><p>sketch_mar29a.ino:94:1: error: 'ComPort' was not declared in this scope</p><p>sketch_mar29a.ino: At global scope:</p><p>sketch_mar29a.ino:100:1: error: 'HTML' does not name a type</p><p>sketch_mar29a.ino:128:1: error: expected unqualified-id before '?' token</p><p>Fout bij compileren.</p><p> Dit rapport zou meer informatie hebben met</p><p> &quot;Tijdens de compilatie uitgebreide uitvoer weergeven&quot;</p><p> ingeschakeld in Bestand &gt; Voorkeuren.</p><p>what,s wrong?</p>
<p>It looks like you may have accidentally copied the processing code and html into arduino</p>
<p>sorry</p><p>yes i did</p><p>unterminated string constant ?????</p>
<p>Great work!</p><p>There's also something called SLIP, that allows an embedded device like the Arduino to talk TCP/IP using an RS232 cable. </p><p>I haven't been able to get it to work, and haven't found an instructable for it, but perhaps someone else has better luck!</p>
<p>Thanks! I'll look into that; you may see it coming.</p>
<p>nice ible but here's the catch... arduino needs to be connected to the computer at all times.... OBVIOUSLY, ETHERNET SHIELD IS CHEAPER THAN PC or LAPTOP!!!</p>
<p>That's not a problem if you already have a server that runs 24/7. You could also modify this to work with a router running the openwrt firmware as long as it has a serial port.</p>
<p>But your opening picture suggest that you really need about a dozen computers all around the house.</p>
<p>You are right! It is not the most accurate picture, but I think it send the right message....it has the right feeling.</p>
<p>You're right, it's not the perfect solution. Good for a college student who leaves his computer in his dorm room while he's at class though!</p>
<p>Where's the security? The whole Internet of (Insecure) Things.</p><p>PHP is inherently insecure. You need to jump through hoops to make it secure. (but reasonably possible)</p>
<p>I think it's secure enough to control the blinds in my college dorm room...but you're right I would not do anything serious or sensitive this way!</p>
<p>Good intro to the Internet of Things. I'm not sure how this statement would work correctly:</p><p> int key = Serial.read();</p><p>If you touch the '1' key, the computer sends the ASCII code for 1, which is actually 49 expressed as an integer. The easiest way to fix this is:</p><p> int key = Serial.read() - '0'; // Subtract ASCII code for zero</p><p>Because the ASCII code for zero is 48, then the digit character '1 becomes:</p><p> int key = 49 - 48;</p><p> key = 1;</p><p>which would work correctly. I would also add these two lines to the very top of the program:</p><p>#define CLOSEBLINDS 1</p><p>#define OPENBLINDS 2</p><p>and change the if statement code to:</p><p> switch (key) {</p><p> case CLOSEBLINDS:</p><p> Close();</p><p> break;</p><p> case OPENBLINDS:</p><p> Open();</p><p> break;</p><p> default:</p><p> Serial.println(&quot;Unresolved state, shouldn't be here!&quot;);</p><p> break;</p><p> }</p><p>I find a switch/case much easier to read once you get rid of the magic numbers for 1 and 2, plus it makes it easy to add new commands.</p>
<p>That's How I thought it would work, and it tripped me up at first! That is what would happen if i sent &quot;1&quot; from the Arduino serial monitor, or from processing as a string. Since processing is sending an int value it knows just to send the value of 2 and not ASCII 2. </p>
<p>Ethernet shield expensive? They cost around $10... That's a lot cheaper than the electricity required to power a computer 24/7.</p>
<p>Luckily I don't pay for my electricity :P</p>
<p>I don't mean to be a smart aleck... but if you have a spare computer handy, why do you need the Arduino? ;)</p>
<p>I find the Arduino super easy to use, plus a lot of code is already available for interfacing it with ir controls and stuff like that, and I figured that while I'm at class or at work my computer might as well help me access my already completed Arduino projects.</p>
<p>To interface your computer with things in the world, like sensors, actuators, LCD displays. Someone please correct me if I'm wrong, but most PCs are not set up with pins that can do what an Arduino does, except RPis, Beaglebones and the other similar single-board computers in the maker world.</p>
<p>Generally, any of that can be done through a serial port. Most older computers (which is what I would use in this context) have onboard serial ports.</p>
<p>This is a good seed idea for making a home connected system.</p><p>Since the introduction picture does imply an army of connected devices then a good expansion approach would be to use arduino pro mini's, wirelessly connected using NRF24L01+ wireless modules to create a network. The the host PC would talk to one connected arduino, which can then wireless send a command to a specific, or multiple, arduinos to carry out commands.</p>

About This Instructable

108,926views

987favorites

License:

More by ZachariahZebadee:Water Splash Alarm Clock - Wake up to water falling on you Internet Controlled Arduino (no Ethernet shield) 
Add instructable to: