The Planted Tank Forum - View Single Post - DIY PAR meter, Yeah you heard me
View Single Post
Old 11-10-2010, 05:03 PM   #18
mistergreen
No more Bow ties
 
mistergreen's Avatar
 
PTrader: (13/100%)
Join Date: Dec 2006
Location: Cincinnati
Posts: 14,336
Default

I don't think I showed you how I'm reading the values so far.



It's all through USB... It's supplying the ardiuno power and a way for the ardiuno to communicate to my computer...
This is my serial monitor outputting the values.


The values jump/dance around like it's being hit by photons, kinda cool. So I wrote the code to find the average within every second...

NON-PAR code...(NOT FINAL)
Code:
unsigned long average = 0;
unsigned long time;
int counter = 0;

void setup() {
  Serial.begin(9600);
  time = millis();
}

void loop() {
  int sensorValue = analogRead(0);
  average += sensorValue;
  counter++;

  //every second or 1000 millis
  if(millis() > time+1000) {
    average = average/counter;
    Serial.println(average);
    
    //reset timer & counter to get ready for the next second.
    time = millis();
    counter = 0;
    average = 0;
  }
}
Oh, I double checked the readings by going outside... Full sun will give me the maximum value of 1023.. In the shade, around 100-120.
mistergreen is online now   Reply With Quote