- Microsoft Windows, I'm using Windows XP SP3
- Web Server, I'm using EasyPHP as my web server.
This step is based on Windows XP
- Click Start>Settings>Control Panel
- Double click System
- Click on Hardware tab & click Device Manager button
Arduino Source Code
The Arduino source code use in this article is downloaded from Ocean Control. Upload this code to your Arduino if you don't want to buy the device from Ocean Control.
It is very easy to control the Arduino through COM port based on Ocean Control. See example below:
"@00 on 1\r" to turn on LED1
The command string must start will @ & follow by two zero address space which is intended to use for RS485. But you still can use it for RS232.
Remember to put a \r at the end of the command string, it is use to terminate the string with Carriage Return.
There is also a very detail PDF file on how to send the command string which can be download from Ocean Control.
PHP Source Code
The PHP code is very simple, but I encounter a problem that the Arduino always cannot be control when the first command send to the Arduino. I must add a line at line 19 to open the COM port without any valid command in order to make the Arduino to working correctly.
Try & catch is used for error detection. It is also not working in my computer. If the Arduino is not connect to the computer, it just display some nonsense message as below.
Running PHP Code
- Download the PHP source code & place to the WWW folder of the web server.
- Open Internet Explorer or any browser
- Enter http://localhost/phpArduino.php (for EasyPHP 5.39) or http://localhost:8888/phpArduino.php (for EasyPHP 12.0). Note: The port 8888 might be changing.
You will see 4 buttons display on top left of the browser screen, first two buttons use to turn on & off LED1, the next two buttons use to turn on & off LED2. For example, click on button 1 (label 1 on) will send the string command (@00 on 1\n) to the Arduino to turn on LED1, while click on button 2 (label 1 off) will send the string command (@00 of 1\n) to the Arduino to turn off LED1.