NodeMCU with SD card and moisture sensor.


This is simple project using a NODEMCU and a couple of sensors. It is extension of my previous project where, I observed internet connection issues and moisture sensor electrode damage after some time. This time we will connect a SD CARD shield to log moisture data and battery status with customer made moisture sensor electrode. The data will be saved as a csv file, this means you can quite easily open in Microsoft Excel without any conversion.




Basic Feature,
1) Integration of the SD card module to store data
2) Upgraded electrode with stainless steel material. (custom made)

Basics you need to know,
1) NodeMCU with Arduino IDE
2) Hardware
Moisture sensor
b Battery  
c Breadboard 
 3)  SD card module


Hardware design:
Basic connection with NodeMCU.
1) Connect reset pin with D0, It will reset NodMCU after deepsleep timer.
2) Analog reading connection with A0 pin in NODEMCU.



Code:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
const int chipSelect = D8;
const int analogInPin = A0;
File myFile;
int i;
const int sleepTimeS = 600; // Deep sleep time 10 minutes 60*10

int address = 120; // EEPROM stored data location it can be inbetween 0-511 
byte value;
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
   EEPROM.begin(512);
   i = EEPROM.read(address);
  if (!SD.begin(chipSelect)) 
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}
void loop()
{
  delay(000);
  myFile = SD.open("blogger.csv", FILE_WRITE);      
  float h = analogRead(analogInPin);

  if (isnan(h)) 
  {
    Serial.println("Failed to read from sensor!");
    return;
  }
  // if the file opened okay, write to it:
  if (myFile) 
  {
    Serial.print("opened csv file...");
    myFile.print(i);
    myFile.print(",");
    myFile.println(h);
    // close the file:
    myFile.close();
    i=i+1; // To conunt total number of data and reset inbetween
    EEPROM.write(address, i);
    EEPROM.commit();
    Serial.println("closed csv file");
    
    Serial.println(h);
    Serial.println(i);
    
  } 
  else 
  {
    // if the file didn't open, print an error:
    Serial.println("error opening csv file ");
  }
  ESP.deepSleep(sleepTimeS * 1000000);
}
-------------------------------------------------------------------------------------------------------------------------

Final setup

SD card data imported in excel sheet with graph for further analysis.


Comments

Popular Posts