Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: inconsistent temperature readings (LM35DT) on: December 10, 2012, 09:52:35 am
Hmm, I assumed that the ground pins on the arduino were shorted to each other. Shouldn't all grounds be connected anyway?

I followed some advice on adafruits website and it seemed to work. It seems strange since I already had a 10ms delay, and was repeating the reading 100 times, but calling my function a second time produced more accurate results.


Quote
Problems you may encounter with multiple sensors:
If, when adding more sensors, you find that the temperature is inconsistant, this indicates that the sensors are interfering with each other when switching the analog reading circuit from one pin to the other. You can fix this by doing two delayed readings and tossing out the first one

http://learn.adafruit.com/tmp36-temperature-sensor
2  Using Arduino / Sensors / Re: inconsistent temperature readings (LM35DT) on: December 09, 2012, 04:48:09 pm
The temperature change when I heat up the sensors, so it would seem that they are indeed connected.
3  Using Arduino / Sensors / inconsistent temperature readings (LM35DT) on: December 09, 2012, 03:08:25 pm
Hi,

I have 3 LM35DTs hooked up to my arduino inputs A0-A2. When I go to read their values I get significantly different results for each sensor (example: 16, 26, 21), even though their touching each other, meaning their temperatures should be identical. Interestingly, even if I move a sensor from one input to anther, the values don't change, suggesting that it's not a variation in the sensors. Any ideas of what could be causing these issues?

Here is the code I use to read the sensors:

I just call it 3 times with a different sensor_pin value.

Code:
float readTemp(int sensor_pin){
  // set reference voltage to 1.1V
  analogReference(INTERNAL);
  // make sure it had enough time to switch
  delay(10);
  float refV = 1.1;

  // take 100 readings and get the average
  float accumulatorRaw = 0;
  for (int i = 0; i < 100; i++){
    accumulatorRaw += analogRead(sensor_pin);
  }
  float averageRaw = accumulatorRaw / float(100);
  // LM35DT sensor: 0.01V per 1 degree centigrade
  float tempValue = ((averageRaw * refV ) / 1024) / 0.01;
 
  return tempValue;
}
4  Using Arduino / Programming Questions / Re: software low pass filter debug help on: December 09, 2012, 02:20:28 pm
oh I see. Hmm I guess I'll just define the size of the array. I wish arduino had more libraries built in. Thanks.
5  Using Arduino / Programming Questions / Re: software low pass filter debug help on: December 09, 2012, 01:06:20 pm
sorry that should have been just `data[]`.

hmm, so maybe my for loop should look like this:

Code:

  for (int i = 0; i < sizeof(data_array) - 1; i++)
    data_array[i] = data_array[i + 1];


edit: ok it runs now, but for some reason my array seems to be only of size 2, but when I print out sizeof(data) it is 40? And I thought I set it to 10...
6  Using Arduino / Programming Questions / software low pass filter debug help on: December 09, 2012, 12:45:53 pm
Hi,

I'm trying to add a software low pass filter to a noisy sensor to make the output smoother. I think I have the idea right and it compiles and uploads fine, but my arduino seems to crash when I run it; no serial output when if I call the lowPassFilter function. I'm used to seeing run time errors when I usually program, and now that I don't I'm stuck figuring out my error. Is there any way to simulate run time somehow to figure out errors? Or do I need a hardware debugger? I'm new to arduino so I'm just using the standard arduino IDE. It's not very feature rich in terms of auto completion or built in documentation. Should I be using something else?

here is my code:

Code:

float data[10];

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

  // initialize array
  for (int i = 0; i < sizeof(data); i++){
    data[i] = 0.0; 
  }
}

void loop(){
  float current_value = readData();
  float filtered_value = lowPassFilter(current_value, data);

  Serial.print("Value = ");
  Serial.println(filtered_value);
}

float lowPassFilter(float new_data, float *data_array){
 
  float filtered_value = 0;
  float data_array_sum = 0;
 
  // remove oldest data in array (first index) and shift all other indexes to the left
  for (int i = 0; i < sizeof(data_array); i++)
    data_array[i] = data_array[i + 1];
 
  // add new data to array (last index)
  data_array[sizeof(data_array) - 1] = new_data;
 
  // get average value from the data array
  for (int i = 0; i < sizeof(data_array); i++){
    data_array_sum += data_array[i];
  }
  filtered_value = data_array_sum / sizeof(data_array);
 
  return filtered_value;
}


Any ideas of what my problem could be or how I could figure it out without a hardware debugger?

Thanks

Pages: [1]