Introduction

Just got your first Arduino, but you don’t have any additional hardware? Gotten a little tired of watching the LED blink by itself, with no interaction? Check this out. This is the first thing I ever made for Arduino, as I had just received my first Uno and didn’t have any additional hardware.

After playing with the included examples and some tutorials I got bored after about an hour (making the internal LED blink is only exciting for so long!). So I decided to make it a bit more interesting; i wanted to be able to enable and disable the internal LED using a web interface.

This is actually quite simple, and could easily be altered to enable remote control of relays or other different types of outputs. The great thing about using a web interface is that it is cross-platform and pretty much enables you to also control your Arduino using most devices with web browsing capabilities, such as smartphones and tablets.

Well, enough talk. Let’s get to it!

Prerequisites

Here’s what you’ll need:

  • An Arduino board with an internal LED (usually on pin 13) or a separate LED
  • A webhosting service with PHP support
  • The Arduino IDE
  • The Processing IDE
  • A text editor (e.g. Notepad++, Geany, or whatever you prefer)

Instructions

First, we’ll start off with the web interface. It’s function is to give the user the choice to either switch the LED on or off. When either one of them is clicked, the command is written to a .txt-file as a 1 (ON) or 0 (OFF) value.

The interface consists of three files; a HTML frontend, a PHP document, and a .txt-file for storing values. So, firstly create these files using a text editor:

  • index.html
  • led.php
  • LEDstate.txt

index.html should contain the following:

<html>
    <head>
        <title>LED ON/OFF</title>
    </head>
    <body>
        <!-- This is just for aesthetics, centering the content within the paragraph --> 
        <p align="center">
            <font size="8">

            <!-- This part is a a link, which also sends a request to the php-document, telling it to write 1 or 0 to LEDstate.txt --> 
            <b><a href="led.php?state=1">ON</a></b> / <b><a href="led.php?state=0">OFF</a></b></font>
        </p>
    </body>
</html>

Here’s an example of what it should look like.

Now for the PHP file :

<?php
    $onoroff = $_GET["state"]; // Declares the request from index.html as a variable 
    $textfile = "LEDstate.txt"; // Declares the name and location of the .txt file

    $fileLocation = "$textfile"; 
    $fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and replaces any previous content 
    $stringToWrite = "$onoroff"; // Write either 1 or 0 depending on request from index.html 
    fwrite($fh, $stringToWrite); // Writes it to the .txt file 
    fclose($fh); 

    header("Location: index.html"); // Return to frontend (index.html) 
?>

The .txt file (LEDstate.txt) can be left empty.

Upload these three files to your website, and remember the location. We’re gonna need it for later.

Now it’s time to code the Arduino!

For this, we can simply use the “Physical Pixel” example code from the Arduino website, written by David A. Mellis, Tom Igoe and Scott Fitzgerald. We only need the Arduino part of it though, so I’ll copy it onto here. What it does is to open up a serial connection to the host computer and listens for serial inputs. If the Arduino receives the command “H” it sets the LED to “HIGH” (ON), or “LOW” (OFF) if it receives the command “L”. (For more information on this, check out the “blink” tutorial).

const int ledPin = 13; // the pin that the LED is attached to - change this if you have a separate LED connected to another pin 
int incomingByte; // a variable to read incoming serial data into 

void setup() { 
    // initialize serial communication: 
    Serial.begin(9600); 
    // initialize the LED pin as an output: 
    pinMode(ledPin, OUTPUT); 
} 
    
void loop() { 
    // see if there's incoming serial data: 
    if (Serial.available() > 0) { 

        // read the oldest byte in the serial buffer: 
        incomingByte = Serial.read();

        // if it's a capital H (ASCII 72), turn on the LED: 
        if (incomingByte == 'H') { 
            digitalWrite(ledPin, HIGH); 
        } 
        
        // if it's an L (ASCII 76) turn off the LED:
        if (incomingByte == 'L') {
            digitalWrite(ledPin, LOW); 
        } 
    } 
}

Next, upload the sketch to your Arduino using the Arduino IDE.

To test if it works, open up the serial port monitor and type either “H” or “L” (without quotation marks), then click send. If the LED turns on and off, you’re good to go! If not, check if the pin variable is set to the actual pin your LED is connected to (if you’re not using the internal one - which usually is at pin 13).

Now for the last part that ties it all together! Open up the Processing IDE and enter the following:

/* 

A simple Processing script for enabling or disabling the LED on an Arduino using a web interface and serial communication. 
Author: Sindre Lindstad 
Created: 19th of January 2011 
http://projects.sindrelindstad.com 

*/

import processing.serial.*; 
Serial port; 

void setup() { 
    /* This part must be altered to fit your local settings. The number in brackets after "Serial.list()" is where you declare what COM port your Arduino is connected to. 
    If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3...) . */ 
    port = new Serial(this, Serial.list()[1], 9600); // Open the port that the Arduino board is connected to, at 9600 baud 
} 
    
void draw() {
    String onoroff[] = loadStrings("http://YOURDOMAIN.COM/LEDstate.txt"); // Insert the location of your .txt file 
    print(onoroff[0]); // Prints whatever is in the file ("1" or "0") 
    
    if (onoroff[0].equals("1") == true) { 
        println(" - TELLING ARDUINO TO TURN LED ON"); 
        port.write('H'); // Send "H" over serial to set LED to HIGH 
    } else { 
        println(" - TELLING ARDUINO TO TURN LED OFF"); 
        port.write('L'); // Send "L" over serial to set LED to LOW 
    } 

    delay(7000); // Set your desired interval here, in milliseconds 
}

Remember to edit it according to the comments. Now you should be all set to hit the Run/Play button!

A small empty window will pop up, but your sketch should be running properly and posting messages in the Processing terminal window. If you haven’t set it to connect to the right serial COM-port it will post an error to the terminal window. If you haven’t set the correct path to your .txt file, it will post “html” instead of “1” or “0”.

Also note that you cannot use the Arduino IDE serial port monitor (or any other serial monitor) while running the sketch. If everything works; - hooray! Show your friends, and have them turn your LED on and off from whereever they might be in the world.

If it doesn’t work, review everything and make sure it’s all set up properly. If it still won’t work; leave a comment.

Update: Reddit user tenbatsu jazzed up the Arduino sketch a bit, and made it a little sexier. It’s designed for the use of three (external) LEDs. A blue LED to fade in and out, a green LED that indicates a “ready” state, and a red LED that indicates a “change” state. Have a look!

const int fadePin = 9; // The pretty blue LED
const int redPin = 10; // Red LED const 
int greenPin = 11; // Green LED 
const int fadeAmount = 5; // Increment to adjust brightness 

int incomingByte; // A variable to read incoming serial data into 
int brightness = 0; // How bright the LED is 

void setup() { 
    // Initialize serial communication: 
    Serial.begin(9600); 

    // Declare outputs: 
    pinMode(fadePin, OUTPUT); 
    pinMode(redPin, OUTPUT); 
    pinMode(greenPin, OUTPUT); 
} 
    
void loop() { 
    // Indicate ready state 
    digitalWrite(greenPin, HIGH); 
    digitalWrite(redPin, LOW); 

    if (Serial.available() > 0) { 
        // Indicate change state 
        digitalWrite(redPin, HIGH); 
        digitalWrite(greenPin, LOW); 
        
        // See if there's incoming serial data: 
        incomingByte = Serial.read(); 
        
        if (incomingByte == 'H' && brightness < 255) { 
            // Cycle the blue LED from dim to bright 
            for (brightness = 0; brightness < 255; brightness += fadeAmount) { 
                analogWrite(fadePin, brightness); 
                delay(30); 
            } 
        } else if (incomingByte == 'L' && brightness > 0) { 
            // Cycle the blue LED from bright to dim 
            for (brightness = 255; brightness > 0; brightness -= fadeAmount) { 
                analogWrite(fadePin, brightness); 
                delay(30); 
            } 
        } 
    } 
} 

Comments:

