Hi,
I've just registered, so this is my first post after "lurking" around the forum for a while seeing what people have been doing in the area.
I've had a look round the forums and I can't find the solution to my particular problem. I've been interested in home automation for a while, and after exploring the options available I settled on the following:
- Arduino Mega 2560
- Arduino Ethernet shield
- relay modules connected to output pins on the arduino (similar to this: http://www.ebay.co.uk/itm/like/121310853746?limghlpsr=true&hlpv=2&ops=true&viphx=1&hlpht=true&lpid=108&device=c&adtype=pla&crdt=0&ff3=1&ff11=ICEP3.0.0&ff12=67&ff13=80&ff14=108
I have also coded (with my very limited knowledge of HTML5 and CSS) a website which after a load of struggling, I've finally managed to get run successfully (and more importantly display properly with all the CSS and JS) off the Ethernet shield SD card. I chose HTML rather than an android / Ipad app as with HTML I can just log onto a website on the LAN and use either the laptop / ipad /iphone / or android phones rather than develop a platform specific interface for each.
Within one of the "control" pages (in this case "bathroom.htm") I have an "ON/OFF" button for a lightbulb, and I am wondering how I would go about coding this both from a HTML and a Arduino sketch perspective. Note here that I've seen several implementations on these forums and on the internet of separate ON and separate OFF buttons, which set the Pin to "LOW" and "HIGH" respectively, but I've not seen any HTML code I can allocate to a single button which when the button is pressed will switch the PIN from "HIGH" to "LOW" when the current state is "HIGH", but from "LOW" to "HIGH" when the current state is low.
Could somebody help me out with the following please:
- HTML code for the button
- Arduino sketch for the arduino running the standard webserver sketch (so maybe just the additional lines for void setup(), and the full lines for void loop () )
I've attached a picture of the button on my webpage to this post, and the HTML behind this currently this is as follows:
<section>
<header>
<h3>Lights</h3>
</header>
<p>Central lighting unit with extractor fan. </p>
<footer>
<ul class="buttons">
<li><a href="#" class="button special">ON / OFF</a></li>
</ul>
</footer>
</section>
I assume that the solution will use the serial.print function, and maybe an if statement like...
if (currentState == HIGH && lastState == LOW)
....but I'm not quite sure how to tie this all together into the HTML / arduino sketch.
Please note that it would also be useful if I could expand this solution to cover a number of additional buttons (ie an expandable solution), so if I had 10 lightbulbs in the house connected through relays to 10 different pins on the Arduino, the solution would allow me to differentiate between these and map a slight variation of the standard code to each of the 10 buttons on my webpage, to switch any of these bulbs on or off independently with that button press.
Any help at all is much appreciated! XD
P.S I've found the following links which I've seen doing something similar but in both cases it's not quite what I want:
http://forum.arduino.cc/index.php?topic=72204.0