Another project that demonstrate how to build a low cost lake/pond water level logger sensor that can be deployed without an RF communication. however this project works as independent/standalone can be deployed on a remote area intended for science and environmental use suitable for school research studies.
This device can sustain up-to 8 to 12 months or you can attach a solar panel with intelligent charging controller to charge automatically when the battery reach to 10%, however as you can see the illustration below it is powered by 3.3v 2500 mAh lithium ion polymer battery. We assumed that you are familiar with the component which is used on this project. This project is driven by 5 main components, the ATMEGA328P Microcontroller, 4 level water sensing probe, RTC (Real Time Clock), and the microSD Card which is data will be stored.
Required Components
- Arduino IDE | Atmel Studio
- Microcontroller – Arduino NANO, MINI, MEGA, UNO, LEO, DUE, ZERO, 101, MKR1000, FIO, NodeMCU, Teensy Board, TeensyDuino, ESP8266 12, 12E, ESP32, LinkItOne, ESP8266 NodeMCU, ESPDuino, ATMEGA328 16/12, ATMEGA32u4 16/8/ MHz, ESP8266, ATMEGA250 16 MHz, ATSAM3x8E, ATSAM21D, ATTINY85 16/8 MHz Note: The Diagram below is using NANO. (please refer to each MCU’s respective pin-outs)
- RTC Chip or Module
- microSD Card (4~8 GB FAT)
- microSD Card Socket / microSD Module
- Transistors (See below diagram required values)
- Capacitors (See below diagram required values)
- Resistors (See below diagram required values)
- Galvanized Steel Wire/Rod (for sensor see below diagram required value)
- Solder Less Breadboard (Optional)
- Jumper Wire
- Prototyping Board
- PCB board (for testing)
Wiring Guide
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
#include <SdFat.h> #include <EEPROM.h> #include <PowerSaver.h> #include <DS3234lib3.h> char filename[15] = "corelog.csv"; PowerSaver chip; DS3234 myTime; SdFat sd; SdFile file; #define POWER 4 #define myTimePOWER 5 #define errorHandler 3 int microSDCSPin = 10; //microSDCSPin int LvlState1 = 0, LvlState2 = 0, LvlState3 = 0, LvlState4 = 0; ISR(PCINT0_vect) { asm("nop"); } /*SETUP*/ void setup() { Serial.begin(9600); pinMode(POWER, OUTPUT); pinMode(myTimePOWER, OUTPUT); pinMode(errorHandler, OUTPUT); digitalWrite(POWER, HIGH); digitalWrite(myTimePOWER, HIGH); delay(1); // ERROR HANDlER if(!sd.begin( microSDCSPin, SPI_FULL_SPEED)) { delay(10); sd.initErrorHalt(); } // ERROR HANDLER else { delay(10); file.open(filename, O_CREAT | O_APPEND | O_WRITE); delay(1); String time = myTime.timeStamp(); file.println(); file.print("Date/Time - Monitoring"); file.println(); PrintFileTimeStamp(); file.close(); digitalWrite(errorHandler, HIGH); delay(10); digitalWrite(errorHandler, LOW); } chip.sleepInterruptSetup(); } void loop() { digitalWrite(POWER, LOW); digitalWrite(myTimePOWER, LOW); delay(1); chip.turnOffADC(); chip.turnOffSPI(); //chip.turnOffWDT(); chip.turnOffBOD(); chip.goodNight(); chip.turnOnADC(); chip.turnOnSPI(); delay(1); digitalWrite(POWER, HIGH); digitalWrite(myTimePOWER, HIGH); delay(10); myTime.checkDST(); printToSD(); delay(2000); } /* Print Data to microSD */ void printToSD() { pinMode(microSDCSPin, OUTPUT); if(!sd.begin( microSDCSPin, SPI_FULL_SPEED)) { delay(10); sd.initErrorHalt(); } else { delay(10); file.open(filename, O_WRITE | O_AT_END); delay(1); String settime = myTime.timeStamp(); SPCR = 0; //SPI Registers LvlState1 = digitalRead(2); LvlState2 = digitalRead(5); LvlState3 = digitalRead(6); LvlState4 = digitalRead(7); if(LvlState1 == 1) { file.print("Level - 1"); file.print(settime); file.print(","); file.print("0"); file.println(); file.print(settime); file.print(","); file.print("1"); } else if(LvlState1 == 0) { file.print(settime); file.print(","); file.print("1"); file.println(); file.print(settime); file.print(","); file.print("0"); } if(LvlState2 == 1) { file.print("Level - 2"); file.print(settime); file.print(","); file.print("0"); file.println(); file.print(settime); file.print(","); file.print("1"); } else if(LvlState2 == 0) { file.print(settime); file.print(","); file.print("1"); file.println(); file.print(settime); file.print(","); file.print("0"); } if(LvlState3 == 1) { file.print("Level - 3"); file.print(settime); file.print(","); file.print("0"); file.println(); file.print(settime); file.print(","); file.print("1"); } else if(LvlState3 == 0) { file.print(settime); file.print(","); file.print("1"); file.println(); file.print(settime); file.print(","); file.print("0"); } if(LvlState4 == 1) { file.print("Level - 4"); file.print(settime); file.print(","); file.print("0"); file.println(); file.print(settime); file.print(","); file.print("1"); } else if(LvlState4 == 0) { file.print(settime); file.print(","); file.print("1"); file.println(); file.print(settime); file.print(","); file.print("0"); } file.println(); PrintFileTimeStamp(); file.close(); digitalWrite(errorHandler, 1); delay(10); digitalWrite(errorHandler, 0); } } /*Write time stamp function*/ void PrintFileTimeStamp() { file.timestamp(T_WRITE, myTime.year, myTime.month, myTime.day, myTime.hour, myTime.minute, myTime.second); file.timestamp(T_ACCESS, myTime.year, myTime.month, myTime.day, myTime.hour, myTime.minute, myTime.second); } // microSD Card Error Handler void SDcardError() { for(int i=0;i<3;i++) //ERROR { digitalWrite(errorHandler, HIGH); delay(50); digitalWrite(errorHandler, LOW); delay(150); } } |
Downloads
- Download PowerSaver Code Library
- Download SdFat Code Library
- Download DS3234 Code Library
- Download DS3234 Datasheet