Please note: These comments are exports from an older platform, and are no longer active.

Beginner tutorial, controlling things with your arduino via a web interface - BuildLounge » BuildLounge - Jan 2, 2012

[…] a self described “Norwegian guy”, has put together this really neat tutorial for people getting started with the arduino. In this tutorial, you can learn how to remotely turn on/off the little blinking light on the […]

waqas - Apr 1, 2012

i am confuse in one thing what is processing ide and arduino ide? should i upload both in arduino or how i m confuse?

hugh - May 5, 2012

thx for you reply. I figured that my arduino is connect to COM3 and it is the only one which shown up. Therefore i change it to port = new Serial(this, Serial.list()[0], 9600); Another problem is that, im hosting a server locally with Apache and i put the LEDtext.txt file under etc/cmos/LEDtext.txt and set the corresponding loadStrings(“localhost/cmos/LEDstate.txt”); but its giving me null exception saying the file is not exist. what did i do wrong?

hugh - May 5, 2012

nvm, i tried to set it as my local directory and it works perfectly nice now :) I have a question tho, what the purpose of using Processing, can we do something in arduino or just PHP to make the LED be controllable from web?

sindre - May 5, 2012

If you connect the Arduino directly (through USB) to the web server, you can feed it commands from PHP using serial communication. Or you could use an Ethernet Shield to connect the Arduino directly to your local network. Otherwise you’ll need a link between the webserver and the Arduino - in this case a computer + Processing.

nightowl - Apr 4, 2012

hello, i do this i put the serial port 0 run but nothing happend with the arduino.

hugh - May 5, 2012

this line: port = new Serial(this, Serial.list()[1], 9600); Im getting arrayoutofbound exception. need help

agus joko - Oct 5, 2012

Help,, I try the code, but the led.php cannot save state 0/1 to LEDstate.php,, maybe we must declare the location of LEDstate.txt file??? thx

yukom - May 2, 2012

that’s works… thanks bro… i’ll develop to the next my project using relay…

yukom - May 2, 2012

@waqas that’s Processing IDE is like an interface of your arduio sketch in Arduino IDE, the analogy like this : Your sketch in arduino IDE is a backend of your project and the Processing sketch in Processing IDE is a front end of user that control your project. i hope that’s will help you, i’m sorry my english not good. :D

sindre - May 5, 2012

