<?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>Casa Nogal de las Brujas</title>
	<atom:link href="http://www.casanogaldelasbrujas.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.casanogaldelasbrujas.com/blog</link>
	<description>Una casa aislada en el Somontano</description>
	<lastBuildDate>Sun, 25 Mar 2012 07:59:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>And I was worried about the solar production when the fog rolled in</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/12/03/and-i-was-worried-about-the-solar-production-when-the-fog-rolled-in/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/12/03/and-i-was-worried-about-the-solar-production-when-the-fog-rolled-in/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 14:45:29 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=284</guid>
		<description><![CDATA[800W from a 2.8kW array in that weather]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/fog.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/fog-224x300.jpg" alt="" title="fog" width="224" height="300" class="aligncenter size-medium wp-image-290" /></a></p>
<p>800W from a 2.8kW array in that weather <img src='http://www.casanogaldelasbrujas.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/12/03/and-i-was-worried-about-the-solar-production-when-the-fog-rolled-in/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flooring and kitchen cabinets in</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/10/02/flooring-and-kitchen-cabinets-in/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/10/02/flooring-and-kitchen-cabinets-in/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 18:10:25 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Building]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/2011/10/02/flooring-and-kitchen-cabinets-in/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/10/20111002-200935.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/10/20111002-200935.jpg" alt="20111002-200935.jpg" class="alignnone size-full" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/10/20111002-201003.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/10/20111002-201003.jpg" alt="20111002-201003.jpg" class="alignnone size-full" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/10/20111002-201015.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/10/20111002-201015.jpg" alt="20111002-201015.jpg" class="alignnone size-full" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/10/02/flooring-and-kitchen-cabinets-in/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gas and laminate flooring installed</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/09/21/276/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/09/21/276/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 08:20:48 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Building]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=276</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/IMG_0077.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/IMG_0077-764x1024.jpg" alt="" title="IMG_0077" width="640" height="857" class="aligncenter size-large wp-image-277" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/IMG_0076.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/IMG_0076-764x1024.jpg" alt="" title="IMG_0076" width="640" height="857" class="aligncenter size-large wp-image-281" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/IMG_0078.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/09/IMG_0078-764x1024.jpg" alt="" title="IMG_0078" width="640" height="857" class="aligncenter size-large wp-image-278" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/09/21/276/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PV install done!</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/06/26/pv-install-done/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/06/26/pv-install-done/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 17:45:55 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Off grid power]]></category>
		<category><![CDATA[Solar power]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=265</guid>
		<description><![CDATA[The PV installation is finally completed and the battery have had their first taste of those juicy solar electrons. The tech details: 12 x Yingli 235W modules for 2.82kW of installed PV wired in 4 strings of 3 panels. 100Vmp &#8230; <a href="http://www.casanogaldelasbrujas.com/blog/2011/06/26/pv-install-done/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The PV installation is finally completed and the battery have had their first taste of those juicy solar electrons.<br />
The tech details:</p>
<ol>
<li>12 x Yingli 235W modules for 2.82kW of installed PV wired in 4 strings of 3 panels.  100Vmp for each string in summer.</li>
<li>Morningstar 60A MPPT charge controller</li>
<li>5 PzS 700 700Ah (C5) traction batteries from <a href="http://www.sunlight.gr/">Sunlight.gr</a></li>
<li>SMA Sunny Island 5048, 5kW inverter with a shunt installed so that its internal SoC can keep track of the energy coming in through the morningstar controller</li>
<li>5kW diesel generator from Volvox Engineering (rebadged Vidhata generator from India) with a Deapsea 3110 controller</li>
<li>Mounting structure custom made from aluminium tubing, 60x40x2mm.
</ol>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/solarview1.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/solarview1.jpg" alt="" title="solarview" width="640" height="425" class="aligncenter size-full wp-image-269" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/electrics.jpeg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/electrics.jpeg" alt="" title="electrics" width="640" height="425" class="aligncenter size-full wp-image-271" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/panelview.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/panelview.jpg" alt="" title="panelview" width="640" height="425" class="aligncenter size-full wp-image-272" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/panelsfrombehind.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/06/panelsfrombehind.jpg" alt="" title="panelsfrombehind" width="640" height="425" class="aligncenter size-full wp-image-273" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/06/26/pv-install-done/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Barley</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/04/15/barley/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/04/15/barley/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 06:21:35 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Land]]></category>
		<category><![CDATA[Plants]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=253</guid>
		<description><![CDATA[Hello my pretties]]></description>
			<content:encoded><![CDATA[<p>Hello my pretties</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/04/IMG00177-20110414-1922.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/04/IMG00177-20110414-1922-300x225.jpg" alt="" title="barley" width="300" height="225" class="aligncenter size-medium wp-image-255" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/04/15/barley/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Version 0.1 Battery Monitor</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 22:27:08 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Off grid power]]></category>
		<category><![CDATA[Solar power]]></category>
		<category><![CDATA[battery monitor]]></category>
		<category><![CDATA[Digital SG meter]]></category>
		<category><![CDATA[specific graphic meter]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=238</guid>
		<description><![CDATA[Basic features working well: Measuring SG and temp and calculating the SoC. Displaying on LCD and working over SMS.]]></description>
			<content:encoded><![CDATA[<p>Basic features working well: Measuring SG and temp and calculating the SoC.  Displaying on LCD and working over SMS.</p>

<a href='http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/p1150083/' title='P1150083'><img width="150" height="150" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/02/P1150083-150x150.jpg" class="attachment-thumbnail" alt="P1150083" title="P1150083" /></a>
<a href='http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/p1150082/' title='P1150082'><img width="150" height="150" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/02/P1150082-150x150.jpg" class="attachment-thumbnail" alt="P1150082" title="P1150082" /></a>
<a href='http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/p1150081/' title='P1150081'><img width="150" height="150" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/02/P1150081-150x150.jpg" class="attachment-thumbnail" alt="P1150081" title="P1150081" /></a>
<a href='http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/p1150080/' title='P1150080'><img width="150" height="150" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/02/P1150080-150x150.jpg" class="attachment-thumbnail" alt="P1150080" title="P1150080" /></a>
<a href='http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/p1150079/' title='P1150079'><img width="150" height="150" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/02/P1150079-150x150.jpg" class="attachment-thumbnail" alt="P1150079" title="P1150079" /></a>
<a href='http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/p1150078/' title='P1150078'><img width="150" height="150" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/02/P1150078-150x150.jpg" class="attachment-thumbnail" alt="P1150078" title="P1150078" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/02/20/version-0-1-battery-monitor/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SG data logger, first steps</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/01/31/sg-data-logger-first-steps/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/01/31/sg-data-logger-first-steps/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 19:40:19 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Off grid power]]></category>
		<category><![CDATA[Solar power]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=214</guid>
		<description><![CDATA[The helpful chaps at JSA Photonics sent over a replacement sensor and it&#8217;s working rather nicely. Have only run real tests using a single SG value as my battery doesn&#8217;t cycle much yet. Got the dimensions of the cell cap &#8230; <a href="http://www.casanogaldelasbrujas.com/blog/2011/01/31/sg-data-logger-first-steps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The helpful chaps at <a href="http://www.jsaphotonics.com/">JSA Photonics</a> sent over a replacement sensor and it&#8217;s working rather nicely.  Have only run real tests using a single SG value as my battery doesn&#8217;t cycle much yet.<br />
<a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/sensor-arduino.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/sensor-arduino-300x225.jpg" alt="" title="sensor-arduino" width="300" height="225" class="alignleft size-medium wp-image-215" /></a></p>
<p>Got the dimensions of the cell cap dimensiones slightly wrong when ordering so the sensor&#8217;s sitting a bit lower than it should be.<br />
<a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/sesnor-inbat.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/sesnor-inbat-300x225.jpg" alt="" title="sesnor-inbat" width="300" height="225" class="alignleft size-medium wp-image-216" /></a></p>
<p>The manual meter reads just below 1.26<br />
<a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/maual-reading.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/maual-reading-300x225.jpg" alt="" title="maual-reading" width="300" height="225" class="alignleft size-medium wp-image-217" /></a></p>
<p>And so does the sensor!  The Arduino AD converter is only 10 bit, which limits the accuracy of the readings, but anyway 2 decimal places is good enough for specific gravity.  Note that it has an integrated temperature sensor too.  The output reading is currently not temperature corrected.<br />
<a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-4.46.16-PM.png"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-4.46.16-PM-300x172.png" alt="" title="Screen shot 2011-01-30 at 4.46.16 PM" width="300" height="172" class="alignleft size-medium wp-image-218" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/01/31/sg-data-logger-first-steps/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SMA Sunny Island installed</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2011/01/31/sma-sunny-island-installed/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2011/01/31/sma-sunny-island-installed/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 19:25:04 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=208</guid>
		<description><![CDATA[Sunny Island 5048 hooked up to the generator and the 800Ah Forklift battery from Sunlight.gr.]]></description>
			<content:encoded><![CDATA[<p>Sunny Island 5048 hooked up to the generator and the 800Ah Forklift battery from Sunlight.gr.<br />
<a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/siandbatt.jpg"><img src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2011/01/siandbatt-300x199.jpg" alt="" title="SI and battery" width="300" height="199" class="alignleft size-medium wp-image-209" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2011/01/31/sma-sunny-island-installed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SMS generator control with Arduino</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2010/07/20/sms-generator-control-with-arduino/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2010/07/20/sms-generator-control-with-arduino/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 22:59:19 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Off grid power]]></category>
		<category><![CDATA[water]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=196</guid>
		<description><![CDATA[Arduino GPRS shield <a href="http://www.casanogaldelasbrujas.com/blog/2010/07/20/sms-generator-control-with-arduino/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Driving 20km every day just to turn the generator and water pump on was becoming a drag, so I built an arduino solution with a GPRS shield, relay board, current sensor and real time clock to be able to turn them on remotely and monitor error conditions.</p>
<p>During testing I must have put too much current through one of the Phidgets sensors caused it stopped working properly, would only close, but not open &#8211; so switched it out for a 10A solid state version.  Have been using the SMS command system for a week now without a hitch, basically I can start the generator, stop it, query it&#8217;s status and turn the timer on or off.  If the unit detects any error condition, it will immediately shut the generator off and send an SMS alert.</p>
<p>The unit also has a built in warm up and cool down time for the generator and uses the current sensor to detect if the well is dry, i.e. if well is dry, pump stops, so current sensors can detect this and the arduino will shut down the generator.  The current sensor will also detect if the generator didn&#8217;t come on or if the pump failed to turn on &#8211; or if the generator stopped when it should be running.  All result in an error SMS being sent.</p>
<p>Had to mount the Arduino on the ceiling as the antenna cable wasn&#8217;t long enough</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/07/P11308592.jpg"><img class="alignleft size-full wp-image-200" title="P1130859" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/07/P11308592.jpg" alt="" width="499" height="332" /></a></p>
<p>Relay box as close to the thick cabling as possible</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/07/P1130860.jpg"><img class="alignleft size-medium wp-image-203" title="P1130860" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/07/P1130860-199x300.jpg" alt="" width="199" height="300" /></a></p>
<p>Complete source code below, if anyone needs to rip bits out of it.  Note that you&#8217;ll need to change the phone number, and the password &#8220;1234&#8243;, this password has nothing to do with the sim card, it&#8217;s just a number I&#8217;ve picked so that only people who know it can send messages to the generator.</p>
<pre>

#include "Wire.h"
#include <WString.h>
#define DS1307_I2C_ADDRESS 0x68
#define maxLength 200
#define PHONE 11111111111

String inString = String(maxLength);
int HOUR = 21;
int MINUTE_START = 01;
int MINUTE_STOP = 55;
boolean DEBUG = false;
unsigned long starttime = 0;
const unsigned long OVERRUN_TIME = 2UL*60UL*60UL*1000UL;

const int GEN_START_PIN = 10;
const int LOAD_PIN = 11;
const int LED = 13;
int GEN_START_DELAY = 20000;
int GEN_STOP_DELAY = 20000;
const int RETRY_LIMIT = 3;
const int CURRENT_SENSOR_PIN = 2;
const double MINIMUM_LOAD = 0.2;
long WARMUP_DELAY = 60000;  

long LOAD_DELAY = 10000;
const int GPRSonModulePin = 2;
const double PUMP_LOAD = 4.0;
double load = 0.0;
boolean errorSent = false;
boolean stoppedInWindow = false;

boolean timerOn = true;

int genState = 0; //0 = off, 1=running
int pumpCommandState = 0;
int genCommandState = 0; //0 = stop, 1 = start

int error = 0;
char* errorMsg[] = {"No error","Pump failed to start","Generator failed to start","Generator failed to stop","Generator overrun","Generator still running after stop signal"};
char* msg = "";

void getSerialChars() {
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (inString.length() < maxLength) {
       inString.append(inChar);
    }
  }
}

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                   // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
          byte *minute,
          byte *hour,
          byte *dayOfWeek,
          byte *dayOfMonth,
          byte *month,
          byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() &#038; 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() &#038; 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void switchModule(){
  digitalWrite(GPRSonModulePin,HIGH);
  delay(2500);
  digitalWrite(GPRSonModulePin,LOW);
  delay(25000);
  if (DEBUG) {
    Serial.println("GPRS module turned on");
  }
}

boolean genInTimerWindow() {
    byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
    getDateDs1307(&#038;second, &#038;minute, &#038;hour, &#038;dayOfWeek, &#038;dayOfMonth, &#038;month, &#038;year);
    if (DEBUG) {
       Serial.print("Time: ");
       Serial.print(hour,DEC);
       Serial.print(":");
       Serial.println(minute,DEC);
    }
    if (hour != HOUR) {
      stoppedInWindow = false;
    }
    if ((hour == HOUR) &#038;&#038; (minute >= MINUTE_START) &#038;&#038; (minute <= MINUTE_STOP)) {
      return true;
    } else {
      return false;
    }
}

void startGen() {
  if (DEBUG) {
     Serial.println("Starting gen");
  }
  digitalWrite(GEN_START_PIN, HIGH);
  genState = 1;
}

void stopGen() {
  if (DEBUG) {
     Serial.println("Stopping gen");
  }
  digitalWrite(GEN_START_PIN, LOW);
  genState = 0;
}

void connectLoad() {
   if (DEBUG) {
      Serial.println("Connecting load");
   }
   digitalWrite(LOAD_PIN, HIGH);
}

void disconnectLoad() {
   digitalWrite(LOAD_PIN, LOW);
   if (DEBUG) {
      Serial.println("Disconnecting load");
   }
}

double readLoad() {
  int load = analogRead(CURRENT_SENSOR_PIN);
  return (((double)load)*25.0/1023.0);
}

void deleteAllMsgs() {
  delay(1500);
  Serial.println("AT+CMGD=0,4");
  delay(4000);
}

int smsCommand() {
  int retval=0;
  delay(1500);
  Serial.print("AT+CMGL=");
  Serial.print(34,BYTE);
  Serial.print("REC UNREAD");
  Serial.println(34,BYTE);
  delay(3000);

  if (Serial.available() > 0) {
    inString = "";
    delay(500);
    getSerialChars();
    if (inString.contains("1234#")) {
      String command = String(20);
      command = inString.substring(inString.indexOf('#')+1,inString.length());
      if (command.contains("start")) retval = 1;
      if (command.contains("stop")) retval = 2;
      if (command.contains("clear")) retval = 3;
      if (command.contains("status")) retval = 4;
      if (command.contains("timer on")) retval = 5;
      if (command.contains("timer off")) retval = 6;
      if (retval != 0) deleteAllMsgs();
    }
  }

  return retval;
}

void sendSMSpreamble() {
    delay(1500);
    Serial.print("AT+CMGS=");
    Serial.print(34,BYTE);
    Serial.print(PHONE);
    Serial.println(34,BYTE);
    delay(1500);
}

void sendSMSappend() {
    delay(500);
    Serial.print(0x1A,BYTE);                // end of message command 1A (hex)
    delay(5000);
}

void sendErrorSMS() {
    sendSMSpreamble();
    Serial.print("Error: ");
    Serial.print(errorMsg[error]);
    writeStatus();
    sendSMSappend();
}  

void sendStopSMS() {
    sendSMSpreamble();
    writeStatus();
    sendSMSappend();
}

void writeStatus() {
    load = readLoad();
    Serial.println(msg);
    Serial.print("L: ");
    Serial.println(load);
    Serial.print("Gen: ");
    Serial.println(genState);
    Serial.print("Runtime: ");
    Serial.print((millis()-starttime)/60000UL);
    Serial.println(" min");
    Serial.print("Timer: ");
    if (timerOn) {
      Serial.print(HOUR);
      Serial.print(":");
      Serial.print(MINUTE_START);
      Serial.print(" - ");
      Serial.println(MINUTE_STOP);
    } else {
      Serial.println("Off");
    }
}    

void sendStatusSMS() {
  sendSMSpreamble();
  writeStatus();
  sendSMSappend();
}

void raiseError() {
  stopGen();
  sendErrorSMS();
}

void genStartSequence() {
  if (DEBUG) {
     Serial.println("Gen start sequence");
  }
  disconnectLoad();
  startGen();
  delay(GEN_START_DELAY);
  load = readLoad();
  if (DEBUG) {
      Serial.println(load);
  }
  if (load >= MINIMUM_LOAD) {
        starttime = millis();
        delay(WARMUP_DELAY);
        connectLoad();
        delay(LOAD_DELAY);
        load = readLoad();
        if (load > PUMP_LOAD) {
          if (DEBUG) {
              Serial.print("Pump came on");
          }
        } else {
          error = 1;
          if (DEBUG) {
            Serial.print(load);
            Serial.println(" was less than the pump load.");
          }
        }
   } else {
       error = 2;

       if (DEBUG) {
          Serial.print(load);
          Serial.println(" was less than the minimum load.");
        }

   }
}

void genStopSequence() {
  if (DEBUG) {
     Serial.println("Gen stop sequence");
  }
  disconnectLoad();
  delay(WARMUP_DELAY);
  stopGen();
  delay(GEN_STOP_DELAY);
  load = readLoad();
  if (load >= MINIMUM_LOAD) {
    error = 3;

  } else {
    sendStopSMS();
  }
}

void blinkLED() {
  digitalWrite(LED,HIGH);
  delay(1000);
  digitalWrite(LED,LOW);
}

void setup() {
  Serial.begin(19200);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  pinMode(GEN_START_PIN, OUTPUT);
  digitalWrite(GEN_START_PIN, LOW);
  pinMode(LOAD_PIN, OUTPUT);
  digitalWrite(LOAD_PIN, LOW);  

  Wire.begin();
  delay(5000);

  starttime = 0UL;
  switchModule();                    // swith the module ON
  Serial.println("AT+CMGF=1");      

  if (DEBUG) {
    //byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
    //getDateDs1307(&#038;second, &#038;minute, &#038;hour, &#038;dayOfWeek, &#038;dayOfMonth, &#038;month, &#038;year);
    //HOUR = hour;
    //MINUTE_START = minute;
    //MINUTE_STOP = MINUTE_START+1;
    WARMUP_DELAY=1000;
    LOAD_DELAY = 1000;

    GEN_START_DELAY = 2000;
    GEN_STOP_DELAY = 2000;
  }
  msg = "Module turned on.";
  //sendStatusSMS();
  msg = "";
  digitalWrite(LED, LOW);
}

void loop() {

  switch (smsCommand()) {
      case 1:
        genCommandState = 1;
        error = 0;
        timerOn = false;
        break;
      case 2:
        genCommandState = 0;
        stoppedInWindow = true;
        msg = "Stop signal from SMS";
        break;
      case 3:
        error = 0;
        break;
      case 4:
        msg = "";
        sendStatusSMS();
        break;
      case 5:
        timerOn = true;
        sendStatusSMS();
        break;
      case 6:
        timerOn = false;
        sendStatusSMS();
        break;
  }

 if (error == 0) {
    errorSent = false;

    if (genState == 0) {
       starttime = 0UL;
       if ((timerOn) &#038;&#038; (genInTimerWindow()) &#038;&#038; (!stoppedInWindow)) {
          if (DEBUG) {
            Serial.println("In time window");
          }
          genCommandState = 1;
       }
       if (genCommandState == 1) {
          genStartSequence();
       }
    } else {
       if ((timerOn) &#038;&#038; !genInTimerWindow()) {
          genCommandState = 0;
          msg = "Stopped by timer";
       }
       if (readLoad() < PUMP_LOAD) {
          msg = "Stop signal from pump";
          if (DEBUG) {
            Serial.println(msg);
          }
          genCommandState = 0;
          stoppedInWindow = true;
       }
       unsigned long time = millis();
       if ((time - starttime) > OVERRUN_TIME) {
         error = 4;
       }
       if (genCommandState == 0) {
         genStopSequence();
       }
    }
 } else {
    if (!errorSent) {
      raiseError();
      errorSent = true;
    }
 }
 delay(2000);
 blinkLED();

 if (DEBUG) {
   Serial.print("gen state=");
   Serial.print(genState);
   Serial.print(" Load=");
   Serial.println(readLoad());
 }  

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2010/07/20/sms-generator-control-with-arduino/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Exhaust silencer version 2.0</title>
		<link>http://www.casanogaldelasbrujas.com/blog/2010/01/26/exhaust-silencer-version-2-0/</link>
		<comments>http://www.casanogaldelasbrujas.com/blog/2010/01/26/exhaust-silencer-version-2-0/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 19:18:47 +0000</pubDate>
		<dc:creator>stephen</dc:creator>
				<category><![CDATA[Off grid power]]></category>

		<guid isPermaLink="false">http://www.casanogaldelasbrujas.com/blog/?p=184</guid>
		<description><![CDATA[Going to make the expansion chamber smaller, so that it&#8217;s deeper underground, then funnel the gases through a maze made out of blocks filled with sand.  There&#8217;s a big hole filled with builders sand that forms the center of this &#8230; <a href="http://www.casanogaldelasbrujas.com/blog/2010/01/26/exhaust-silencer-version-2-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Going to make the expansion chamber smaller, so that it&#8217;s deeper underground, then funnel the gases through a maze made out of blocks filled with sand.  There&#8217;s a big hole filled with builders sand that forms the center of this structure, with any luck the sand and the irregular direction of the baffled blocks <strong>and</strong> the fact that it&#8217;s all underground will make this super silent.</p>
<p>Perimeter foundations with sandy center:</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00180-20100126-0809.jpg"><img class="alignnone size-medium wp-image-185" title="IMG00180-20100126-0809" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00180-20100126-0809-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>And a maze of baffles including one at an odd angle to break the sound and try and reduce echoes.  The gap between the blocks is always about three times the size of the surface area of the existing exhaust pipe, so shouldn&#8217;t have a problem with back-pressure on the engine.</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00181-20100126-0909.jpg"><img class="alignnone size-medium wp-image-186" title="IMG00181-20100126-0909" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00181-20100126-0909-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>After waiting for the cement to dry, I filled the holes up with sand, leaving a gap towards the top for the concrete to fill:</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00183-20100128-0923.jpg"><img class="alignleft size-medium wp-image-188" title="IMG00183-20100128-0923" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00183-20100128-0923-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Used wooden blanks to form the roof and laid some mesh over it to add some strength to the croncrete</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00184-20100128-1005.jpg"><img class="alignleft size-medium wp-image-190" title="IMG00184-20100128-1005" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00184-20100128-1005-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>&#8230;and covered it all in concrete</p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00185-20100128-1032.jpg"><img class="alignleft size-medium wp-image-191" title="IMG00185-20100128-1032" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00185-20100128-1032-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00186-20100128-1032.jpg"><img title="IMG00186-20100128-1032" src="http://www.casanogaldelasbrujas.com/blog/wp-content/uploads/2010/01/IMG00186-20100128-1032-300x225.jpg" alt="" width="300" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.casanogaldelasbrujas.com/blog/2010/01/26/exhaust-silencer-version-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

