Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Second counter are not logged in the SD card on: November 04, 2012, 09:35:51 am
sorry i have little knowledge on programming From what i see im pretty close to what i wanted to attain. That thing is actually happening on the sensor B, it log every count with its specific time but not in sensor A. But i can see also that same code was used in both sensor. thank you!
2  Using Arduino / Programming Questions / Re: Second counter are not logged in the SD card on: November 04, 2012, 08:57:15 am
number of bees that entered Feeding Station A:  1
Bees are being detected entering Feeding Station A
number of bees that entered Feeding Station A:  2
Bees are being detected entering Feeding Station A
number of bees that entered Feeding Station A:  3
Bees are being detected entering Feeding Station B
number of bees that entered Feeding Station B:  1
3, 1
DATE:2012/11/04-TIME:21:49:36
3, 1
DATE:2012/11/04-TIME:21:49:37
Bees are being detected entering Feeding Station B
number of bees that entered Feeding Station B:  2
3, 2
DATE:2012/11/04-TIME:21:49:37
3, 2
DATE:2012/11/04-TIME:21:49:37
Bees are being detected entering Feeding Station A
number of bees that entered Feeding Station A:  4
Bees are being detected entering Feeding Station A
number of bees that entered Feeding Station A:  5
Bees are being detected entering Feeding Station B
number of bees that entered Feeding Station B:  3
5, 3
DATE:2012/11/04-TIME:21:49:40
5, 3
DATE:2012/11/04-TIME:21:49:40




this is what happens on my serial port, In stationA it only shows the count but does not log, in stationB EVERTIME there is a count it will log it with the time included PLUS the present number in station A
3  Using Arduino / Programming Questions / Re: Second counter are not logged in the SD card on: November 04, 2012, 08:49:10 am
Sorry for the late post, i was out for a week, anyway i changed some bracket on my code. The one in the BeeCounterA, what happens is that i was able to see the number of count in A but it cannot be log in the sd. When the BeeCounterB counts, it will log its present value and at the SAME time log the present value of counterA. I tried rearranging my brackets to no avail. I also follow what sir Paul recommended to do.

