Pages: [1]   Go Down
Author Topic: Controlling Arduino with JavaScript in web browser  (Read 2501 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
Karma: 3
Posts: 108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ArduGate is an open-source web gateway software I am developing, for interfacing Arduino with JavaScript. It is actually made up of a serial-to-HTTP gateway (based on my miniweb project), some JavaScript routines performing communication with AJAX and an agent sketch running on Arduino.
It makes interaction between in-browser JavaScript and Arduino possible, and thus makes developing a up-stream application for Arduino that runs on any platform with a browser a lot easier.

You can find more information and download it on the project homepage.
Right now access to following Arduino APIs/objects are implemented:
  • pinMode
  • digitalRead/digitalWrite
  • analogRead/analogWrite
  • EEPROM (read/write)
  • Servo (attach/detach/read/write)
  • Wire

The key concept is using JavaScript inside the web browser to interact with Arduino. Here are several demostrating JavaScript code clips. You will find the code similar to that in an ordinary Arduino sketch.

Blinking Example
<script language="javascript" src="serial.js"></script>
<script language="javascript" src="arduino.js"></script>
<script language="javascript">
var port = "COM18";
var on = false;

self.setInterval(blink, 1000);

function Start()
    connected = SerialOpen(port, 57600);
    if (!connected) {
        alert("Error connecting with Arduino on " + port);
    pinMode(13, OUTPUT);

function Stop()
    connected = false;

function blink()
    if (connected) {
        digitalWrite(13, on ? HIGH : LOW);
    on = !on;

<input type="button" value="Start" onClick="Start()" />
<input type="button" value="Stop" onClick="Stop()"/>

Accessing EEPROM
/* write a byte of 0x80 to EEPROM at address 0xA0*/
var address = 0xA0;
var data = 0x80;
if (EEPROM.write(addr, data))
/* success, now read back from EEPROM */
data =;
Controlling a servo
/* create servo object */
var myServo = new Servo();
/* attach servo to pin 3 */
/* set servo angle */
/* get servo angle */
var angle =;
alert("Current angle is " + angle);

« Last Edit: May 21, 2012, 12:38:47 pm by stanleyhuang » Logged

Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am unable to get the "ArduGate Demo" http://localhost:8880/ to communicate with my Arduino. The port box is empty. there are no com port choices to select from. When I try to send a command, I get a message from the webpage: Error sending command .  command: 0x10  code:0 Can anyone help me with this problem?

Pages: [1]   Go Up
Jump to: