I have a LED attached to my Arduino wifi shield that I want to control from my PHP web server. In terms of communication, should I

  1. Make my Arduino a web server and then communicate with PHP web server via HTTP

  2. Make my Arduino a web client and receive commands from my PHP web service. I would parse the JSON response

Also my other question is should I communicate with JSON between my PHP web server or is there a better way to send commands to my LED light?

2 Answers 2


There's no need for either PHP or JSON. Simply detect when one of two URLs (say, /led/on and /led/off) has been accessed on the Arduino's web server, change the LED state, and return a 204 response.

  • Is it possible to do this when the arduino is web client instead of a server? Apr 7, 2014 at 6:39
  • 1
    No. If configured as a client then you'll need to have some sort of way to communicate to the client the desired state, requiring parsing on the part of the Arduino. Fortunately you don't need anything particularly complex; a simple 0 or 1 in the response is likely to be enough. Apr 7, 2014 at 6:41
  • i see. One more question. Say I am sending temperature data from a sensor on my arduino board to php server constantly. If the temperature is over 25 degrees then my server would turn on the LED attached to my arduino. How would that work? In this case would the arduino as a web client make sense? Apr 7, 2014 at 6:54
  • 1
    I wouldn't have the PHP server handle this. Have a threshold on the Arduino and have the PHP server communicate with it to set it. Apr 7, 2014 at 7:04

The REST protocol is ideal for this and there's a nice Sketch already written, called RESTduino on Github: https://github.com/jjg/RESTduino

Basically (and loosely) REST treats a URL as a command. Quoting from the RESTduino doc's:

"To turn on the LED attached to pin #9 (currently case sensitive!):

This will set the pin to the HIGH state and the LED should light. Next try this:

This will use PWM to illuminate the LED at around 50% brightness (valid PWM values are 0-255)."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.