use arduino to get data from MySQL database

hi guys,

I've been searching a few days, but not really found something.
what i would really like to do is use a MySQL database to control my Arduino Mega(1280). so i can use a web interface to control my arduino.
i wand it to do like this because i have really good knowledge of php, HTML & CSS.
my arduino will be in my PC case it self so it will be always connected to my pc. it will mostly control a lot of leds in my pc case
i have already a local & internet webserver running so no problems on that side :slight_smile:

if it is not possible to use a MySQL database to control the arduino.
i will probably use a php script to send strings or something similar to the arduino which will then set the corresponding output
i know this can be done because i've seen people do it:

tried to set this up but there was no support for windows)

Curently im trying to get this code working but not really succesfull, i keep getting the error "fopen(COM3): failed to open stream: Permission denied in E:\Scripting\Arduino-MEGA\webcontrol\index.php"

## index.php ##
	$fp = fopen("COM3", "w");
	while (true){
		$i = ($i + 1) % 10;
		echo "Wrote $i - the LED should flash (" . ($i % 2 == 0 ? ' 1 time ' : '2 times ') . ")\r\n";
		fwrite($fp, chr($i));
		sleep(3);
	}
	fclose($fp);

## Arduino code ##
int ledPin = 13;
int usbnumber = 0;
void setup() {
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    if (Serial.available() > 0) {
        usbnumber = Serial.read();
    }

    if (usbnumber > 0) {
        if (usbnumber % 2 == 0){
            digitalWrite(ledPin, HIGH);
            delay(300);
            digitalWrite(ledPin, LOW);
            delay(300);
        }else{
            digitalWrite(ledPin, HIGH);
            delay(300);
            digitalWrite(ledPin, LOW);
            delay(300);
            digitalWrite(ledPin, HIGH);
            delay(300);
            digitalWrite(ledPin, LOW);
            delay(300);
        }
        usbnumber = 0;
    }
}

i don't think its the arduino code, just php that can't connect to it, yes i checked arduino is at COM3, will keep looking to get it work :slight_smile:
EDIT: got this code working, needed to use "\.\COM3" instead of just "COM3"

any help is appreciated :slight_smile:

Mvg Maarten

There are various ways to have the Arduino controlled from the PC. What operating system is the PC running? What sort of controls do you want to send the Arduino? Is it just a matter of storing some sort of configuration data in the database and have the Arduino look it up when required? Will the configuration data need to change? If so, how do you intend the Arduino to detect the change - is it polling the configuration?

i have Windows 7 Ultimate 64-Bit running
my goal is to control a lot of LED's in my pc case and be able to set different 'profiles'
i'm currently thinking of using a php script witch send all outputs to the arduino so it knows witch LED's there need to burn
and let the php script set up the different 'profiles' for the LED's
if i can use a database to control my arduino i will let it check like every 5 secs or more

EDIT: got the php script working now, needed to use "\.\COM3" instead of just "COM3", don't ask me why but i find it at a page from microsoft -> Naming Files, Paths, and Namespaces - Win32 apps | Microsoft Learn

Maarten200:
i find it at a page from microsoft -> Naming Files, Paths, and Namespaces - Win32 apps | Microsoft Learn

That's a very interesting link, thanks for sharing.

hi i'am new here and i'am doing the same project im just curious where did you get that video..thanks in advance :smiley:

here is the YouTube channel:

I have also done a similar project:

Using a PC/WIndows XP, FLASH & PHP.. (Wamp Server)and an Arduino..

http://arduino.cc/forum/index.php/topic,124394.0.html

you can easy include the MySQL database portion from WAMP server and communicate to it through a PHP script..

hi friend..i am new to arduino. am using UNO. i am having a great doubt. i am doing a project on nfc shield. so i want to know when the nfc tags are read by the sheild it should compare the ID of tag with sql server and if matched it should go for next loop... what should i do for that... pleasee help me...