To store serial data and can be viewed any time

Actually I am a begginer to arduino and i have a doubt. I need a set of telementary data to be stored and can be restored from the atmega proccesor. I’ve attached the code if possible to solve this please do reply guys. And if not possible you can also say the alternate method.

Thank you

My_project.ino (392 Bytes)

Your code is so small that you could have posted it in your post using code tags so it looks like

int sensorPin = A0;
int sensorValue = 0;
int Sensor = A1;
int absolutePressure;
void setup() {
  pinMode(Sensor , INPUT);
  Serial.begin(9600);
}

void loop() {

  sensorValue = analogRead(sensorPin);
  absolutePressure = analogRead(Sensor);
  absolutePressure = ((absolutePressure / 0.045) - 0.095);
  Serial.println("Telementary data:");
  Serial.println(absolutePressure, sensorValue);
}

Please explain what Serial.println(absolutePressure, sensorValue); does?

===
How many readings do you want to store? That will determine what the best way to store it is.

Please explain what Serial.println(absolutePressure, sensorValue); does?

It prints the value in absolutePressure, in base 14. Isn’t that obvious?

In that serial.println the data shows Carbon monoxide sensor value, atmospheric pressure, I require atleast 50 values (it's ok if any value is missed) from Carbon monoxide and atmospheric pressure of 50 value. and this is the new code. sorry for that mistake...
code:
int sensorPin = A0;
int sensorValue = 0;
int Sensor = A1;
int absolutePressure;
void setup() {
pinMode(Sensor , INPUT);
Serial.begin(9600);
}

void loop() {

sensorValue = analogRead(sensorPin);
absolutePressure = analogRead(Sensor);
absolutePressure = ((absolutePressure / 0.045) - 0.095);
Serial.println("Telementary data:");
Serial.println(absolutePressure);
Serial.print(",");
Serial.print(sensorValue);
delay(100);
}

sterretje:
Your code is so small that you could have posted it in your post using code tags so it looks like

So, what is the problem? You are sending data to the PC. Make the PC store the data, and count the number of values that it has stored.

sorry i don't knew how to put the code using tags

krithik2005:
sorry i don't knew how to put the code using tags

Why not? It is covered in the stickies at the top of every section of the forum - specifically the one named "How to use this forum - please read."

int sensorPin = A0;
int sensorValue = 0;
int Sensor = A1;
int absolutePressure;
void setup() {
  pinMode(Sensor , INPUT);
  Serial.begin(9600);
}

void loop() {

  sensorValue = analogRead(sensorPin);
  absolutePressure = analogRead(Sensor);
  absolutePressure = ((absolutePressure / 0.045) - 0.095);
  Serial.println("Telementary data:");
  Serial.println(absolutePressure);
  Serial.print(",");
  Serial.print(sensorValue);
}
void loop() {

If you are going to put the { on the line with the function, the only excuse that holds water for doing that is to save real-estate. Following that with a blank line blows that excuse out of the water.

What IS the problem? The Arduino code sends data to the serial port. It is up to the application that receives the data to store it, if that is what you want it to do.

actually iam making a small model of satellite which has a capablity of storing the data on-board so...

krithik2005:
actually iam making a small model of satellite which has a capablity of storing the data on-board so...

I think you mean "needs to have...".

Use EEPROM to store small amounts of data, persistent over resets. There is a library for that.

I knew I should have asked. How often? Or better, how many samples in total.

You have two int values that need to be stored; that's 4 bytes. You can store 250 pairs in eeprom on an 328P based board.

At the rate that your current code will write that to eeprom (once it does that), your eeprom will be full in no time.

/*
 * EEPROM Write
 *
 * Stores values read from analog input 0 into the EEPROM.
 * These values will stay in the EEPROM when the board is
 * turned off and may be retrieved later by another sketch.
 */

#include <EEPROM.h>

/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;

void setup() {
  /** Empty setup. **/
}

void loop() {
  /***
    Need to divide by 4 because analog inputs range from
    0 to 1023 and each byte of the EEPROM can only hold a
    value from 0 to 255.
  ***/

  int val = analogRead(0) / 4;

  /***
    Write the value to the appropriate byte of the EEPROM.
    these values will remain there when the board is
    turned off.
  ***/

  EEPROM.write(addr, val);

  /***
    Advance to the next address, when at the end restart at the beginning.

    Larger AVR processors have larger EEPROM sizes, E.g:
    - Arduno Duemilanove: 512b EEPROM storage.
    - Arduino Uno:        1kb EEPROM storage.
    - Arduino Mega:       4kb EEPROM storage.

    Rather than hard-coding the length, you should use the pre-provided length function.
    This will make your code portable to all AVR processors.
  ***/
  addr = addr + 1;
  if (addr == EEPROM.length()) {
    addr = 0;
  }

  /***
    As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
    EEPROM address is also doable by a bitwise and of the length - 1.

    ++addr &= EEPROM.length() - 1;
  ***/


  delay(100);
}

is this example used for my project ??

With a lot of modifications, yes. Use EEPROM.put and EEPROM.get; you're working with ints and not bytes so those two functions will handle that for you.

Because your storing ints, the address needs to be incremented by the size of the int.

PS
You did not answer the question how much data you need to store. 10 Samples, 100 samples, 1000 samples, ...

10 samples are enough

void loop()
{
  static int currentEEaddress;
  static int sampleCount;

  sensorValue = analogRead(sensorPin);
  absolutePressure = analogRead(Sensor);
  absolutePressure = ((absolutePressure / 0.045) - 0.095);

  if (sampleCount < 10)
  {
    EEPROM.put(currentEEaddress, absolutePressure);
    currentEEaddress += sizeof(absolutePressure);
    EEPROM.put(currentEEaddress, sensorValue);
    currentEEaddress += sizeof(sensorValue);

    sampleCount++;
  }
  else
  {
    Serial.println("10 samples taken");
  }
}

EEPROM.put
EEPROM.get

I’ll leave the reading of the samples from the EEPROM using get up to you; should not be that difficult.

sir how data can we save in Arduino UNO which has a atmega 328

Did you test it? This should work on an Uno.