Go Down

Topic: Arduino issue of reading “stretch sensor” when temperature sensor is also connec (Read 127 times) previous topic - next topic

Mjafko

I have an Arduino UNO R3 board. I am trying to connect "stretch sensor" which is DIY with conductive fiber and I am getting its resistance reading from it. Reading are fine, linear when I breath and so on. But when I connect LilyPad temperature sensor from SparkFun, it is all messy. Resistance jumping up and down for more then 10k Ohm even when I don't move or breath ( holding my breath ). This only happen's when I connect my temperature sensor as I said.

Let me tell ya I am no any kind of expert of electronic. Working with Arduino board for a very first time.

My Arduino is connect to my laptop. So that is also way he get power supply.

Simple electric scheme how I connect elements :
http://imgur.com/a/1qNfB


And my code looks like :

Code: [Select]
//  Tempererature analog pin
const int tempPin = A0;
int num_samples = 10; // Number of samples before measure temperature!

//  Stretch pin's
const int stretchPin = A5;
const long int R1_resistor = 593000; // Resistor 600k ohm (593k ohm measured with Ohm-meter)

void setup() {

  Serial.begin(9600);
}

void loop() {
  temperature();
  delay(200);
  stretch();
  delay(500);
}

/*
LEGENDs :
S = stretch
T = temperature
*/

void sendData(char symbol, float number) {
  Serial.print(symbol);
  Serial.println(number);
}

//Stretch sensor
void stretch () {
  int raw = 0;
  int V_in = 5;
  float V_out = 0;
  float R2_resistor = 0;
  float buffer = 0;

  raw = analogRead(stretchPin);
  if(raw) {
    buffer = raw * V_in;
    V_out = (buffer) / 1023.0;
    buffer = (V_in / V_out) -1;
    R2_resistor = R1_resistor * buffer;
    sendData('S', R2_resistor);
  }
}

// Temperature measure!
void temperature () {
  int total = 0;
  float temp;

  for(int i = 0; i < num_samples; i++) {
    total += analogRead(tempPin);
    delay(5);
  }

  float v = total * 4.9 / 1024.0; // 4.93 volt measure
  temp = ((v - 0-5) * 100) / num_samples
 sendData('T', temp);
} //  End of.emperature
}


Could you help me out with my project ? I been stuck at this for a while now. Thank you.

I gona provide some graphs so you could see better.

This is how "graph" looks like without temperature sensor connected to Arduino. It shows right on breath taking.
http://imgur.com/a/hOWfi


And this picture shows "graph" with temperature sensor connected. It's messy and at some points could say I take breath even I did not. When I did is marked with red.
http://imgur.com/a/H1xcI


EDIT: pictures don't wanna show. Added links to them.

Greetings, Marko!

TomGeorge

Everything runs on smoke, let the smoke out, it stops running....

TomGeorge

Hi,
Try reading the stretch analog pin twice, and only using the last reading each time, the UNO only has one AtoD, and it is switched from input to input.

There is a capacitor on the AtoD that charges up/down to the level it is switched to, this takes time and if sampled too quick you will have some crosstalk between the channels.

All you have to do is add an extra analogRead line.

Code: [Select]
raw = analogRead(stretchPin);
 raw = analogRead(stretchPin);


It will read the stretchPin twice, but only use the last read.

Hope this helps.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

Mjafko

Hi,
Try reading the stretch analog pin twice, and only using the last reading each time, the UNO only has one AtoD, and it is switched from input to input.

There is a capacitor on the AtoD that charges up/down to the level it is switched to, this takes time and if sampled too quick you will have some crosstalk between the channels.

All you have to do is add an extra analogRead line.

Code: [Select]
raw = analogRead(stretchPin);
 raw = analogRead(stretchPin);


It will read the stretchPin twice, but only use the last read.

Hope this helps.. Tom.. :)
Thank you @TomGeorge I will test it out and report back here results :)

Greetings,
Marko.

Mjafko

Well it is maybe a little bit better when I add another analog reading. But still not the way I wanted. Anything else I could try to get better results ?

Greetings,
Marko.

edgemoron

Try this:
Code: [Select]
// Temperature measure!
void temperature () {
  int total = 0;
  float temp;

  analogRead(tempPin);
  for(int i = 0; i < num_samples; i++) {
    total += analogRead(tempPin);
    delay(5);
  }
  total /= num_samples;
  float v = total * 4.9 / 1024.0; // 4.93 volt measure
  temp = ((v - 0.5) * 100);
 sendData('T', temp);
} //  End of.emperature

Last edit.

Mjafko


Go Up