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);
}