1

I would like to use an Arduino microcontroller (with whatever shield necessary) to control LEDs. My challenge is how to get users to interact with a javascript-driven webpage to send a signal to the microcontroller to blink an LED.

r4gt4g
  • 31
  • 3
  • This is a arduino question, not about electronics. – Olin Lathrop Jun 07 '13 at 22:42
  • 6
    @OlinLathrop maybe you would be a lot happier if you ignored the [arduino] tag. – Phil Frost Jun 07 '13 at 22:46
  • 4
    Given the 1854 non-closed [tag:arduino] questions on the site, and the official stance that Arduino questions belong here and not on some hypothetical Arduino SE, the EE world is changing. One might want to either keep up or ignore the tag. This question perfectly belongs here, it's very much about electronics. – Anindo Ghosh Jun 08 '13 at 07:17
  • So do you want the users to browse to the Arduino (Arduino serving the pages), or do you want an existing webserver to connect to an Arduino? – jippie Jun 08 '13 at 07:45
  • He wants to know how to get users to interact with a web page! Question should be closed. – Leon Heller Jun 08 '13 at 08:27
  • 3
    @Anindo: No, it's not about electronics. Some arduino questions can be, but this one isn't. It's at a much high level that is purely software within the arduino environment, which is specifically designed so that people don't have to know about electronics or microcontrollers. If if were asking, for example, how to drive external LEDs given the digital outputs from a microcontroller or even from a arduino, it would be on topic. This is simply not about electronics at all. – Olin Lathrop Jun 08 '13 at 11:30
  • 2
    @Phil: Most arduino questions don't belong here, since they are from the point of view and about the arduino cocoon that specifically removes you from electronics issues. Users that just want to live in that shell don't belong here either. Once they actually want to *learn* about the big world outside and hook up their own things to microcontrollers, whether using arduino development boards or not, *then* they can come here. Until then we need to prevent arduino noise from dragging down this site. – Olin Lathrop Jun 08 '13 at 11:35
  • 1
    From the FAQ: "*We ask and answer questions ... which include electronics, physical computing, and those working with microcontrollers, **Arduinos** and embedded systems.*". Doesn't say "*except software ones within the environment's cocoon*". OP wants to achieve user **interaction with an Arduino**. – Anindo Ghosh Jun 09 '13 at 04:34
  • 1
    @OlinLathrop so [code](http://electronics.stackexchange.com/questions/41620/) [questions](http://electronics.stackexchange.com/q/12684/) [on](http://electronics.stackexchange.com/q/5415/8144) [AVR](http://electronics.stackexchange.com/q/71007) [are](http://electronics.stackexchange.com/q/69721/) allowed but not arduino? – Manishearth Jun 09 '13 at 08:45
  • @Manishearth I believe an individual user doesn't really decide "allowed" v/s "not allowed" in SE sites. Such comments are more a reflection of any individual's limitations. – Anindo Ghosh Jun 09 '13 at 13:36
  • @Manish: That question was at a *much* lower level specifically related to microcontroller details. That is very different from high level software questions about a web server that could really be running on any platform. – Olin Lathrop Jun 09 '13 at 13:55
  • @OlinLathrop: If you look at the answers, no, the web servers can't run on any platform. – Manishearth Jun 09 '13 at 14:03
  • @AnindoGhosh: I thought he was using appeal to authority. – Manishearth Jun 09 '13 at 14:04

3 Answers3

3

The software could combine the arduino examples blink with webserver.

The hardware to run the web server on the arduino would be either the Ethernet or WiFi shield. Alternatively, you may want to run the server on another machine and use the USB serial link from that machine to the arduino to control whether the led is on.

The web server could set a variable when a url is posted to, and that variable could determine whether or not the blinking occurs. Ask at stack exchange or google for the javascript side to use ajax to post a value to a url when the user does something, or use a simple form with checkboxes to start with.

Pete Kirkham
  • 1,976
  • 12
  • 16
  • just to be sure I understand: i can have a website hosted on some private webserver, a webpage served by that server can be interacted with (POST request), that interaction is then POSTed to the Arduino webserver shield? So the arduino webserver is just listening for these requests and can pass them to the microcontroller? (just want to clarify I understand the general process) – r4gt4g Jun 08 '13 at 12:42
  • You could do that, as long as the client doing the POST can reach the arduino. Cross-site restrictions may prevent you POSTing to the arduino from a page on another server; the answer above assumes that the arduino would be the web server. If you have another local computer being the web server, then you can just use the existing USB serial connection to the arduino rather than ethernet. – Pete Kirkham Jun 10 '13 at 12:21
  • Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the links for reference. –  Jun 10 '13 at 14:52
  • @CamilStaps the hardware element is plugging in a ethernet or wifi shield, and I didn't want to have too long a software answer on an electronics site, so just linked to the relevant pages. – Pete Kirkham Jun 10 '13 at 15:42
  • There's absolutely nothing wrong with software, as long as it's electronics-related ;) but it's a good consideration! –  Jun 10 '13 at 15:58
  • @CamilStaps As evidenced from the comments on the question, I think Olin Lathrop would categorically disagree with you. :) – mikeY Jun 10 '13 at 16:18
2

javascript-driven webpage to send a signal to the microcontroller to blink an LED

Assuming you want the outside (webserver) to contact your Arduino when an user interaction occurs - and NOT just poll for state changes as an earlier answer explains.

You need your Arduino and an Ethernet shield configured as a "webserver" to answer incoming requests and blink your LED when appropriate. You also need to defeat your local NAT/Firewall with a DMZ or port-forwarding (so the Arduino can be reached from the outside world).

On the outside (website), on your interaction page (that is, the page the web user reaches and should make your Arduino blink) - add the simple IMG tag with your Arduino IP and URL string. The web user's browser will attempt to fetch the IMG and tickle your Arduino, which will then blink. Ditto with javascript adding inline document.write of an IMG tag as needed.

Far more efficient to simply host the webpage on the Ardiuno since it will be accepting incoming traffic anyways.

Ron J.
  • 348
  • 4
  • 13
1

I would try using Xively

https://xively.com/dev/tutorials/arduino_wi-fi/

You could have the Arduino running as a server, but that would require a static ip and some port-forwarding to get the Arduino out on the web so that your webpage could POST to it. (By the way I find using GET is simpler than POST for small amount of data.)

Xively is polling based, so your Arduino can be behind a firewall.

geometrikal
  • 4,921
  • 2
  • 23
  • 41