Here's how to make your Arduino do things from over the internet without an ethernet or wifi shield. This is a simple way to make your project controllable from anywhere in the world!

Step 1: Platform Compatability

This method WILL NOT work under Windows. I can't tell you how long it took me to figure that out. The command we're using, fopen() is not implemented the same way under Windows and Linux, so you have to use Linux. Never used it before? Don't panic, it's not that bad.
<p>thank you for your instruction. but how can i download it?</p>
<p>Most of the problem is troubleshoot, hope this thing could help anyone ^^<br><br>1. setup your serial port &quot;stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts&quot;</p><p><br>2. add 2 sec delay between fwrite and fclose to avoid serial interrupt or crash cause by fopen<br><br>3. to prevent Arduino restart use 10uF capacitor from GRD to RST.<br><br>Reference :<br><a href="http://stackoverflow.com/questions/13114275/php-serial-port-data-return-from-arduino" rel="nofollow">http://stackoverflow.com/questions/13114275/php-se...</a><br><a href="http://systemsarchitect.net/connecting-php-with-arduino-via-serial-port-on-linux/" rel="nofollow">http://systemsarchitect.net/connecting-php-with-ar...</a><br><a href="http://systemsarchitect.net/arduino-and-php-serial-communication-with-a-protocol/" rel="nofollow">http://systemsarchitect.net/arduino-and-php-serial...</a> </p>
<p>Good tutorial, but you shouldn't suggest installing services without giving proper instructions to start/stop them as well as how to prevent them from being started automatically at boot (for those who don't plan on running a dedicated HTTP service/Arduino gateway.) Also, MySQL isn't used by your tutorial. It shouldn't be included. Definitely useful for data-driven PHP sites, but that's not what your making here. Good job though!</p>
<p>Pals! My PHP code is here:</p><p>&lt;?php<br><br>$verz=&quot;1.0&quot;;<br>$comPort = &quot;/dev/ttyUSB0&quot;; /*change to correct com port */<br><br>$led = $_POST[&quot;led&quot;];<br><br>$fp =fopen($comPort, &quot;w&quot;);<br>sleep(2);<br>fwrite($fp, $led); /* this is the number that it will write */<br>fclose($fp);<br><br>?&gt;<br>&lt;html&gt;<br>&lt;body&gt;<br><br>&lt;center&gt;&lt;h1&gt;Arduino from PHP Example&lt;/h1&gt;&lt;b&gt;Version &lt;?php echo $verz; ?&gt;&lt;/b&gt;&lt;/c$<br><br>&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $PHP_SELF;?&gt;&quot;&gt;</p><p>&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp<br>&lt;input type=&quot;text&quot; name=&quot;led&quot;&gt;<br>&lt;input type=&quot;submit&quot; value=&quot;OK&quot;&gt;<br>&lt;br /&gt;<br><br>&lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</p><p>And the Arduino code is here, it lights up the LED on Pin 9 when Arduino Nano received ASCII '1' :</p><p><br>int motor1Pin = 9; // the first motor's port number<br>int usbnumber = 0; //this variable holds what we are currently reading from serial<br><br>void setup() { //call this once at the beginning<br> pinMode(motor1Pin, OUTPUT);<br> <br> Serial.begin(9600); //start up serial port<br>}<br><br>void loop() { //main loop<br> if (Serial.available() &gt; 0) { //if there is anything on the serial port, read it<br> usbnumber = Serial.read(); //store it in the usbnumber variable<br> }<br><br> if(usbnumber == '1')<br> digitalWrite(motor1Pin, HIGH);<br> else<br> digitalWrite(motor1Pin, LOW);<br>}</p>
<p>i get stack errors when I press any button</p>
<p>Nice one. Was looking for help in writing to the serial port from a php sequence to trigger output on the Arduino, this was just the ticket. No Servos, I just needed buttons and LED response. Thanks, aloishis89!</p>
<p>any luck?</p>
<p>Everytime you open the serial port with $fp =fopen($comPort, &quot;w&quot;);, you have to sleep(2); in order to allow the arduino time to boot up. It's pretty annoying, because you have to wait 2 seconds every time you send a command, but unless you can sustain the connection, you have to do that.</p>
<p>So I'd (like) to assume this also works under OSX, too?</p>
<p>I've fixed the problem.</p><p>I give Apache permission to use the serial port. I did this in terminal <br> with the following command:<br></p><p>sudo adduser www-data dialout<br><br>Once this is done, I restart Apache with the following terminal command:<br><br><br>sudo /etc/init.d/apache2 restart</p>
<p>It doesn't work for me.</p>
hi, this only works for me if i have the arduino serial monitor open. if i close it and try then php just hangs. do you know why this might be?
for me /dev/tty.usbETC.. only worked when the arduino serial monitor was open, but if i used /dev/cu.usbETC... then it worked always (mac 10.8.4)
<p>And even THAT isn't working with me, I'm on Mac as well.</p>
<p>Apparently when there is no serial connection happening, the arduino goes to sleep and takes a while to reboot. Go here <a href="http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection#.UxOm_R_zvzl" rel="nofollow">http://playground.arduino.cc/Main/DisablingAutoRes...</a> for some solutions. I just used the capacitor going to ground.</p>
<p>Do I have to allow PHP permissions to do anything special? I have been working over many a code and still nothing comes out of php other than ls and simple commands.</p>
<p>put this code-&gt; $PHP_SELF=&quot;your file php name&quot;;</p><p>after this code</p><p>$verz=&quot;1.0&quot;;</p><p>$comPort = &quot;com4&quot;; /*change to correct com port */</p><p>example:</p><p>$verz=&quot;1.0&quot;;</p><p>$comPort = &quot;com4&quot;; /*change to correct com port */</p><p>$PHP_SELF=&quot;control.php&quot;;</p>
<p>Thanks for your help. I forgot I inquired about this issue. I actually got my code to work after changing some permissions on the usb device (making the specific USB port world writable). Probably not the most secure thing to do, but will also be ignoring escape characters or what not.</p>
Put code file on running. Web server and access it from web browser
very good tutorials that help me to create web application controller <br>thanks so much <br> <br>
very good tutorials that help me to find what I need to build a web based application and <a href="http://www.intorobotics.com/controlling-arduino-board-php-web-based-script-tutorials/" rel="nofollow">control from internet sensors Using Arduino board</a>
Congratulations! I really appreciate your idea! When my just bought arduino arrives i'll try it!
For windows users, this code should do. <br> <br>exec(&quot;mode COM3: BAUD=9600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off&quot;); <br>$fp = fopen(&quot;COM3&quot;, &quot;w&quot;); <br>fwrite($fp, &quot;1&quot;); //write string to serial <br>fclose($fp);
Thank you so much for posting this! I've been searching for a way to control a parallax propeller from a wamp server. This code got me up and running.
where we have to put this code?

About This Instructable




More by aloishis89:Control an Arduino with PHP Build a $30k CyberGlove for $40 - Submitted by BayLab for the Instructables Sponsorship Program Build a Linux Cluster -  Submitted by BayLab for the Instructables Sponsorship Program 
Add instructable to: