Permalink
Browse files

Add water TX & RX

  • Loading branch information...
1 parent 5951cc0 commit 6df18996fbc4ac1fb688523e69f28ffa4575a184 @nathanchantrell committed Aug 2, 2012
Showing with 201 additions and 4 deletions.
  1. +17 −4 README
  2. +96 −0 TinyTX_Water/TinyTX_Water.ino
  3. +88 −0 TinyTX_Water_RX/TinyTX_Water_RX.ino
View
21 README
@@ -3,8 +3,7 @@ TinyTX - An ATtiny84 and RFM12B wireless sensor node
By Nathan Chantrell. For hardware design see http://nathan.chantrell.net/tinytx
-Licenced under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence:
-http://creativecommons.org/licenses/by-sa/3.0/
+Licenced under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence: http://creativecommons.org/licenses/by-sa/3.0/
TinyTX_DS18B20
@@ -28,13 +27,27 @@ With LDR to read LED pulses on electricity meter.
TinyTX_LDR
-----------------
+----------
With LDR to read light levels.
+TinyTX_Water
+------------
+A leak/flood sensor using the TinyTX, a 100K resistor and two wire probes. See below for a receiver.
+
+
+TinyTX_Water_RX
+---------------
+Receiver example for the above leak/flood sensor, can be run on a Tiny TX and brings D9 high on a water alarm and D10 high on a low battery alarm. Could be used to trigger an external device, sound a buzzer etc. Same code could also be used on a Nanode/WiNode etc.
+
+
TinyTX_RX_Simple
----------------
-A simple receive example, outputing received data on the serial monitor.
+A simple receive example, outputing received data on the serial monitor.
+
+
+TinyTX_NanodeRF_emoncms
+-----------------------
For a Nanode sketch to upload to emoncms see: https://github.com/nathanchantrell/NanodeRF_emoncms
@@ -0,0 +1,96 @@
+//----------------------------------------------------------------------------------------------------------------------
+// TinyTX_Water - An ATtiny84 and RFM12B Leak/Flood sensor
+// By Nathan Chantrell. For hardware design see http://nathan.chantrell.net/tinytx
+//
+// Wire probes on A0 (ATtiny pin 13) and ground and 100K between A0 and D9 (ATtiny pin 12)
+// See TinyTX_Water_RX for a receiver example
+//
+// Licenced under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence:
+// http://creativecommons.org/licenses/by-sa/3.0/
+//
+// Requires Arduino IDE with arduino-tiny core: http://code.google.com/p/arduino-tiny/
+//----------------------------------------------------------------------------------------------------------------------
+
+#include <JeeLib.h> // https://github.com/jcw/jeelib
+
+ISR(WDT_vect) { Sleepy::watchdogEvent(); } // interrupt handler for JeeLabs Sleepy power saving
+
+#define myNodeID 1 // RF12 node ID in the range 1-30
+#define network 210 // RF12 Network group
+#define freq RF12_433MHZ // Frequency of RFM12B module
+
+int CAL = 400; // Analogue reading below which will trigger a tx
+
+//########################################################################################################################
+//Data Structure to be sent
+//########################################################################################################################
+
+ typedef struct {
+ int alarm; // alarm status
+ int supplyV; // Supply voltage
+ } Payload;
+
+ Payload tinytx;
+
+//########################################################################################################################
+
+void setup() {
+
+ rf12_initialize(myNodeID,freq,network); // Initialize RFM12 with settings defined above
+ rf12_sleep(0); // Put the RFM12 to sleep
+
+ pinMode(9, OUTPUT); // set D9 to output
+
+}
+
+void loop() {
+
+ digitalWrite(9, HIGH); // set D9 high
+ delay(10);
+ int reading = analogRead(0);
+ digitalWrite(9, LOW); // set D9 low
+
+ tinytx.supplyV = readVcc(); // Get supply voltage
+
+ if (reading < CAL){ // water detected
+ tinytx.alarm = 999; // set the alarm message
+ rfwrite(); // Send data via RF
+ }
+
+ if (tinytx.supplyV < 2500){ // low battery
+ tinytx.alarm = 100; // set the alarm message
+ rfwrite(); // Send data via RF
+ }
+
+ Sleepy::loseSomeTime(30000); //JeeLabs power save function: enter low power mode for 30 seconds (valid range 16-65000 ms)
+
+}
+
+//--------------------------------------------------------------------------------------------------
+// Send payload data via RF
+//--------------------------------------------------------------------------------------------------
+ static void rfwrite(){
+ rf12_sleep(-1); //wake up RF module
+ while (!rf12_canSend())
+ rf12_recvDone();
+ rf12_sendStart(0, &tinytx, sizeof tinytx);
+ rf12_sendWait(2); //wait for RF to finish sending while in standby mode
+ rf12_sleep(0); //put RF module to sleep
+}
+
+//--------------------------------------------------------------------------------------------------
+// Read current supply voltage
+//--------------------------------------------------------------------------------------------------
+ long readVcc() {
+ long result;
+ // Read 1.1V reference against Vcc
+ ADMUX = _BV(MUX5) | _BV(MUX0);
+ delay(2); // Wait for Vref to settle
+ ADCSRA |= _BV(ADSC); // Convert
+ while (bit_is_set(ADCSRA,ADSC));
+ result = ADCL;
+ result |= ADCH<<8;
+ result = 1126400L / result; // Back-calculate Vcc in mV
+ return result;
+}
+
@@ -0,0 +1,88 @@
+//----------------------------------------------------------------------------------------------------------------------
+// TinyTX Water Sensor Receiver Example
+// By Nathan Chantrell.
+//
+// Using the TinyTX as a receiver for the TinyTX_Water Sensor
+// Could also run on a Nanode/WiNode etc
+// Brings D9 high for 5 sec on receipt of water alarm and D10 high on low battery
+//
+// Licenced under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence:
+// http://creativecommons.org/licenses/by-sa/3.0/
+//----------------------------------------------------------------------------------------------------------------------
+
+//#define DEBUG //uncomment enable serial printing
+
+#include <JeeLib.h> // https://github.com/jcw/jeelib
+
+// Fixed RF12 settings
+#define MYNODE 30 //node ID of the receiever
+#define freq RF12_433MHZ //frequency
+#define group 210 //network group
+#define tinyTXNode 1 // node ID of the tinyTX to watch
+
+ typedef struct {
+ int rxD; // sensor value
+ int supplyV; // tx voltage
+ } Payload;
+ Payload rx;
+
+ int nodeID; //node ID of tx, extracted from RF datapacket. Not transmitted as part of structure
+
+void setup () {
+
+ #ifdef DEBUG
+ Serial.begin(9600);
+ #endif
+
+ rf12_initialize(MYNODE, freq,group); // Initialise the RFM12B
+
+ pinMode(9, OUTPUT); // set D9 to output
+ pinMode(10, OUTPUT); // set D10 to output
+
+ #ifdef DEBUG
+ Serial.println("TinyTX Water Sensor Receiver");
+ Serial.println("----------------------------");
+ Serial.println("Waiting for an alarm");
+ Serial.println(" ");
+ #endif
+
+}
+
+void loop() {
+
+ if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) {
+ nodeID = rf12_hdr & 0x1F; // get node ID
+
+ if (nodeID == tinyTXNode) {
+ rx = *(Payload*) rf12_data;
+ int alarm = rx.rxD;
+ int millivolts = rx.supplyV;
+
+ #ifdef DEBUG
+ Serial.print("Received an alarm from Node: ");
+ Serial.println(nodeID);
+ #endif
+ if (alarm == 999) {
+ digitalWrite(9, HIGH); // set D9 high
+ #ifdef DEBUG
+ Serial.println("Water detected!");
+ #endif
+ } else if (alarm == 100) {
+ digitalWrite(10, HIGH); // set D10 high
+ #ifdef DEBUG
+ Serial.println("Battery Low!");
+ #endif
+ }
+ #ifdef DEBUG
+ Serial.print("TX Millivolts: ");
+ Serial.println(millivolts);
+ Serial.println("--------------------");
+ #endif
+ delay(5000); // reset outputs after 5000ms
+ digitalWrite(9, LOW); // set D9 low
+ digitalWrite(10, LOW); // set D10 low
+ }
+
+ }
+
+}

0 comments on commit 6df1899

Please sign in to comment.