Measuring pressure and light - circuit guidance

Hello!

I'm trying to put together a basic pressure and light measuring device and would appreciate some input on my circuit design. The design is pretty minimal, but I'm entirely new to Arduino and electronics in general so I was hoping for someone more knowledgeable to have a look in order to avoid unnecessary mistakes.

I'm using an Arduino Uno, a force sensitive resistor (SEN-09673) and a mini photocell (SEN-09088) to measure the time difference between applying pressure and sensing an increased amount of light. I've connected the force sensor and the light sensor in two parallel circuits containing a sensor and an 1k Ohm resistor, powered by the Arduino's 5V port. I've hooked the analog pin up to the point between the sensor and the resistor. (I've attached a breadboard schematic.)

Now, my question is basically: will this work?
(Are the resistors too strong/not strong enough? Am I missing something? Will the sensors influence each other somehow?)

Thank you!

Hi robin183

Can you say a bit more about what you are trying to achieve?

What is applying the pressure? What light is the light sensor reading? How quickly or slowly are the light and pressure changing? How short or long a time period are you expecting to measure between them?

Also, if you have written any code, could you please post it? Use the code tags when you do - there is a button marked "#" above the row of smileys on the post entry form.

The basic structure of your circuit looks reasonable: the sensors are in voltage dividers; you are going to analogRead() each of the inputs and do something based on the result, I guess. There might be better values for your 1k resistors depending on the answers to the questions above. But you won't "blow up" your Arduino connecting like this.

All the best

Ray

Hi! Thanks for responding.

I'm hoping to be able to measure the response time of a touch screen. It would work by touching the screen with the force sensor and reading changes on the screen with the light sensor. The touch screen goes from fully black to fully white when sensing touch, so the difference should be big enough for the light sensor to pick up without too much work. The time between force and light should be approximately 75-150 ms by a rough guesstimate. I'm hoping the sensors aren't going to limit my experiments, but if they are, then I guess I'll have to deal with that later.

Your assumptions are correct - that's what I intend to do. And good to hear that I've managed to make the circuit safe, then I should be able to start experimenting a bit with it soon!

Also, I've written some code for it, but it's entirely untested as I wanted some input on the circuit before trying it out. The limits I've set for what counts as "enough" pressure/light are currently set to half (512), but I intend to calibrate that value later on to reflect the actual values I can expect to read from the input.

const int forceSensorPin = 0; // Force sensitive resistor on A0
const int lightSensorPin = 1; // Light sensitive resistor on A1
const int forceLimit = 512;   // The lowest force reading to count as force
const int lightLimit = 512;   // The lowest light reading to count as light

int forceInput = -1; // The measured force, 0-1023 (inclusive)
int lightInput = -1; // The measured light, 0-1023 (inclusive)
int forceTime = -1;  // The time when force was measured
int lightTime = -1;  // The time when light was measured
int latency = -1;    // The time delta of the lightTime and forceTime
int avgLatency = -1; // The average latency of all measured cycles

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

void loop() {
  if (forceTime == -1) { // if force not measured
    readForce();
  } else if (forceTime != -1 && lightTime == -1) { // if force measured and light not measured
    readLight();
    calculateLatency();
    printLatency();
    reset();
  }
}

void readForce() {
  forceInput = analogRead(forceSensorPin);
  if (forceInput >= forceLimit) {
    forceTime = millis();
  }
}

void readLight() {
  lightInput = analogRead(lightSensorPin);
  if (lightInput >= lightLimit) {
    lightTime = millis();
  }
}

void calculateLatency() {
  latency = lightTime - forceTime;
  if (avgLatency == -1) {
    avgLatency = latency;
  } else {
    avgLatency = ((avgLatency + latency) / 2) + 0.5;
  }
}

void printLatency() {
    Serial.print("Latency: ");
    Serial.println(latency);
    Serial.print("Average: ");
    Serial.println(avgLatency);
    Serial.println();
}

void reset() {
  forceInput = -1;
  lightInput = -1;
  forceTime = -1;
  lightTime = -1;
  latency = -1;
}

OK, thanks for that.

The datasheet linked from the Sparkfun website says (p5) that there is a breakpoint at the low end of pressure where it behaves like a switch. Around this point, the resistance drops from 100k to 10k.

With a 1k resistor in your voltage divider, "not pressed" would give a voltage into the Arduino of 5V * (1k / (100k+1k)) = about 50mV. "Pressed" would give 5Vk * (1 / (10k+1k)) = about 450mV. A ratio of 9:1. And the 450mV would give an analogRead() reading of 1023 * (0.45/5) = about 90. So you would need to lower the threshold in your code. If you wanted a larger reading, you could increase the 1k resistor to 4.7k say. But still plan to test the sensor and calibrate your threshold value, e.g. by using the Arduino example program AnalogReadSerial.

On the light sensor, Sparkfun says it ranges from 10k dark down to 1k light. Again, you should test it to see how bright the light has to be to get a sensible change in voltage at the Arduino, but it feels like your 1k resistor is reasonable here.

However, CdS photo resistors have a relatively slow response time, around 100ms I believe. This is about the same as the period you are trying to measure. If the response (output voltage change vs time since light change) of the sensor is consistent, maybe there is some way you could calibrate for it.

But it might be easier to choose a different type of sensor. I have seen photo-diode sensors with response time in single digit microseconds.

Hope this helps

Ray

Your calculations will save me quite some time calibrating. I'll change the resistor to 4.7k to boost the readings a bit, and using the AnalogReadSerial code for calibration is an excellent idea!

Too bad about the response time of my sensor though, that will probably complicate things a bit. Thank you for pointing that out, then I won't be as puzzled if my measurements go way above the expected values. I'll look into getting a photo-diode sensor with a better response time.

Thank you very much for your help! : )