<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>codetorment &#187; wireless</title>
	<atom:link href="http://www.codetorment.com/tag/wireless/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codetorment.com</link>
	<description>code, tech, random stuff</description>
	<lastBuildDate>Tue, 04 May 2010 21:04:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=6206</generator>
		<item>
		<title>Arduino wireless motion detector : part 3</title>
		<link>http://www.codetorment.com/2009/11/07/arduino-wireless-motion-detector-part-3/</link>
		<comments>http://www.codetorment.com/2009/11/07/arduino-wireless-motion-detector-part-3/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 16:43:24 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ethernet]]></category>
		<category><![CDATA[motion]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rf-transmitter]]></category>
		<category><![CDATA[shield]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=394</guid>
		<description><![CDATA[In this third and final part I&#8217;ll show you how to get the arduino to access a website using an ethernet shield and php. The data can then be displayed in a number of ways. Here the data is simply printed one line at a time. Each time motion is detected, the networked arduino connects [...]]]></description>
			<content:encoded><![CDATA[<p><strong>In this third and final part I&#8217;ll show you how to get the arduino to access a website using an ethernet shield and php. The data can then be displayed in a number of ways. Here the data is simply printed one line at a time.</strong></p>
<p>Each time motion is detected, the networked arduino connects to the web and executes a php script which writes the time and date of the event to a text file. When you want to check if motion was detected, acces a different php script which displays all (if any) recorded events.</p>
<p>Check my next post to see how to send sensor data from the arduino to a website using php.</p>
<p>If you followed<a title="part 1" href="http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/" target="_blank"> part 1</a> and <a title="part 2" href="http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/" target="_blank">part 2</a> all you need to do for part 3 is change the code of the receiving arduino since we&#8217;re only changing the output from &#8216;blink a led&#8217; to &#8216;access a website&#8217;.<span id="more-394"></span></p>
<p>Sketch :</p>
<pre class="brush: cpp;">
#include &lt;Ethernet.h&gt;

int ledPin = 13;    // pin for the LED
int RFinPin = 8;    // pin for the RF receiver
int val = 0;         // variable for reading the pin status
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };    // unique mac address
byte ip[] = { 192, 168, 1, 36};        // unique and valid ip for your network
byte server[] = { 77, 222, 78, 32};  // ip google

void setup() {
   Ethernet.begin(mac, ip);
   pinMode(ledPin, OUTPUT);    // declare LED as output
   pinMode(RFinPin, INPUT);    // declare RF receiver as input
   Serial.begin(9600);
   delay(1000);
}

Client client(server, 80);

void loop(){
   val = digitalRead(RFinPin);        // read input value
   if (val == HIGH) {
     digitalWrite(ledPin, HIGH);      // turn LED ON
     if (client.connect()) {
       Serial.println(&quot;connected&quot;);
       client.println( &quot;GET /folder/movement.php HTTP/1.1&quot;);
       client.println(&quot;Host: yourdomain.com&quot;);
       client.println(&quot;Connection: close&quot;);
       client.println();
       client.stop();
     } else {
       Serial.println(&quot;connection failed&quot;);
     }
   } else {
     digitalWrite(ledPin, LOW);       // turn LED OFF
   }
   delay(5000);
}
</pre>
<p>The script movement.php is executed when the arduino connects to <em>www.yourdomain.com/folder/movement.php</em></p>
<p>movement.php code :</p>
<pre class="brush: php;">
&lt;?php

$myFile = &quot;movement_data.txt&quot;;
$fh = fopen($myFile, 'a') or die(&quot;can't open file&quot;);
$stringData = date(&quot;D, d M Y H:i:s&quot;) . &quot;\n&quot;;
fwrite($fh, $stringData);

fclose($fh);

?&gt;</pre>
<p>The script display_movement.php takes the movement data and prints one line for every event recorded.</p>
<p>display_movement.php code:</p>
<pre class="brush: php;">
&lt;?php

 $fileName = &quot;movement_data.txt&quot;;

 if(file_exists($fileName)){
      $file = fopen($fileName,'r');

      while(!feof($file)){
                $name = fgets($file);
                if($name != NULL){
                echo('&lt;br&gt;'. &quot;Movement registered on : &quot;.$name.'&lt;/br&gt;');
			}
        }

        fclose($file);
}
?&gt;
</pre>
<p>When display_movement.php is executed you should see something like :</p>
<p><a href="http://www.codetorment.com/wp-content/uploads/movement.png"><img class="alignnone size-full wp-image-621" title="movement" src="http://www.codetorment.com/wp-content/uploads/movement.png" alt="movement Arduino wireless motion detector : part 3" width="380" height="128" /></a></p>
<p>In the next post I&#8217;ll discuss how to write sensor data (light intensity, temperature,&#8230;) to a website and plot a line chart using php.</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/11/07/arduino-wireless-motion-detector-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino wireless motion detector : part 2</title>
		<link>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/</link>
		<comments>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 17:23:58 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[ethernet]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[rf-transmitter]]></category>
		<category><![CDATA[shield]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=345</guid>
		<description><![CDATA[In this part we&#8217;ll connect to a webpage and fetch some data from a php script. When building a project it&#8217;s better to test and debug each part on its own instead of trying to debug a much larger system. So we&#8217;ll start by attaching an ethernet shield and get it to talk to a [...]]]></description>
			<content:encoded><![CDATA[<p>In this part we&#8217;ll connect to a webpage and fetch some data from a php script.</p>
<p>When building a project it&#8217;s better to test and debug each part on its own instead of trying to debug a much larger system. So we&#8217;ll start by attaching an ethernet shield and get it to talk to a webpage. Once that is up and running we&#8217;ll connect the second arduino and rf.</p>
<p><span style="color: #ffffff;">Note: For this part you&#8217;ll need a webhosting account with a company who provides access to PHP on it&#8217;s accounts. Or you&#8217;ll need to run a local webserver. Contact your webhost to verify if your account has PHP access enabled.</span></p>
<div id="attachment_350" class="wp-caption alignnone" style="width: 526px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9556.JPG"><img class="size-full wp-image-350   " title="DSCN9556" src="http://www.codetorment.com/wp-content/uploads/DSCN9556.JPG" alt="Arduino Ethernet Shield" width="516" height="425" /></a><p class="wp-caption-text">Arduino Ethernet Shield</p></div>
<p><span id="more-345"></span>First we&#8217;ll create a script named &#8216;time.php&#8217; which will print out the date and time when we visit www.yourdomain.com/time.php . Open the file and paste the following code:</p>
<pre class="brush: php;">
&lt;?php
// Prints something like: Sunday 25th of October 2009 07:12:46 PM
echo date('l jS \of F Y h:i:s A');
?&gt;
</pre>
<p>Now close, save and upload time.php to your domain. If you put the script in the www or public_html folder it will be accesible from www.yourdomain/time.php if you&#8217;ve placed it inside another folder make sure to use www.yourdomain.com/folder/time.php in the next part.</p>
<p>Before we continue, open a webbrowser and go to www.yourdomain/time.php or wherever you placed the script and make sure it shows the date and time.</p>
<p>When the script is working, start the arduino IDE , create a new sketch and copy paste the code below</p>
<pre class="brush: cpp;">
#include &lt;Ethernet.h&gt;

byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {   xxx, xxx, xxx, xxx};
byte server[] = { yyy, yyy, yyy, yyy};

Client client(server, 80);

void setup()
{
  pinMode(switchPin, INPUT);
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println(&quot;connecting...&quot;);

  if (client.connect()) {
    Serial.println(&quot;connected&quot;);
    client.print(&quot;GET http://www.yourdomain.com/folder/time.php HTTP/1.0\n&quot;);
    client.print(&quot;Host: www.yourdomain.com\n\n&quot;);
    client.println();
  }
  else {
    Serial.println(&quot;connection failed&quot;);
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println(&quot;disconnecting.&quot;);
    client.stop();
    for(;;)
      ;
  }
}
</pre>
<p>&nbsp;</p>
<pre class="brush: cpp;">byte ip[] = { xxx, xxx, xxx, xxx};
</pre>
<p>Make sure to change the xxx, xxx, xxx, xxx with your settings, where xxx, xxx, xxx, xxx should be an available ip in the range of your network. Check your router for the range of ip-adresses in your network.</p>
<p>in my case the above line would read :</p>
<pre class="brush: cpp;">
byte ip[] = { 192, 168, 1, 36};
</pre>
<p>Next is the ip address of the server you wish to connect to. If your webhost does not provide you with a unique ip dedicated to your domain you should try using google&#8217;s ip. To check if your domain is asigned a unique ip ( your domain is the only one hosted on that ip ) open a command prompt and ping your domain with &#8216;ping www.yourdomain.com&#8217;.  On the next line the ip adress associated with your domain should show up on windows in the form of &#8216;Ping statistics for domain xxx.xxx.xxx.xxx&#8217;. Now open a browser and type in xxx.xxx.xxx.xxx instead of www.yourdomain.com. If you are seeing your domain, you have a unique ip assigned to your domain. If not, ping www.google.com and use the ip adress returned for the yyy.yyy.yyy.yyy below.</p>
<pre class="brush: cpp;">
byte server[] = { yyy, yyy, yyy, yyy};
</pre>
<p><a href="http://www.codetorment.com/wp-content/uploads/cmd02.jpg"><img title="cmd02" src="http://www.codetorment.com/wp-content/uploads/cmd02.jpg" alt="cmd02 Arduino wireless motion detector : part 2" width="535" height="192" /></a></p>
<p>So the server ip becomes :</p>
<pre class="brush: cpp;">
byte server[] = { 74, 125, 67, 100};
</pre>
<p>These settings should get you up and running. The only thing left to do is change these lines to match your domain and the url of the time.php script :</p>
<pre class="brush: cpp;">
client.print(&quot;GET http://www.yourdomain.com/folder/time.php HTTP/1.0\n&quot;);
client.print(&quot;Host: www.yourdomain.com\n\n&quot;);
</pre>
<p>Now upload the code to the arduino and open the serial monitor.<br />
If all went well the monitor should show something similar:</p>
<div id="attachment_389" class="wp-caption alignnone" style="width: 409px"><a href="http://www.codetorment.com/wp-content/uploads/serial.JPG"><img class="size-full wp-image-389" title="serial" src="http://www.codetorment.com/wp-content/uploads/serial.JPG" alt="Serial Monitor" width="399" height="352" /></a><p class="wp-caption-text">Serial Monitor</p></div>
<p>As you can see second to last line displays the correct date and time.</p>
<p>Check <a title="Part 3" href="http://www.codetorment.com/2009/11/07/arduino-wireless-motion-detector-part-3/" target="_self">part 3</a> where I show you how to put it all together to create a weblogging wireless motion detector.</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arduino wireless motion detector : part 1</title>
		<link>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/</link>
		<comments>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 03:06:48 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[rf-transmitter]]></category>
		<category><![CDATA[shield]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=316</guid>
		<description><![CDATA[This video shows a very basic setup of two arduinos talking wireless over RF. The two rf-boards used in this setup were discussed earlier in this post. The left arduino has a sensorshield with a PIR-sensor and a rf-transmitter connected to it. When the PIR-sensor detects changes in IR-radition in it&#8217;s field of view, it [...]]]></description>
			<content:encoded><![CDATA[<p>This video shows a very basic setup of two arduinos talking wireless over RF.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=7242154&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=7242154&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>The two rf-boards used in this setup were discussed earlier in <a title="RF-transmitter-receiver" href="http://www.codetorment.com/2009/10/24/arduino-goodness-continued/" target="_blank">this</a> post.</p>
<p>The left arduino has a sensorshield with a PIR-sensor and a rf-transmitter connected to it. When the PIR-sensor detects changes in IR-radition in it&#8217;s field of view, it triggers the rf-transmitter and a red led.<span id="more-316"></span></p>
<p>The right arduino just has a rf-receiver and a green led connected to it. When the right arduino receives a radio signal the green led turns on.</p>
<p>Code for the transmitting arduino:</p>
<pre class="brush: cpp;">
int ledPin = 12;                 // pin
int pirPin = 4;                  // pin for PIR-sensor
int RFoutPin = 7;                // pin for RF transmitter
int value = 0;                   // used to store data from PIR-sensor

void setup() {
pinMode(RFoutPin, OUTPUT);       // declare RF-transmitter as output
  pinMode(ledPin, OUTPUT);       // declare led as output
pinMode(pirPin, INPUT);          // declare PIR-sensor as input
}

void loop() {
value = digitalRead(pirPin);     // read PIR-sensor
if (HIGH == value) {             // transmit HIGH signal
digitalWrite(RFoutPin, HIGH);
digitalWrite(ledPin, HIGH);
}
else {                           // transmit LOW signal
    digitalWrite(RFoutPin, LOW);
    digitalWrite(ledPin, LOW);
 }

}
</pre>
<p>Code for the receiving side:</p>
<pre class="brush: cpp;">
int ledPin = 11;                  // pin for the LED
int RFinPin = 7;                  // pin for the RF receiver
int val = 0;                      // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT);          // declare LED as output
pinMode(RFinPin, INPUT);          // declare RF receiver as input
}
void loop(){
 val = digitalRead(RFinPin);      // read input value
 if (val == HIGH) {               // check if the input is HIGH
    digitalWrite(ledPin, HIGH);   // turn LED ON
 } else {
  digitalWrite(ledPin, LOW);      // turn LED OFF
  }
}
</pre>
<p>Ok, maybe this example was a bit too easy.</p>
<p>Check <a title="Part 2" href="http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/" target="_self">part 2</a> to learn how to connect arduino to a network and send/receive data to/from a webpage using the ethernet shield discussed <a href="http://www.codetorment.com/2009/10/24/arduino-goodness-ethernet-shield/">here</a>.</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
