Storing Data in Arduino – Basic

Posted on March 9, 2011

This is an untested code, but it should work in providing you with basic knowledge on how to store data on the arduino. The source file will be uploaded at a later data, and hope this should give you a basic idea of how you can store and access data through programming. A more in detail explanation of this process may be provided if required, contact me. But the code is quite self explanatory. And sorry about the bad formatting, may be best to get the source file found on the Drop Box link below:


* This Function considers input data being from push button *

* This Code stores 3 values in any memory location and can later be accessed *

* Written By: Felin00b 03/09/11 *


int storageA, storageB, storageC; //These are the storage spaces, you could add N number of storage elements taking

//into account maximum memory available on the Arduino

int anyData, inputData, i=0; //This would be any data you want saved, say from a sensor or whatever i is simply random constant

void setup() {

Serial.begin(115200); //Change this Baud rate to whichever you prefer

pinMode(anyData, INPUT);


void loop() {

// read the state of a push button or sensor

inputData = digitalRead(anyData);

// check if the pushbutton or other data from sensor is detected.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH)


// Count the number of times the button is pushed and store every 5th data starting storageA through C and repeat

i++; //increment i, basically count the number of times it is pushed



storageA = i; //store the value of i in memory location A and it will not come out of there until you change it


else if (i=10)


storageB = i;


else if (i = 15)


storageC = i;


else if (i>16)

{//Now display all that was stored.

Serial.print(storageA, DEC); Serial.print(” value in storegeA memory “); Serial.println();

Serial.print(storageB, DEC); Serial.print(” value in storegeB memory “); Serial.println();

Serial.print(storageC, DEC); Serial.print(” value in storegeC memory “); Serial.println();