Question
I have stumbled upon a problem while writing a code for my datalogger (based on arduino). So far I have a code that takes readings
I have stumbled upon a problem while writing a code for my datalogger (based on arduino). So far I have a code that takes readings from the sensor and stores them into a text file. However, it takes the readings every 2 seconds (maximum sampling rate of sensor). I would like to add 2 or 3 functions that would save the data every hour, 4 hours and or 6 hours with the push button as a select mechanism. This is what I have so far:
#include
DHT dht; //File myFile;
int chipSelect = 4; const int rs = 10, en = 9, d4 = 5, d5 = 6, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() { dht.setup(8); // data pin 8 lcd.begin(16, 2); pinMode(chipSelect, OUTPUT);
if (!SD.begin(chipSelect)) { lcd.setCursor(0, 0); lcd.print("CARD NOT"); lcd.setCursor(0, 1); lcd.print("INITIALIZED"); delay(4000); lcd.clear(); } else { lcd.setCursor(0, 0); lcd.print("CARD INITIALIZED"); delay(4000); lcd.clear();
lcd.setCursor(0, 0); lcd.print("Logging..."); delay(4000); lcd.clear(); } }
void loop() {
float humidity = dht.getHumidity(); float temperature = dht.getTemperature();
delay(dht.getMinimumSamplingPeriod());
File dataFile = SD.open("datalog.txt", FILE_WRITE); if (dataFile) { //dataFile.println(temperature); //dataFile.close(); } lcd.setCursor(0, 0); lcd.print("humidity"); lcd.setCursor(12, 0); lcd.print(humidity);
lcd.setCursor(0, 1); lcd.print("temperature "); lcd.setCursor(12, 1); lcd.print(temperature);
dataFile.println("Temperature :"); dataFile.println(temperature); dataFile.close(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started