I have a light sensor that turns off a LED when it detects light and turns on the LED when it doesn't detect any light, this loop repeats itself thru infinity...
Now, my question is, if i wanted to connect this to a database and updates the database everytime the sensor detects changes, how do i do that using php
and also, i also don't know what code to use in the web server that checks changes in this database and sends alert or sumthing so that i can turn the LED on and off via web.
Now, my question is, if i wanted to connect this to a database and updates the database everytime the sensor detects changes, how do i do that
You need an Ethernet shield, and to have the Arduino act as a client. Look at the example for doing that.
The client will then contact the server, and execute the specified (php) script, supplying whatever information is required for the script to execute.
The script will return some sort of response, which the Arduino should read (and act upon, if appropriate).
using php
You can use any scripting language you like, on the server. Obviously, it makes no sense to try to execute php on the client.
and also, i also don't know what code to use in the web server that checks changes in this database and sends alert or sumthing
That is not an Arduino-specific requirement. It is server-side code.
so that i can turn the LED on and off via web.
You seem to think that you can run a client (send data to a server) and a server (respond to requests to control LEDs) at the same time. You can, though it isn't trivial.
You also seem to think that you can control the light sensor from the internet. You can't. The input to the sensor is not data from a client somewhere. It is light hitting it.
maybe you would have to alter your code to handle/know it is in 'manual' mode or something? (ie: ignoring the light sensor data/code routine, when you manually change the light through your 'GUI')?
I do not have an Arduino Ethernet shield to play/test with..
but I have made a LOCAL version of a GUI/front end, that uses PHP to send data to the 'waiting' Arduino via SERIAL COMM.
I used a local installation of WAMP Server to dev/test this all out.. (and posted all files somewhere around here..lol)
this allows you to call up the 'web page' you created (I happened to use ADOBE FLASH as an interface as well to send the data to the php script that gets forwarded over to the serial com of choice)..
click on 3 numeric steppers to increase a PWM value from 0-255..then send the data and an RGB led will 'update' using these values.
To access it from outside your LAN...and truly from the internet.. you would have to log into your router and forward over the HTTP port to the IP address of the machine you installed WAMP on.. (so any traffic coming to your IP is routed to the 'web server' to deliver the GUI/html page...etc.
what I havent attempted to work out is:
1.) sending/listening for DATA on the SERIAL COM port coming FROM the Arduino to the PHP 'script'...
2.) I havent touched on any database attempts, because I havent messed around with #1 above yet.. (ie: no data to save basically)
once you can receive data FROM the Arduino to a PHP script..the database part is trivial..
**apparently..its very hard to go from Arduino >> PHP (most classes only support this under Linux?)... but going form PHP to Arduino is 'fine'.. (if you wanted to log the 'count/state' from the GUI starting point/interface.. you could.. but you wouldnt be able to get a reply/confirmation from the Arduino on things..