h1

JeeNodes Update

December 7, 2014

Last year for Christmas I gave my sister a green house monitor made out of 2 JeeNodes and LCD screen and some leds.  See the post  about it here.   Basically a JeeNode is a small Arduino with a radio added.JeeNode v6 -2

I works great, but the battery life on the JeeNode in the greenhouse didn’t last long.  Reportedly it lasted 2 to 3 days. This year I’m giving it an upgrade or version 2.0.  I have added 2 parts from Adafruit.   First is this solar charger piece, and second is this solar panel.  We already had this 2500 mAh battery.

Last year I couldn’t quite get the code to sleep properly. Now I have updated the JeeNode in the greenhouse to sleep, almost a minute at a time.  This should extend the battery life greatly, hopefully at least a month at a time.  See the code below if you are interested.

Transmitter

// http://jeelabs.net/
//http://opensource.org/licenses/mit-license.php
//12/4/14 Todd Miller GreenhouseTX9

#include <JeeLib.h>
#include <avr/sleep.h>
Port tmp (2);
int value;
int valueTemp;
int prevTemp;
int radioIsOn=1;
byte x = 0;
MilliTimer readoutTimer, aliveTimer;

ISR(WDT_vect){Sleepy::watchdogEvent();} // must include when using Sleepy class.

void setup() {
tmp.mode2(INPUT);
rf12_initialize(1, RF12_433MHZ, 177);
rf12_easyInit(15); // every 10 seconds send out pkg
Serial.begin(57600);
Serial.println(F(“Greenhouse TX 9”));
delay(5);//wait for power to settle
}

void loop() {
Serial.flush();
delay(2);
if (x !=0) {
Sleepy::loseSomeTime(55000);
}
x=1;
valueTemp=0;
calcTemp();
byte sending = rf12_easySend(&valueTemp, sizeof value);

if (sending){
Serial.print(F(“Header = “));
Serial.print((int) rf12_hdr);
Serial.print(F(” Temp: “));
Serial.print(rf12_data[0]);
Serial.println(F(” F”));
Serial.println(F(” ———“));
}

if (aliveTimer.poll(60000)){
sending = rf12_easySend(0, 0); // always returns 1
Serial.println(F(“Sending ‘Alive’ Message”));
}
if (sending) {
// make sure the radio is on again
if (!radioIsOn)
rf12_sleep(-1); // turn the radio back on
radioIsOn = 1;
}
if (radioIsOn && rf12_easyPoll() == 0) {
rf12_sleep(0); // turn the radio off
radioIsOn = 0;
}
}

void calcTemp(){
for (int i=0; i <3; i++){
valueTemp = valueTemp + tmp.anaRead();
delay(2);
}
valueTemp = (valueTemp/3);
float voltage = valueTemp * 3.3;
voltage /= 1024.0;
float temperatureC = (voltage – 0.5) * 100 ;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
valueTemp=temperatureF;
Serial.print(F(“Temp = “));
Serial.println(valueTemp);
if(valueTemp>=120)
valueTemp=prevTemp;
prevTemp=valueTemp;
}

Receiver

// http://jeelabs.net/
// http://opensource.org/licenses/mit-license.php
// digiRead() & digiWrite() – ports D pin
// anaRead() & digiWrite2() – Ports A pin
// mode sets Digital pin mode2 sets ports Analog pin
// 11/21/13 Todd Miller Greenhouse RX9
// Updated 10/29/14 added solar panel / batter charger to greenhouse sensor as battery life was too short.
// 11/30/14 Config and resolder some loose wires RX 11

#include <JeeLib.h>
#include <PortsLCD.h>
#include <avr/sleep.h>

Port ledOne (1); // green – red led wire to pin 5 ? on all ports for all leds  green also works on pin 2?
Port ledTwo (2); // yellow
Port ledThree (3); // red
PortI2C myI2C (4);
LiquidCrystalI2C lcd (myI2C);
int temp;
int data;
byte y =0;
byte r = 0;
byte threshold= 34;
int backlightSwitch;
int tmpHigh;
int tmpLow;
byte tmp=0;
int pkg1=0;
int pkg2=0;
int pkg3=0;
int yCount = 0;
unsigned long interval = 120000;
unsigned long previousMillis;