Code:
void loop() {
  // read the Sensor input pin:

  CurrentSensorStateA = digitalRead(BeeSensorA);
  CurrentSensorStateB = digitalRead(BeeSensorB);

  // compare the Sensor State to its previous state
  if (CurrentSensorStateA != PreviousSensorStateA)
  {
    // if the state has changed, increment the counter for bees
    if (CurrentSensorStateA == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
    {
      lastEvent= millis(); // a bee can be recorded

      // if the current state is HIGH then the button
      // wend from off to on:

      BeeCounterA++;
      Serial.println("Bees are being detected entering Feeding Station A");
      Serial.print("number of bees that entered Feeding Station A:  ");
      Serial.println(BeeCounterA);
    }
  }
  if (CurrentSensorStateB != PreviousSensorStateB)
  {
    // if the state has changed, increment the counter for bees
    if (CurrentSensorStateB == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
    {
      lastEvent= millis(); // a bee can be recorded

      // if the current state is HIGH then the button
      // wend from off to on:

      BeeCounterB++;
      Serial.println("Bees are being detected entering Feeding Station B");
      Serial.print("number of bees that entered Feeding Station B:  ");
      Serial.println(BeeCounterB);
    }
4  Using Arduino / Programming Questions / Re: Second counter are not logged in the SD card on: October 30, 2012, 09:53:01 am


only Sensor A are being logged in the SD CARD??
5  Using Arduino / Programming Questions / Second counter are not logged in the SD card on: October 30, 2012, 09:49:14 am
hi guys!!
 I made a program to count the number of bees entering a feeding station. With use of IR sensor. I based my counter program on the "StateChangeDetection" program. I also sync it to RTC DS 1307. so that the time and present number of bees will be logged. I have to make two, so far my sd card are only logging per one sensor (but same code on two sensors). It is in a csv format.

 I also want to view my file per time, or whenever the arduino was cut off. another file will be make when open once again. Thank you in advance any insight will do.

Code:
//Program by Jeremy Blum
//www.jeremyblum.com
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Assisted by Inigo D. Villanueva III
//Edited by Ignacio D. Villanueva III
//For thesis purpose entitled "
//Thesis members: James Santiago. Belen Cruz. Franzes Francisco, Kaye Agut

#include <SD.h>  //SD Card Library
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;
//SPI SD Card Pins
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
const int CS_pin = 10;
int pow_pin = 8;


// this constant won't change:
const int  BeeSensorA = 3;    // IR sensor that will set HIGH whenever a bee passes otherwise LOW
const int  BeeSensorB = 5;


// Variables will change:
int BeeCounterA = 0;                 // counter for the number of bee that had passed sensorA
int CurrentSensorStateA = 0;         // current state of SensorA
int PreviousSensorStateA = 0;       // previous state of SensorA


int BeeCounterB = 0;               // counter for the number of bee that had passed sensorB
int CurrentSensorStateB = 0;       // current state of SensorB
int PreviousSensorStateB = 0;     // previous state of SensorB

long lastEvent= 0; // The last time a bee has entered the feeding station
long interval= 300; // The debounce time


char dateTimeString[30];
int yr;


void setup() {

  Serial.begin(9600);
  Wire.begin();
  RTC.begin();


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

  // initialize the button pin as a input:
  pinMode(BeeSensorA, INPUT);
  pinMode(BeeSensorB, INPUT);

  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the Sensor input pin:

  CurrentSensorStateA = digitalRead(BeeSensorA);
  CurrentSensorStateB = digitalRead(BeeSensorB);

  // compare the Sensor State to its previous state
  if (CurrentSensorStateA != PreviousSensorStateA)
  {
    // if the state has changed, increment the counter for bees
    if (CurrentSensorStateA == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
    {
      lastEvent= millis(); // a bee can be recorded

      // if the current state is HIGH then the button
      // wend from off to on:

      BeeCounterA++;
      Serial.println("Bees are being detected entering Feeding Station A");
      Serial.print("number of bees that entered Feeding Station A:  ");
      Serial.println(BeeCounterA);
    }

    if (CurrentSensorStateB != PreviousSensorStateB)
    {
      // if the state has changed, increment the counter for bees
      if (CurrentSensorStateB == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
      {
        lastEvent= millis(); // a bee can be recorded

        // if the current state is HIGH then the button
        // wend from off to on:

        BeeCounterB++;
        Serial.println("Bees are being detected entering Feeding Station B");
        Serial.print("number of bees that entered Feeding Station B:  ");
        Serial.println(BeeCounterB);
      }

    }
    {
      DateTime now = RTC.now();
      yr = now.year() - 2000;

      sprintf (dateTimeString, "DATE:%.2d/%.2d/%.2d-TIME:%.2d:%.2d:%.2d", now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
    }

    //Write Log File Header
    File logFile = SD.open("DATALOG.csv", FILE_WRITE);
    if (logFile)

    {

      logFile.print(BeeCounterA);
      logFile.print(", ");
      logFile.println(BeeCounterB);
      logFile.println(dateTimeString);
      logFile.close();

      Serial.print(BeeCounterA);
      Serial.print(", ");
      Serial.println(BeeCounterB);
      Serial.println(dateTimeString);


    }
    else

    {
      Serial.println("LogFile cannot be opened");

    }

    PreviousSensorStateA = CurrentSensorStateA;
    PreviousSensorStateB = CurrentSensorStateB;


  }

}














6  Using Arduino / Storage / Re: Logging time of RTC once a sensor was triggered in csv format on: October 23, 2012, 01:41:52 am



this image is what i wish to happen in my logger
7  Using Arduino / Storage / Logging time of RTC once a sensor was triggered in csv format on: October 23, 2012, 01:31:24 am
Hello guys, this is a follow up post from my previous one, below is the code for my counter that im planning to sync with the RTC. Once the sensor was triggered it will record the increment and the timestamp.

This is one is the code for my counter sensor

Code:
//Program by Jeremy Blum
//www.jeremyblum.com
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Assisted by Inigo D. Villanueva III
//Edited by Ignacio D. Villanueva III
//For thesis purpose entitled "
//Thesis members: James Santiago. Belen Cruz. Franzes Francisco, Kaye Agut

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

//SPI SD Card Pins
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
const int CS_pin = 10;
int pow_pin = 8;


// this constant won't change:
const int  buttonPin1 = 3;    // the pin that the pushbutton is attached to
const int  buttonPin2 = 5;
const int ledPin1 = 13;       // the pin that the LED is attached to
const int ledPin2 = 11;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int buttonPushCounter1 = 0;   // counter for the number of button presses
int buttonState1 = 0;         // current state of the button
int lastButtonState1 = 0;     // previous state of the button

long lastEvent= 0; // The last time a bee has entered the feeding station
long interval= 300; // The debounce time


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

  // initialize the button pin as a input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin1);
  buttonState1 = digitalRead(buttonPin2);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState)
  {
    // if the state has changed, increment the counter
    if (buttonState == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
 {
lastEvent= millis(); // a bee can be recorded

      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("Bees are being detected entering Feeding Station A");
      Serial.print("number of bees that entered Feeding Station A:  ");
      Serial.println(buttonPushCounter);
    }
   
 
  }
  if (buttonState1 != lastButtonState1)
  {
    // if the state has changed, increment the counter
    if (buttonState1 == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
 {
lastEvent= millis(); // a bee can be recorded)

      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter1++;
      Serial.println("Bees are being detected entering Feeding Station B");
      Serial.print("number of bees that entered Feeding Station B:  ");
      Serial.println(buttonPushCounter1);
    }
 

    //Write Log File Header
    File logFile = SD.open("DATALOG.csv", FILE_WRITE);
    if (logFile)
   
     {
       
      logFile.print(buttonPushCounter);
      logFile.print(", ");
      logFile.println(buttonPushCounter1);
      logFile.close();

      Serial.print(buttonPushCounter);
      Serial.print(", ");
      Serial.println(buttonPushCounter1);

    }
    else

    {
      Serial.println("LogFile cannot be opened");

    }

    lastButtonState = buttonState;
    lastButtonState1= buttonState1;


  }

}











This one is the code to show the time from my RTC DS1307

Code:
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    //RTC.adjust(DateTime(__DATE__, __TIME__));
  }

}

void loop () {
    DateTime now = RTC.now();
   
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
   

 
    Serial.println();
    delay(1000);
}

Some people said i should use interrupt once the sensor was triggered an interrupt function will get the time from the RTC and log it, however i have no idea how to use it. thanks!
8  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 12:19:22 pm
Pardon me, okay what i did here is that i have a pulse sensor, It is a phototransistor and an IR led, when the bee passed that a pulse (HIGH) will be detected, and it must increment the number. I originally modified the StateChangedetection program for this, and as a preliminary test i used push buttons to replace the sensor for conveniency purposes

BTW i replaced it this way

Code:
// Variables will change:
int CurrentNumberofBeesA = 0;   // counter for the number of bees that entered the sensor
int ActualStateofSensorA = 0;         // state of the sensor (Either HIGH or LOW)
int PreviousStateofSensorA = 0;     // previous state of the sensor (Either HIGH or LOW)
int CurrentNumberofBeesB = 0;   // counter for the number of bees that entered the sensor
int ActualStateofSensorB = 0;         // state of the sensor (Either HIGH or LOW)
int PreviousStateofSensorB= 0;     // previous state of the sensor (Either HIGH or LOW)


long lastEvent= 0; // The last time a bee has entered the feeding station or the last time a bee was detected by the sensor
9  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 11:53:39 am
Quote
I think that the best thing, at this point, is for you to post all of your code.

im sorry for the terrible names, i changed it a little bit i hope it will be more understandable.

Code:
//Program by Jeremy Blum
//www.jeremyblum.com
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Assisted by Inigo D. Villanueva III
//Edited by Ignacio D. Villanueva III
//For thesis purpose entitled "
//Thesis members: James Santiago. Belen Cruz. Franzes Francisco, Kaye Agut

#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;

// this constant won't change:
const int  buttonPinA = 3;    // the pin that the pushbutton is attached to
const int  buttonPinB = 5;

// Variables will change:
int CurrentNumberofBeesA = 0;   // counter for the number of button presses
int ActualStateofCounterA = 0;         // state of the button (Either HIGH or LOW)
int PreviousStateofCounterA = 0;     // previous state of the button (Either HIGH or LOW)
int CurrentNumberofBeesB = 0;   // counter for the number of button presses
int ActualStateofCounterB = 0;         // state of the button (Either HIGH or LOW)
int PreviousStateofCounterB= 0;     // previous state of the button (Either HIGH or LOW)


long lastEvent= 0; // The last time a bee has entered the feeding station
long interval= 300; // The debounce time



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

  // initialize the button pin as a input:
  pinMode(buttonPinA, INPUT);
  pinMode(buttonPinB, INPUT);

  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  ActualStateofCounterA= digitalRead(buttonPinA);
  ActualStateofCounterB = digitalRead(buttonPinB);

  // compare the buttonState to its previous state
  if ((ActualStateofCounterA != PreviousStateofCounterA ) || (ActualStateofCounterB != PreviousStateofCounterB))
  {
    // if the state has changed, increment the counter
    if (ActualStateofCounterA == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
    {
      lastEvent= millis(); // a bee can be recorded)
      // if the current state is HIGH then the button
      // wend from off to on:

      CurrentNumberofBeesA++;
      Serial.println("Bees are being detected entering Feeding Station A");
      Serial.print("number of bees that entered Feeding Station A:  ");
      Serial.println(CurrentNumberofBeesA);

    }
    {   
      // if the state has changed, increment the counter
      if (ActualStateofCounterB == HIGH && millis() - lastEvent > interval)// Ignore this reading if it is too close to the last one
      {
        lastEvent= millis(); // a bee can be recorded)
        // if the current state is HIGH then the button
        // wend from off to on:
      } 
      CurrentNumberofBeesB++;
      Serial.println("Bees are being detected entering Feeding Station B");
      Serial.print("number of bees that entered Feeding Station B:  ");
      Serial.println(CurrentNumberofBeesB);
    }




    //Write Log File Header
    File logFile = SD.open("DATALOG.csv", FILE_WRITE);
    if (logFile)


    {

      if(ActualStateofCounterA != PreviousStateofCounterA)

        logFile.print(CurrentNumberofBeesA);
      logFile.print(", ");
      logFile.println(CurrentNumberofBeesB);
      logFile.close();

      Serial.print(CurrentNumberofBeesA);
      Serial.print(", ");
      Serial.println(CurrentNumberofBeesB);

    }
    else

    {
      Serial.println("LogFile cannot be opened");

    }

    CurrentNumberofBeesA= ActualStateofCounterA;
    CurrentNumberofBeesB= ActualStateofCounterB;


  }

}










10  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 10:26:21 am
I also wonder why one of the sensor does a double count when i pressed it once. But if i unplug one pin. It actually just works right. hmmmmmm.

Im using 2 pushbuttons as my sensor. In the program i used debouncing so i don't think its the problem.
11  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 10:23:13 am

Quote
Hard to see in that tiny picture, but writing out the changed value in column 1 or column 2 or both is trivial. If one or more values change, you need to write a record. For each column, determine what to put in that column - a new value or a series of spaces. Then, write the record.

I modified my post. I wish i can create a logger like the one on the second picture. Can you suggest what can i do? thanks!!
12  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 10:12:53 am
thanks so much dan35, my logger now looks like this. Much better than my old one.



however, i wish i could make something like this where you don't include the data of sensor A when the sensor B was incremented, like this



i hope you guys will never get tired of helping me, sorry for being a newbie  smiley-confuse smiley-confuse
13  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 07:38:26 am
Quote
You'll want to make sure all the braces match here, but they look right.  BTW, when posting your code, please use the Auto Format tool under the Tools menu first--it'll make the code a bit easier to follow.

can't find the tools menu, thanks a lot. ill keep you posted.

im doing it one step at a time, i wish i can make it right so i can proceed to the RTC and the temperature/ humidity sensor.. thanks!! smiley
14  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 04:00:29 am
im thinking of using delay? refresh rate?
but my data will not be accurate i think.. arghh  smiley-roll-sweat smiley-roll-sweat
15  Using Arduino / Storage / Re: datalogger for counter sensor with RTC HELP! on: September 23, 2012, 03:45:47 am
You open the file. Where do you close it?

Code:
File logFile = SD.open("DATALOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.print(buttonBeeCounterA);
    logFile.print(",");
    logFile.println(buttonBeeCounterB);
    logFile.close();
    

  

    Serial.print(buttonBeeCounterA);
    Serial.print(",");
    Serial.println(buttonBeeCounterB);






    
 }
else

{
    Serial.println("LogFile cannot be opened");

}

}

  

i followed it but same result as the string does. so many data being stored, tons of data. i wonder why?

same result as this

Pages: [1] 2