This is my first project with the arduino, and I know, I jumped right in. This is a pretty big project for a first. I feel like each small part is a hundred sub projects. It's not nearly complete, but I have a working partial version right now, and I figured I might as well put it out there, see if I get any feedback. My documentation is pretty sloppy, but I do put effort into documenting it, so you should be able to see what's going on pretty well. Again, very much a work in progress. At the moment it's fairly limited in capability, here's some stats:
3 outputs (ULN2003 to 12v relay to 110v relay): a water pump, artificial sunlight and a green LED worklight. (Green light does not interrupt the darkness requirement flowering photosensitive plants have)
2 analog inputs: temperature sensors, LM34DZ
2 digital inputs : regular momentary NO pushbuttons
Google Code Archive - Long-term storage for Google Code Project Hosting. <~~ More detailed info
#include "OutletTimer.h"
#include "DigitalInputter.h"
#include "PrintPJRClcd.h"/*Initialize outlets, OutletTimer(pinNumber, InitialMode, InitialTimeSec) */
OutletTimer MainLightOutletTimer(10,0,300);// Main light
OutletTimer MainVegPumpOutletTimer(9,1,60);//Water pumps
OutletTimer GreenWorkLightOutletTimer(8,4,0);//work lights/* Initialize digital inputs DigitalInputter(int pinNumber) */
DigitalInputter WorkLightButton(7);
DigitalInputter PumpToggleButton(6);/* Open LCD library on serial port */
PrintPJRClcd LCD = PrintPJRClcd();/* Initialize analog inputs */
int AnalogRezTemp = 0;
int AnalogAirTemp = 0;
#define AnalogRezTempPin 0
#define AnalogAirTempPin 1/* Variables for time watching */
unsigned long previousMillis = 0; // will store last time millis
unsigned long curMillis = 0;
int timeSinceLast = 0;/* floats for calculating time */
float MainLightTimeFloat;
unsigned char LoopsAround = 0;
void setup()
{/* Set outlet on and off times */
MainLightOutletTimer.OnDuration = 64800; //main lights, 64800 = 18 hours
MainLightOutletTimer.OffDuration = 21600; // 21600 = 6 hours
MainVegPumpOutletTimer.OnDuration = 60;//veg pump
MainVegPumpOutletTimer.OffDuration = 600;
GreenWorkLightOutletTimer.OnDuration = 0;
GreenWorkLightOutletTimer.OffDuration = 0;
Serial.begin(19200);
delay(1000);
LCD.RedrawScreen();}
void loop()
{/* Check inputs */
if (WorkLightButton.CheckPin()) // if work light button has been pushed
{
if (GreenWorkLightOutletTimer.CurrentMode==4) GreenWorkLightOutletTimer.ChangeMode(5); // if current mode is perm off, turn it perm on
else if (GreenWorkLightOutletTimer.CurrentMode==5) GreenWorkLightOutletTimer.ChangeMode(4);
};
if (PumpToggleButton.CheckPin()) //if pump button has been pushed
{
switch(MainVegPumpOutletTimer.CurrentMode) //what's the veg pump at now?
{
case 0: //off, normal operation
MainVegPumpOutletTimer.ChangeMode(1);
break;
case 1: //on, normal operation
MainVegPumpOutletTimer.ChangeMode(4);
break;
case 4: // perm off
MainVegPumpOutletTimer.ChangeMode(5);
break;
case 5: // perm on
MainVegPumpOutletTimer.ChangeMode(0);
break;
};
};/*measure time past since last loop and increment down */
curMillis = millis();
if (curMillis < previousMillis) previousMillis = 0.0; //roll over check
timeSinceLast = curMillis- previousMillis;
previousMillis = curMillis;/* Analog inputs */
AnalogRezTemp = analogRead(AnalogRezTempPin);
AnalogAirTemp = analogRead(AnalogAirTempPin);/* Print info to screen /
//LCD.RedrawScreen();
LCD.PrintData(0,int(AnalogAirTemp/2.1));
LCD.PrintData(1,int(AnalogRezTemp/2.1));
LCD.PrintData(2,MainVegPumpOutletTimer.CurrentMode);
LCD.PrintData(3,(MainVegPumpOutletTimer.TimeLeft/1000));
LCD.PrintData(4, MainLightOutletTimer.CurrentMode);
MainLightTimeFloat = ((long(MainLightOutletTimer.TimeLeft)/1000)/60);
LCD.PrintData(5, int(MainLightTimeFloat));
LCD.PrintData(6, GreenWorkLightOutletTimer.CurrentMode);
/ Pass Time Since Last loop to each outlet */MainLightOutletTimer.ElapseTime(timeSinceLast);
MainVegPumpOutletTimer.ElapseTime(timeSinceLast);
GreenWorkLightOutletTimer.ElapseTime(timeSinceLast);LoopsAround++;
if(LoopsAround==42) LCD.RedrawScreen();
}
/*
- A library for dealing with digital inputs * Created by MulletSoda, 2010
- With love!
*/#ifndef DigitalInputter_h
#define DigitalInputter_h#include "WProgram.h"
class DigitalInputter
{
public**:**
//public variables:
int PinNumber;
int _PinNumber;
unsigned long _currentTime;
unsigned long _deBounceTimeDone;
boolean _deBounce;
void DeBouncer();//public functions:
DigitalInputter(int _PinNumber);
boolean CheckPin();
private**:**
//private variables
//private functions
};#endif
#include "WProgram.h"
#include "DigitalInputter.h"DigitalInputter::DigitalInputter(int PinNumber)
{
//initialize
_PinNumber = PinNumber;
pinMode(_PinNumber, INPUT);
//digitalWrite(_PinNumber, HIGH);//turn on pull up resistor
_deBounceTimeDone = 0;
}boolean DigitalInputter::CheckPin()
{
_currentTime = millis(); //what is the current time?//debounce and check
if (!_deBounce) //if deBounce has not been activated
if (digitalRead(_PinNumber)==1){//read pin, if it returns activated then
{
_deBounce = true;
_deBounceTimeDone =500 + _currentTime; // <******************************************* Will this bypass the rollover problem????
//turn on debounce, set time over, return true
return true;
};
};
if (_deBounce) //if deBounce has been activated
{
if (_deBounceTimeDone <= _currentTime) _deBounce = false; //if enough time has passed
};
return false;
}void DigitalInputter::DeBouncer()
{
}