If you add this to the setup-part of the code it will print a list of your available serial ports upon initiating the sketch: [code lang=“arduino” highlight=“6” title=“Processing sketch”] void setup() { /* This part must be altered to fit your local settings. The number in brackets after “Serial.list()” is where you declare what COM port your Arduino is connected to. If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3…) . */ println(Serial.list()); port = new Serial(this, Serial.list()[1], 9600); // Open the port that the Arduino board is connected to, at 9600 baud } [/code] Then try using one of the serial ports listed in the terminal output.

sindre - May 5, 2012

You’re probably trying to connect to an unavailable COM-port. First connect the Arduino to your computer, then add this line to the code, and run it. It should list the COM-ports currently used by your computer, before it outputs the ArrayIndexOutOfBoundsException error: [code lang=“arduino” highlight=“6” title=“Processing sketch”] void setup() { /* This part must be altered to fit your local settings. The number in brackets after “Serial.list()” is where you declare what COM port your Arduino is connected to. If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3…) . */ println(Serial.list()); port = new Serial(this, Serial.list()[1], 9600); // Open the port that the Arduino board is connected to, at 9600 baud } [/code] Here’s an example output: _[0] “COM1” [1] “COM4”_ In this case it means that the Arduino is connected to either COM1, which is identified as number 0, or COM4, which is identified as number 1. I know my Arduino is connected to COM4, so I use number 1: _port = new Serial(this, Serial.list()[**1**], 9600);_ On your computer, however, it might be another number. If it’s 0, you use this parameter: _port = new Serial(this, Serial.list()[**0**], 9600);_ or if it’s 2: _port = new Serial(this, Serial.list()[**2**], 9600);_ etc.

Carlo - Feb 4, 2013

Can i enable a LED remotely with an Arduino Uno and Arduino Ethernet Shield without a computer?? I made a remote enable of a motor with the mentioned components, but obviously with a PC, want to do the same without a computer, only with Arduino Uno and Arduino Ethernet shield. It’s possible?

ninjo - Feb 0, 2013

Thank you so much. Finally i found a code that work fine. The only one. Now in trying to do this on a raspberry pi but processing is giving me a few problems.

E.V.Subramania - Jan 2, 2013

thanks for this tutorial i made my own version of the led system have a look here http://arduino.mitfiles.com/ it also has a live webcam feed to show you the output

sachin muley - Mar 0, 2013

Sir.. we did the above mentioned procedure…there is no error in index.html,processing ide and arduino ide. everything is running properly..after clicking on ON in index.html,the text file LED_state.txt is also getting updated to 0 or 1…but the led is not blinking…what is the problem? need help….

siegkorn - Feb 0, 2013

Awesome project!!! thanks for sharing!!!

limuel - Mar 5, 2013

this is nice. but can you help me about my final year project a real time vehicle tracking system with collision detection. the only problem is that i can’t send the data taken from the GPS and send to my web server by GPRS, i’m using arduino atmega644 kit, GPS receiver shield and GSM/GPRS shield. and form my domain server i use DOT.TK a free domain name provider and a 000webhost.com for a free web hosting. can you help me about my problem? by the way the data that will be send by gprs will be automatically save to my database it is also online by the use of 000webhost.com, and the data taht is send is the latitude, longitude and the time or the UTC(Universal Time Coordinates). i’m looking forward for your help. hope you can help me about this.. thank you advance… [email protected]

Pedro Celeste - Mar 4, 2013

Hi, I have an arduino Uno and a shield 3G + GPRS(http://www.cooking-hacks.com/index.php/documentation/tutorials/arduino-3g-gprs-gsm-gps?utm_source=banner_3g_shield&utm_medium=banner) and I am developing a project, this project goal is to get the coordenates from the Arduino (done) and send that data (Latitude and Longitude) to my web Server (DataBase). I follow this example and i think you can help me with this.. If you can send me a code or some ideias how to complete my project i would really apreciate. Best regards

Alex - Feb 2, 2013

Hello, I am really interested in your project. I followed your instructions but when i compile the processing program, I get this error: “NullPointerException” while the following line is highlighted: print(onoroff[0]); // Prints whatever is in the file (“1” or “0”) Could you please help me fix this problem? Thanks, Alex

Zainub - Mar 1, 2013

Hello: I want to connect gprs module to an android application. I have teensy++2.0 it uses arduino IDE. I have to turn on and of led through android application. What should I do. Please help me in using AT commands because I have separate GPRS module and Microcontroller (Teensy++2.0). Thanking in anticipation Zainub Bahar

santha - May 4, 2013

hello bros .. my arduino cant work… i dunno … i used port 27,, so .. how i can write script void setup() { port = new Serial(this, Serial.list()[0], 9600); i try [0] .. processing IDE work ane teeling arduino to run led OFF but i try to index.html… and clink on… no respon ,,, so please help….

dataino - Apr 3, 2013

i develop www.dataino.it in php and u can create your project for recinving data or for send data to arduino take a look create your accaunt a little how to http://www.dataino.it/dataino-doc.pdf

Ankit Joshi - May 3, 2013

Hello, Very nice explanation but i want to know can you perform this same functionality by using webservice through GSM shield.I mean that, i want to operate the led from android mobile wirelessly using GSM shield in arduino without sending sms & voice calls. please reply me as soon as possible. Thanks in advance…

Adam McAllister - Jul 2, 2013

Ok, so I can get it to turn on and off from my computer…but I hooked it up to another computer and it does not work. How would run turn off the LED from across the world. Do they need to run the Processing program as well.???

PHP + Arduino … y cómo encender LEDs por Internet | Federico Pfaffendorf - May 2, 2013

[…] - How to remotely enable/disable a LED on your Arduino using PHP and Processing - Enviar datos de PHP a Arduino - Controlling an Arduino with PHP […]

Cynthia - May 5, 2015

I’m also looking for ways to do it without processing code. Does anybody know if its possible or not?

anitha - Mar 4, 2015

hiii, how to use this without using processing code.

Oldtimer - Apr 3, 2015

Congratulations! Great tutorial. In particular for those interested enough to acquire some basic insight into HTML and PHP. I tried it out successfully on my 6 years old and 8 years old grandchildren. A lot easier than teaching my children to program MCS4004 at micro instruction level before there was an assembler available, but as much fun. NB. There is a module build around ESP8266 that eliminates the need for a computer. Actually, in the case of as simple applications as this one, it makes Arduino obsolete. Now they can run Lego train from the cell phone.

webpage - Apr 5, 2015

Humana People to People gets the job to advance under-developed areas with giving teaching to primary school instructors and artisans, helping advocate well being and present knowledge about Aids and then to assist with more rising the places farming. Humana People to People represents a variety of different plans and duties around poverty-stricken areas of nations globally. By way of working together with the regional individuals and their governing administration, they are able to benefit individuals who’re in need of assistance through their non-profit aid organizations. China is one kind of lots of nations that this non-profit institution visits to confront the demanding concerns that they confront now. The Humana People to People Motion works with The Federation for Associations within the Yunnan province of China. The work started within 2005 and remains throughout today. The Humana People to People Association Assignment Department in the Yunnan Area features to increase funds so as to execute different jobs in the province in poverty-stricken places. A number of plans which Humana People to People tries to take to the current area of China involve business schools in which they’re able to expand their training, preparing them for work opportunities, giving details of infectious illnesses and many more.

budi - May 0, 2015

I am confused how to connect the arduino to use the web tutorial you what pyserial or php_class or web directly associated premises arduino

gunawan - Apr 6, 2015

hallo… i got so much error with this. this is the error message : sketch_apr25a:4: error: ‘import’ does not name a type sketch_apr25a:5: error: ‘Serial’ does not name a type sketch_apr25a:16: error: expected constructor, destructor, or type conversion before ‘=’ token sketch_apr25a.ino: In function ‘void draw()': sketch_apr25a:36: error: ‘loadStrings’ was not declared in this scope sketch_apr25a:37: error: ‘print’ was not declared in this scope sketch_apr25a:40: error: ‘println’ was not declared in this scope sketch_apr25a:41: error: ‘port’ was not declared in this scope sketch_apr25a:45: error: ‘println’ was not declared in this scope sketch_apr25a:46: error: ‘port’ was not declared in this scope this is my sketch : const int ledPin = 13; // the pin that the LED is attached to - change this if you have a separate LED connected to another pin int incomingByte; // a variable to read incoming serial data into import processing.serial.; Serial port; void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); } / This part must be altered to fit your local settings. The number in brackets after “Serial.list()” is where you declare what COM port your Arduino is connected to. If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3…) . */ port = new Serial(this, Serial.list()[1], 9600); // Open the port that the Arduino board is connected to, at 9600 baud void loop() { // see if there’s incoming serial data: if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it’s a capital H (ASCII 72), turn on the LED: if (incomingByte == ‘H’) { digitalWrite(ledPin, HIGH); } // if it’s an L (ASCII 76) turn off the LED: if (incomingByte == ‘L’) { digitalWrite(ledPin, LOW); } } } void draw() { String onoroff[] = loadStrings(“http://YOURDOMAIN.COM/LEDstate.txt”); // Insert the location of your .txt file print(onoroff[0]); // Prints whatever is in the file (“1” or “0”) if (onoroff[0].equals(“1”) == true) { println(" - TELLING ARDUINO TO TURN LED ON"); port.write(‘H’); // Send “H” over serial to set LED to HIGH } else { println(" - TELLING ARDUINO TO TURN LED OFF"); port.write(‘L’); // Send “L” over serial to set LED to LOW } delay(7000); // Set your desired interval here, in milliseconds } the html and php file works fine, but i dont know what i do, i just put together arduino sketch with processing sketch and upload to my arduino. can you help me..? thanks before

adi - Nov 4, 2014

Dear sindre, I am Indonesian, I have tried…. its working, good job…but could you help me how to control 2 or 4 led?…

mahesh ds - Sep 4, 2014

its working thanks a lot explained in a perfect manner

Harsha - Nov 6, 2014

Hello Sir, I had done all steps but in processing IDE I’m getting TELLING ARDUINO TO TURN LED ON but not turning LED ON , I’m using Arduino ATMEGA8. Please Help Me

ondsinet - Apr 5, 2015

very nice worked perfectly!

cn - Apr 0, 2015

can i use ethernet shield instead of processing ide?

lloyd - Oct 3, 2014

hello guys! I would like to ask if it is working in Windows OS? I will appreciate any answers,,

bauer - Feb 2, 2015

I started to write this code everything works fine but when I close proxessing ide it’s stopped working. could anyone tell me why?

Neel - Feb 5, 2015

how to create webpage to upload that three files?

Tanvir - Apr 6, 2015

Hi, this works great! Is there a way to to use the processing code with the WiFiShield rather than a serial connection? In other words, so the Arduino doesn’t have to be connected to a PC when being accessed over the internet?

yulius - May 4, 2015

when i using 2 or 3 led, can u explain to me how to using the port..thanks

sangit - Jun 6, 2015

hi sir. i dont know how to upload index.html , led.php and LEDstate.txt to my website. please guide me the process. only this is my problem. i have tested all others. thanks in advance

Alexander - Jun 5, 2015

Thank you , everything works great ,but how to show the arduino led state on website ?

Sarah - Aug 1, 2015

A great tutorial - only one problem with this line: delay(7000); // Set your desired interval here, in milliseconds I would like this to be every 1 second, but it won’t work with less than 10 seconds - delay(10000); Any less than 10 seconds and the LED just comes on and stays on stubbornly refusing to do anything else. Is there a minimum delay or is there a problem with my equipment?

Daniel - Jun 0, 2015

hi. good job but i would like to do the same using the ethernet shield. Could you pls provide a sketch sample ? i tried by myself with a wamp server using php and arduino ethernet web client, it’s not working. thanks by adv. Daniel

Jeff - Jun 4, 2015

I got all this working great. I use this process to initiate a 12vdc pump through my arduino. The only snag I can’t figure out right now is how to set up the code so it doesn’t run in a loop. I am trying to initiate the on button so it is timed after a few seconds; pumps out the required liquid then stops. I am not good at the coding part. If anyone can give me a hand it would be greatly appreciated. Thanks very much for this walkthrough.

Sarah - Aug 4, 2015

I solved it - the problem only happens with the Mega. Works fine on the Uno :)

yapang - Mar 4, 2016

What is processing app? Where do I write this sketch and how to I upload

Sharad - Aug 4, 2016

I can’t access my text file (LEDstate.text). It shows a 404 error.

Mahesh - Jul 2, 2015

nice 100% work well

LowIQ - Nov 3, 2015

I’m extremely new at this. I’m hoping someone is still active on this thread, however old. I am having a lot of trouble getting the arduino.ino working in isolation on my pcduino nano … it is not throwing up any errors. after uploading (locally) all I get is the cpp (command window)pop up and no matter what I type H or L, nothing happens. I cannot pull up the Port Monitor as it just won’t open while the sketch is running … or it doesn’t seem to open?? As I said, no error are thrown. Any thoughts please?

Rohan - Jan 0, 2016

I’m getting same problem as the Gunawan. Getting What should i do?sketch_apr25a:4: error: ‘import’ does not name a type sketch_apr25a:5: error: ‘Serial’ does not name a type sketch_apr25a:16: error: expected constructor, destructor, or type conversion before ‘=’ token sketch_apr25a.ino: In function ‘void draw()’: sketch_apr25a:36: error: ‘loadStrings’ was not declared in this scope sketch_apr25a:37: error: ‘print’ was not declared in this scope sketch_apr25a:40: error: ‘println’ was not declared in this scope sketch_apr25a:41: error: ‘port’ was not declared in this scope sketch_apr25a:45: error: ‘println’ was not declared in this scope sketch_apr25a:46: error: ‘port’ was not declared in this scope this is my sketch : const int ledPin = 13; // the pin that the LED is attached to – change this if you have a separate LED connected to another pin int incomingByte; // a variable to read incoming serial data into import processing.serial.; Serial port; void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); } / This part must be altered to fit your local settings. The number in brackets after “Serial.list()” is where you declare what COM port your Arduino is connected to. If you get error messages, try a different number starting from 0 (e.g. 0, 1, 2, 3…) . */ port = new Serial(this, Serial.list()[1], 9600); // Open the port that the Arduino board is connected to, at 9600 baud void loop() { // see if there’s incoming serial data: if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it’s a capital H (ASCII 72), turn on the LED: if (incomingByte == ‘H’) { digitalWrite(ledPin, HIGH); } // if it’s an L (ASCII 76) turn off the LED: if (incomingByte == ‘L’) { digitalWrite(ledPin, LOW); } } } void draw() { String onoroff[] = loadStrings(“http://YOURDOMAIN.COM/LEDstate.txt”); // Insert the location of your .txt file print(onoroff[0]); // Prints whatever is in the file (“1″ or “0″) if (onoroff[0].equals(“1″) == true) { println(” – TELLING ARDUINO TO TURN LED ON”); port.write(‘H’); // Send “H” over serial to set LED to HIGH } else { println(” – TELLING ARDUINO TO TURN LED OFF”); port.write(‘L’); // Send “L” over serial to set LED to LOW } delay(7000); // Set your desired interval here, in milliseconds } the html and php file works fine

Ash - Sep 3, 2016

Hello there! I am working on a project involving ultrasonic sensors. Can you please help me with how to use the above steps for reading ultrasonic sensor values??

si - Jun 5, 2016

At the line: import processing.serial.*; it give to me the error: ‘import’does not name a type

Bikram karmakar - Jun 1, 2016

same problame

Jocelyn - May 5, 2016

How do i upload 3 files into website.? could some one guide me on that. Other then that my sketches at Arduino IDE and processing works fine

isra - Mar 2, 2016

hy i’m have problem in print(onoroff[0]); // Prints whatever is in the file (“1” or “0”) thats ArrayIndexOutOfBoundsException:0 eror please help

kavindu - Oct 5, 2015

I’m a beginner to this. I have an error when I compile " exit status 1 ‘import’ does not name a type" Please help me

Parag Naik - Aug 0, 2016

Nice project. Very well explain. After facing so many errors finally I did. LEDstate.txt file accessible in paid domain only. I tried in 000webhost which is free domain website and facing problem doing the project. Overall great project. Thanks for sharing

matia - Aug 6, 2016

hello .. I want to ask how to make serial class

Adrian - Sep 0, 2016

Is the web server a separate machine ?

jymd - Nov 1, 2016

What is this processing ide.Arent there other options in case you are using a different compliler like winavr this print ide is confusing.

davison phiri - Jan 1, 2017

True am desperate and i need a big help on thin how to control arduino system fom php to arduino using GPRS and processing programming language

RJ Ilagan - Feb 3, 2017

I’ve tried this code and did all the procedures but the LED won’t lit when i control it using the website, what could be the problem? and one more thing, Can I use Ethernet Shield instead of the Processing IDE?

jerome - Jul 4, 2017

  • TELLING ARDUINO TO TURN LED OFF anyone can jelp me what is the meaning of that message. that’s the message i get when i try this tutorial. please help me.

Tamunoomie Gogo - Apr 4, 2017

Hei, I just stumbled into this tutorial after so many days of trying to get it without the use of processing. Its wonderful and I used that basics to add more devices. Thanks so much. One love

Ander Dominguez - Apr 0, 2017

Greaaaaaat!!!!! It works!!!!! I have looked at about 10 tutorials and this is the first which works!!!!

Sanket Chauhan - Sep 4, 2019

change 1 to 0 It will work