Go Down

Topic: Serial communication from browser (Read 2016 times) previous topic - next topic


Jun 29, 2011, 03:02 pm Last Edit: Jun 29, 2011, 03:21 pm by notexa Reason: 1
Hi everybody,

I'm trying to do the following:
I'm using a live chat application. The problem is that I'm not always looking at my monitor. To make sure I don't miss any chats I wanted to activate a flashing lamp when a chat opens.

What I've got now:
Program that talkes with Arduino through serial USB (prossessing on windows Vista), lamp connected to the Arduino through a relay. Chat window in which I can change the code (or implement an iframe if necessary).

What I still need:
A way to send serial commands (ethernet shield isn't an option) from the browser to the Arduino. It's only for 1 PC, so if I have to install software locally, that's possible.
Anybody that can point me in the right direction ?


Attached is the schema of what I'm trying to do.


You'll probably need something like a webserver running on your PC, so you can go to http://localhost/popupmessage.php (or whatever language you want).  Then your popupmessage.script can talk to the serial port.  You might get all sorts of issues with cross-site scripting blocks and stuff, but I've never tried.  There are some PHP classes that can talk to serial ports, I think.  Perhaps google it.
Current Projects: Rodentometer - Hamster Endurance Moni


Thanks for the tip !
Googling for serial and php gave tons of pages, but finally found something that works :)
I used serialcomm.zip from http://missionduke.com/arduino-projects/

Leds flickering with a status update on the LCD: check, next step: connecting it to my relay.


First thought - why handle the stop button on the PC side.  Having a physical button attached to the Arduino to handle this seems far simpler and also has the additional benefit of allowing for an amusing button:
If your system involves lethal voltages/life critical/flamable elements - you probably shouldn't need to ask.
The Arduino != PC.


That's actually a nice idea :)
And true, the coolness factor increases 10-fold.

I currently have the following code:
Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int ledPin13 = 13;                 // LED connected to digital pin 13
int incomingByte;      // a variable to read incoming serial data into
char* LCDStrings[]={"Incoming chat","Click stop flash","Alarm stopped","Have a good chat"};

void setup() {
  lcd.begin(16, 2);
  pinMode(ledPin13, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600); // initialize serial communication

void loop() {
if (Serial.available() > 0) {
  incomingByte = Serial.read(); // read the oldest byte in the serial buffer

  while (incomingByte == 48) {
    digitalWrite(ledPin13, HIGH);   // sets the LED on
    digitalWrite(ledPin13, LOW);   // sets the LED on
    if (Serial.available() > 0) {
      incomingByte = Serial.read(); // read the oldest byte in the serial buffer
  if (incomingByte == 177) {
    digitalWrite(ledPin13, LOW);    // sets the LED off

int PrintLCD(byte messageid) {
  lcd.setCursor(0, 0);
  lcd.setCursor(0, 1);

Is this ok ? Are there optimalizations possible ?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131