Creating an Accessible Sensor Info Storage System

I am trying to write a program that reads the data from multiple sensors and puts the values into an array, and then compares the "pattern"of the values in that array to a group of pre-programmed pattern possibilities and searches for a match. I am relatively new to Arduino and can't figure out how to pull off the storage and comparison of the pattern possibilities.

Thanks in advance!

Most accessible would be to put the data on an SD card. You can make or buy an SD adapter pretty cheap. SD will give you enormous capacity compared to on-chip memory of most any Arduino, it is the #1 way to log mass data on Arduinos -- the card can be read by a PC or tablet/phone with SD slot.

Without the SD, you can store a good bit of constant (no change) data in flash memory and your captured data in RAM and compare the two.

How many bytes of pre-programmed and read data you need to keep will affect what choices you have.

If your data is all ON/OFF then store and compare it as packed bits in unsigned integers.

Aha, so if I used an SD card how would I program the Arduino to search through it to attempt to find a match fro the values currently being read? The sensor consists of 6 smaller sensors, and the data is received into an array of the six sensor values (ON/OFF). I would like the Arduino to then compare those 6 values to the stored possible patterns (approximately 10 or so such possibilities), and alert me if the current sensor readings match any of the possibilities. Thanks for your help

jackmav:
Aha, so if I used an SD card how would I program the Arduino to search through it to attempt to find a match fro the values currently being read? The sensor consists of 6 smaller sensors, and the data is received into an array of the six sensor values (ON/OFF). I would like the Arduino to then compare those 6 values to the stored possible patterns (approximately 10 or so such possibilities), and alert me if the current sensor readings match any of the possibilities. Thanks for your help

Sounds like a series of if statements to me. Be sure to read up on the boolean operators || and && (OR and AND) before you get started if you don't already know them. Give it a try and we can help.

const int NumDPins = 6; //this many pins will be compared for digital matches
const int NumAPins = 2; //this many analog pins will be compared for max/min
const boolean MatchDigital[] = {HIGH, LOW, LOW, LOW, HIGH, HIGH}; //The pattern of digital pins sought
const int MatchLow[] = {0, 199}; //analog pins will 'match' when above this low point and below the high point
const int MatchHigh[] = {1, 1024}; //analog pins will match when below this high point AND above the low point
const int DPins[] = {2, 3, 4, 12, 11, 13}; //physical digital pins on the Arduino
const int APins[] = {A0, A1}; //physical analog pins
const unsigned long PrintInterval = 100; //milliseconds - don't print more often than this when a match exists 
void setup() {
  Serial.begin(9600);
  Serial.println("Comparer starting!");
}

void loop() {
  for(int i=0; i<NumDPins; i++) {
    if(digitalRead(DPins[i]) != MatchDigital[i]) return;  //if any one fails to match, go back to the top of loop()
  }
  for(int i=0; i<NumAPins; i++) {
    int a = analogRead(APins[i]);
    if(a < MatchLow[i] || a > MatchHigh[i]) return;  //if any one fails to match, go back to the top of loop()
  }
  //if we get to here, then all the above comparisons passed - we have a match!
  static unsigned long LastPrinted = 0; //static so it is remembered for the next loop()
  if(millis() - LastPrinted > PrintInterval) {
    //we haven't printed in the last 100 milliseconds, so we are allowed to print now
    Serial.println("Match!"); 
    LastPrinted = millis();
  }
}

You didn't specify analog pins, but I thought it would be easy enough to add those. Of course this doesn't look at any smart sensors like digital temperature sensors, but it's a good framework to start with.

Notice there are arrays for the desired match, but no need to store the actual sensor values in arrays.

The pins themselves are also arrays, since you may move sensors around to different pins but still keep the same logical order.

If assigned binary values, won't any combination of those values in the saved array always add up to a unique value? If so, that value could be compared to a sought value. - Scotty

Thanks all for the help! :grin: :grin: