1
\$\begingroup\$

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.

\$\endgroup\$
13
  • 6
    \$\begingroup\$ @OlinLathrop maybe you would be a lot happier if you ignored the [arduino] tag. \$\endgroup\$ – Phil Frost Jun 7 '13 at 22:46
  • 4
    \$\begingroup\$ Given the 1854 non-closed 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. \$\endgroup\$ – Anindo Ghosh Jun 8 '13 at 7:17
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ – Olin Lathrop Jun 8 '13 at 11:30
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – Olin Lathrop Jun 8 '13 at 11:35
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Anindo Ghosh Jun 9 '13 at 4:34
3
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ 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) \$\endgroup\$ – r4gt4g Jun 8 '13 at 12:42
  • \$\begingroup\$ 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. \$\endgroup\$ – Pete Kirkham Jun 10 '13 at 12:21
  • \$\begingroup\$ Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the links for reference. \$\endgroup\$ – user17592 Jun 10 '13 at 14:52
  • \$\begingroup\$ @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. \$\endgroup\$ – Pete Kirkham Jun 10 '13 at 15:42
  • \$\begingroup\$ There's absolutely nothing wrong with software, as long as it's electronics-related ;) but it's a good consideration! \$\endgroup\$ – user17592 Jun 10 '13 at 15:58
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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