Give Your Arduino Project It’s Own Mini-Webserver, With An Ethernet Shield

details

We’re going to look at setting up an Arduino as a basic webserver so we can host our own device control website.

You will need:

First things first – open up the File->Examples->Ethernet->WebServer that’s provided within the Arduino IDE. Find the lines referring MAC and IP address.

Edit the line that says EthernetServer server(number), and change the number to8081. This will setup our server to listen on port 8081 in case your ISP is blocking web traffic on the traditional port 80.

Reading these values is all well and good, but making the jump to controlling an Arduino from here is quite a leap, and outside the scope of this tutorial today. Instead of re-inventing the wheel, I’ll point you towards Arduino forum user hari who wrote a basic API for interacting with digital pins. Using this code (I’ve modified it to work with the latest Ethernet library), connect the long lead of an LED (anode) to pin 8, and the short lead to pin 7 (with a suitable resistor). You can then use URLs of the form http://ip:port/digitalWrite/8/1 to turn on the LED, and http://ip:port/digitalWrite/8/0 to turn it off, and read analog values withanalogRead/0.

This example from bildr will also teach you how to control a sequence of LEDs by reading the GET request.

You might also like to checkout this example which outputs a form on the page to control a blinkm RGB LED, though you could easily adapt it for an RGB  strip such as the dynamic ambient lighting project we built a while back.

Source : http://www.makeuseof.com/tag/give-your-arduino-project-its-own-mini-webserver-with-an-ethernet-shield/?utm_source=tuicool

We’re going to look at setting up an Arduino as a basic webserver so we can host our own device control website.

You will need:

First things first – open up the File->Examples->Ethernet->WebServer that’s provided within the Arduino IDE. Find the lines referring MAC and IP address.

Edit the line that says EthernetServer server(number), and change the number to8081. This will setup our server to listen on port 8081 in case your ISP is blocking web traffic on the traditional port 80.

Reading these values is all well and good, but making the jump to controlling an Arduino from here is quite a leap, and outside the scope of this tutorial today. Instead of re-inventing the wheel, I’ll point you towards Arduino forum user hari who wrote a basic API for interacting with digital pins. Using this code (I’ve modified it to work with the latest Ethernet library), connect the long lead of an LED (anode) to pin 8, and the short lead to pin 7 (with a suitable resistor). You can then use URLs of the form http://ip:port/digitalWrite/8/1 to turn on the LED, and http://ip:port/digitalWrite/8/0 to turn it off, and read analog values withanalogRead/0.

This example from bildr will also teach you how to control a sequence of LEDs by reading the GET request.

You might also like to checkout this example which outputs a form on the page to control a blinkm RGB LED, though you could easily adapt it for an RGB  strip such as the dynamic ambient lighting project we built a while back.

Source : http://www.makeuseof.com/tag/give-your-arduino-project-its-own-mini-webserver-with-an-ethernet-shield/?utm_source=tuicool

4
COMMENTS

Please Login to comment
4 Comment authors
Clients6.Coffee4Well-Being.Comobiezyswiat.orgheroes charge hackadamcampo.com Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
adamcampo.com
Guest

Superb, what a website it is! This blog gives useful data to us, keep it up.

heroes charge hack
Guest

This is very interesting, You’re a very skilled blogger.
I’ve joined your rss feed and look forward to seeking more of your excellent post.
Also, I’ve shared your website in my social networks!

obiezyswiat.org
Guest

I blog often and I genuinely appreciate your information. Your article has really peaked my interest.
I’m going to book mark your website and keep
checking for new information about once a week. I opted in for your Feed
as well.

Clients6.Coffee4Well-Being.Com
Guest

What’s up, I read your blog on a regular basis. Your writing style is witty, keep doing
what you’re doing!