Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions