datalogger for counter sensor.

Hello guys! Newbie here in arduino. I wish i could get some help from here. The idea of my datalogger is that it will log a value whenever someone passes a sensor. It is like when a voltage or pulse was sense then it will count as one. I have edited this program by jeremy blum oh his tutorial. The thing is that its way of datalogging is like reading a potentiometer in which the voltage passes through and convert it to analog value. As we all know you can only put a delay on that which makes it log every value of the delay so it logs also even there is no voltage. Plus i want the reading to output a standard value like one(1) when someone passes by

feel free to ask if you are not enlighten on my concept.

//Program by Jeremy Blum
//www.jeremyblum.com
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Edited by Ignacio D. Villanueva III

#include <SD.h>         //SD Card Library

//SPI SD Card Pins
  //MOSI = Pin 11
  //MISO = Pin 12
  //SCLK = PIN 13
  int CS_pin = 10;
  int pow_pin = 8;
  
//Honeybee Sensor Pins
  
  int sense_pin= 0;
  int sense_pin1= 3;
 	

float refresh_rate = 0.0;  //Dataloger Refresh Rate
long id = 1;                //Use this to store the id # of our reading.

void setup()
{

  Serial.begin(9600);
  Serial.println("Initializing Card");
  //CS Pin is an output
  pinMode(CS_pin, OUTPUT);
  
  //SD Card will Draw Power from Pin 8, so set it high
  pinMode(pow_pin, OUTPUT);  
  digitalWrite(pow_pin, HIGH);
  
  //Initialize Card
  if (!SD.begin(CS_pin))
  {
      Serial.println("Card Failure");
      return;
  }
  Serial.println("Card Ready");
  
  //Read the Configuration information (COMMANDS.txt)
  File commandFile = SD.open("COMMANDS.txt");
  if (commandFile)
  {
    Serial.println("Reading Command File");
    
    float decade = pow(10, (commandFile.available() - 1));
    while(commandFile.available())
    {
      float temp = (commandFile.read() - '0');
      refresh_rate = temp*decade+refresh_rate;
      decade = decade/10;
    }
    Serial.print("Refresh Rate = ");
    Serial.print(refresh_rate);
    Serial.println("ms");
    commandFile.close();
  }
  else
  {
    Serial.println("Could not read command file.");
    return;
  }
  
  //Write Log File Header
  File logFile = SD.open("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println(", ,"); //Just a leading blank line, incase there was previous data
    String header = "ID, SENSOR_1, SENSOR_2";
    logFile.println(header);
    logFile.close();
    Serial.println(header);
  }
  else
  {
    Serial.println("Couldn't open log file");
  }
  
}

void loop()
{

  int sense_val = analogRead(sense_pin);
  int sense_val1 = analogRead(sense_pin1);

  
  //Create Data string for storing to SD card
  //We will use CSV Format  
  String dataString = String(id) + ", " + String(sense_val) + ", " + String(sense_val1); 
  
  //Open a file to write to
  //Only one file can be open at a time
  File logFile = SD.open("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println(dataString);
    logFile.close();
    Serial.println(dataString);
  }
  else
  {
    Serial.println("Couldn't open log file");
  }
  
  //Increment ID number
  id++;
  
  delay(refresh_rate);
}
  int sense_val = analogRead(sense_pin);
  int sense_val1 = analogRead(sense_pin1);

Make life easy on yourself and number these 1 and 2, not nothing and 1.

  String dataString = String(id) + ", " + String(sense_val) + ", " + String(sense_val1);

Go ahead. Shoot yourself in the foot.

Get rid of the String class now. There is no reason to construct a single string to write to the file. Writing 5 separate values takes no longer, and wastes far fewer resources.

As we all know you can only put a delay on that which makes it log every value of the delay so it logs also even there is no voltage.

We don't all know any such thing. You can log every n milliseconds, as this code is doing. Or, you can log when either of the two sensor values change. Or, you can log only when both sensor values change.

To log only when a sensor value changes, you need to keep track of the previous value logged. Log a new entry only when the current value differs from the previous value by more than some small amount (greater than 1).

The idea of my datalogger is that it will log a value whenever someone passes a sensor.

Either sensor? Both sensors? Are you concerned about which direction the sensors were tripped in?

yes, i can log every n milliseconds but the idea is to log everytime the sensor sense something that has passed.

How do you determine that something has passed? I presume that you see a relatively large change in one of the sensor readings.

Why are there two sensors?

Considering you will only log a value of 3.3V thats it and you ignore any values (i have a circuit to be applied for this).

I don't understand this. It looks like you are saying that the sensor reading is either 0 or 1023, which looks to me more like a digital sensor.

Please understand also that i want to convert that value into standard like 1(one).

I don't understand. You are already logging the actual value. What "standard values" are you expecting to produce? 0 and 1? If so, and you are only logging the 1's, then what is the purpose?

Can you suggest some coding to be used in this.

Not until we get the requirements nailed down.

I can assume someone has passed when the sensor sense it

How does the sensor report that? You are reading a value from each sensor. What does "nobody is here" return? What does "Hey, there's somebody here" return?

Let's all assume that i want to log voltage here.

Then, you need to know what the reference voltage is, and multiply the analogRead() output by Vref/1023.0.

whenever theres a voltage i want to log it.

There is ALWAYS a voltage. Sometimes it is very low. Make up your mind what you want to log.

And yes there are values and i want to convert those values to 1 or 0. for formalization.

Which ones become 0 and which ones become 1?