void setup () {
lcd.begin(20, 4);
lcd.backlight();
homeScreen();
ledOne.mode(OUTPUT);
ledTwo.mode(INPUT); // digital pin for backlight switch
ledTwo.digiWrite(1);      // turn on pullup resistors
ledTwo.mode2(OUTPUT); // analog pin for led
ledThree.mode(OUTPUT);
rf12_initialize(‘R’, RF12_433MHZ, 177);
startupLights();
Serial.begin(9600);
Serial.print(F(“Greenhouse RX 2.0 11 12/2014”));
lcd.backlight();
}

void loop () {
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
unsigned long currentMillis = millis();
backlightSwitch=ledTwo.digiRead();
if (backlightSwitch == LOW){
lcd.noBacklight();
}
else
lcd.backlight();

if (currentMillis-previousMillis >interval)
yellowLed();

if (rf12_recvDone() && rf12_crc == 0) {
previousMillis=currentMillis;

if (tmp==0)
{
tmp=1;
tmpLow=rf12_data[0];
tmpHigh=rf12_data[0];
}
int* data = (int*) rf12_data;
pkg1++;
if (pkg1>999){
pkg1=0;
pkg2++;
if(pkg2>999){
pkg2=0;
pkg3++;
}
}

if(rf12_data[0] <tmpLow)
tmpLow=rf12_data[0];

if(rf12_data[0] >tmpHigh)
tmpHigh=rf12_data[0];

if(rf12_data[0]<=threshold)
{
redLed();
}
// process data here

else {
greenLed();
lcd.setCursor(14, 2);
lcd.print(rf12_data[0]);
lcd.setCursor(6, 3);
lcd.print(tmpHigh);
lcd.setCursor(15, 3);
lcd.print(tmpLow);
}

if (RF12_WANTS_ACK)
rf12_sendStart(RF12_ACK_REPLY,0,0);
}
}

void greenLed()
{
ledOne.digiWrite(1);
ledTwo.digiWrite2(0);
ledThree.digiWrite(0);

if (y==1 || r==1){
homeScreen();
y=0;
r=0;
}
}

void yellowLed()
{
ledOne.digiWrite(0);
ledTwo.digiWrite2(1);
ledThree.digiWrite(0);
yCount++;

if(y==0 || r==1)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F(“Check sensor!”));
lcd.setCursor(0, 1);
lcd.print(F(“Battery may need”));
lcd.setCursor(0, 2);
lcd.print(F(“recharging.”));
y=1;
r=0;
}

void redLed()
{
ledOne.digiWrite(0);
ledTwo.digiWrite2(0);
ledThree.digiWrite(1);

if(r==0 || y==1)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F(“Check greenhouse!”));
lcd.setCursor(0, 1);
lcd.print(F(“Current Temp:”));
lcd.setCursor(14, 1);
lcd.print(rf12_data[0]);
lcd.setCursor(17, 1);
lcd.print(F(“F”));
r=1;
y=0;
}

void homeScreen()
{
lcd.clear();
lcd.print(F(“Snowdrift Farms”));
lcd.setCursor(0, 1);
lcd.print(F(“Greenhouse Monitor”));
lcd.setCursor(0, 2);
lcd.print(F(“Current Temp: “));
lcd.setCursor(0, 3);
lcd.print(F(“High:”));
lcd.setCursor(10, 3);
lcd.print(F(“Low:”));
}

void startupLights(){
for(int i=0;i<=1;i++){
ledOne.digiWrite(1);
ledTwo.digiWrite2(0);
ledThree.digiWrite(0);
delay(300);
ledOne.digiWrite(0);
ledTwo.digiWrite2(1);
ledThree.digiWrite(0);
delay(300);
ledOne.digiWrite(0);
ledTwo.digiWrite2(0);
ledThree.digiWrite(1);
delay(300);
}
ledOne.digiWrite(1);
ledTwo.digiWrite2(0);
ledThree.digiWrite(0);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: