Go Down

Topic: Controlling Arduino with JavaScript in web browser (Read 6819 times) previous topic - next topic


May 21, 2012, 11:29 am Last Edit: May 21, 2012, 07:38 pm by stanleyhuang Reason: 1
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
Code: [Select]
<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
Code: [Select]
/* 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 = EEPROM.read(addr);

Controlling a servo
Code: [Select]
/* create servo object */
var myServo = new Servo();
/* attach servo to pin 3 */
/* set servo angle */
/* get servo angle */
var angle = myServo.read();
alert("Current angle is " + angle);

My Arduino blog: http://arduinodev.com/blog


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?


Hey, I seem to have the same problem like mnelson07860, there are no ports to select from in the index.html page, tried to add them manually but still could not connect. when opening the ArduGate.exe file it just shows 403 Forbidden error page.


i have same issue :when opening the ArduGate.exe file it just shows 403 Forbidden error page.

Go Up