Saving data on Arduino Uno R3

I am using the Arduino Uno R3 without wifi or Bluetooth and I made a system that records the amount of time that a location receives sunlight. I was wondering if there is a way to make the Arduino save the data it has collected at the end of every day and then later access all of this data when I bring my Arduino inside and connect it to my computer.

#include <LiquidCrystal.h>
const int pin = A0;
int rawValue = 0;
int timer;
int minutes = 0;
int hours = 0;
int seconds = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int state = 0;
bool buttonPressed = false;
bool done = false;
int loopms=50
int count = 1000/loopms;
int oneTimeDelay = 3000;
void setup() { 
  // put your setup code here, to run once:
pinMode(6, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("STARTED");
lcd.setCursor(0, 1);
lcd.print("PRESS BUTTON");
}

void loop() {
  // put your main code here, to run repeatedly:
if(digitalRead(6) ==  HIGH){
  buttonPressed = true;
}
else{
  buttonPressed = false;
}
switch(state){
  case 0:
    original();
    break;
  case 1:
    highdetected();
    break;
  case 2:
    buttonPress();
    break;
  case 3:
  if(buttonPressed){
    state = 1;
    done = true;
  }
  else{
    count--;
    if (!count)
    {
      reader();
      count = 1000/loopms;
    }
  } 
  break;
  case 4:
    stopRead();
    break;
}
delay(loopms);
}
void original(){
if(buttonPressed){
  state = 1;
}
else{
  state = 0;
}
}
void highdetected(){
if(buttonPressed){
  state = 1;
}
else{
  state = 2;
}
}
void buttonPress(){
  if(done){
    state = 4;
  }
  else if(buttonPressed){
    state = 1;
  }
  else if(!buttonPressed){
    state = 3;
  }
}
void reader(){
  //run code
  rawValue = analogRead(pin);
  delay(5);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Reading: ");
  lcd.print(rawValue);
  lcd.setCursor(0, 1);
  lcd.print("SunTime: ");
  lcd.print(timer);
  delay(1000);
  if(rawValue >= 1005){
    timer += 1.0;
 }         
  //end reader code
}
void stopRead(){
  //print final results
  seconds = timer;
  minutes = seconds / 60;
  hours = minutes / 60;
  seconds = timer - (minutes * 60);
  minutes = minutes - (hours * 60);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Final Sun Time: ");
  lcd.setCursor(0, 1);
  lcd.print(hours);
  lcd.print("hrs ");
  lcd.print(minutes);
  lcd.print("mins ");
  lcd.print(seconds);
  lcd.print("s");
  delay(3000);

}

Yes, you can save the data collected by your Arduino Uno R3 and access it later when you connect it to your computer. One way to achieve this is by using an external storage device, such as an SD card module

How much data are we talking about? A small amount (1 kByte) can be stored in the internal EEPROM of the 328P microcontroller on the Uno. For bigger amounts you can consider an external EEPROM or FRAM module. And for BIG amounts you can consider the already mentioned SD card.

In theory you will probably on store the data when the sun goes down. So storing your calculated value only needs to be written once a day. You're working with 16 bit integers so you can store 500 values in internal EEPROM.

If you want to keep track of a date, I would suggest that you buy a RTC module; most of them come with an external EEPROM (e.g. 24C32, 4 kByte) giving you more space.

Comment on the code

timer is an integer, why would you add a float value to it?

Here is a logging weather station/alarm clock. It saves data every 15 minutes to SD card. Time/date, temperature, humidity, and barometric pressure with trend are all saved plus a daily summary.
You need three parts, weather module, SD, RTC. The display just is a bonus and can be omitted. You could basically clone my project, leaving out whatever. The code generally won't notice, except for the T/H/B module.


timer used to be a float but I just forgot to change the 1.0 when I made it an int

Need a semicolon at the end of this line:

int loopms=50;
1 Like

I use FRAM (Ferroresonant (ferroelectric) Random Access Memory), it can be gotten in 32K x 8 for a few dollars. It reads and writes like EEPROM without the associated delays. It is nonvolatile and will last over a billion cycles. With that you connect the USB and have it send the data to your computer.

Hello, can you please tell me how to connect the sd card and how to program it please if you don't mind.


Connections shown for Mega2560

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.