I so the fluctuating in the Arduino reading. two things solved this noise (fluctuations in reading)
-
adding 100nF between FSR (A0 node) to ground
-
changing to pulldown resistor (in that case even the 100nF was not needed)
I so the fluctuating in the Arduino reading. two things solved this noise (fluctuations in reading)
adding 100nF between FSR (A0 node) to ground
changing to pulldown resistor (in that case even the 100nF was not needed)
Well do you want to find out why there is a diference?
What FSR are you using?
Are you actually trying to measure force?
Yes I do.
What FSR are you using?
Are you actually trying to measure force?
Not really, I’m using it to detect a pressing to trigger audio file as well to change the volume of it using the continues reading from the FSR
Well the important thing is the amount of noise you get when the sensor is pushed. Was it the same or different in both cases?
Selecting or volume sounds like a relative slow process.
Do you use oversampling, smoothing or hysteresis in your code code, to reduce noise.
You should have included the code in the first post.
Leo..
here is the full
const byte heartbeatLED = 13;
unsigned long heartbeatMillis;
unsigned long previousMillis = 0;
unsigned long interval = 20; //reading every x ms
//mux pin for reading//
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
const int NUMSENSORS = 3; // change this variable to set the number of sensors
int SIG_pin = A0;
int previousValue[NUMSENSORS] = { 0 };
bool isOn[NUMSENSORS] = { false };
int pressThreshold = 10; // Change this variable to set the pressThreshold value
byte filter = 2; //whatever is needed
void setup() {
Serial.begin(115200);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(heartbeatLED, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
readSensors();
checkHeartbeatTIMER();
}
}
void readSensors() {
// Loop through all the sensors
for (int i = 0; i < NUMSENSORS; i++) {
// Set the multiplexer to select the correct channel
digitalWrite(s0, (i & 1));
digitalWrite(s1, (i & 2) >> 1);
digitalWrite(s2, (i & 4) >> 2);
digitalWrite(s3, (i & 8) >> 3);
// Read the sensor value (when using pullup resistor)
// int sensorValue = 1023 - analogRead(SIG_pin);
// Read the sensor value (when using pulldown resistor)
int sensorValue = analogRead(SIG_pin);
// Check if the sensor value has changed
if (sensorValue != previousValue[i]) {
// Check if the change is greater than the filter value
if (abs(previousValue[i] - sensorValue) > filter) {
// Update the previous value
previousValue[i] = sensorValue;
// Print the sensor value
Serial.print("value_ch");
Serial.print(i);
Serial.print(" ");
Serial.println(sensorValue);
// Check if the sensor value is greater than the press threshold
if (sensorValue > pressThreshold) {
// Check if the sensor is not already on
if (!isOn[i]) {
// Update the on/off state
isOn[i] = true;
// Print the on/off state
Serial.print("ch");
Serial.print(i);
Serial.print("on ");
Serial.println(isOn[i]);
}
} else {
if (isOn[i]) {
isOn[i] = false;
Serial.print("ch");
Serial.print(i);
Serial.print("on ");
Serial.println(isOn[i]);
}
}
}
}
}
}
void checkHeartbeatTIMER() {
//********************************* heartbeat TIMER
//is it time to toggle the heartbeatLED ?
if (millis() - heartbeatMillis >= 500ul) {
//restart this TIMER
heartbeatMillis = millis();
//toggle the heartbeatLED
digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
}
} //END of checkHeartbeatTIMER()
Well consider this:
In one case you have a 10Meg ohm resistor connected to ground (unloaded FSR) and in the other case you have a 10K resistor to ground.
This is the case with the pullup resistor right?
this is with pulldown resistor.
So why I’m getting noise when I have 1Mohm between A0 and GND?
It's 10 Meg ohms.
Say you pick up enough stray noise to induce just 100nA of current into the wires. Which set-up will produce more noise (without the capacitor). The answer involves using ohms law.
So in that case the 10k pulldown will pickup much less noise. So I don’t see why not using it?
(apart of the chance to short the long VCC wire to ground? is this the only down case?)
You can put a 510 ohm resistor in series with the 5V. That way if it does short, it will only draw about 10mA. Also keep the 100nF capacitor.
So when not touched the voltage should be around 0V and when pushed it should go above 2.5V
Will all the FSRs be located close to each other?
I could place it at the arduino side? right? it does not matter if it is close to the arduino 5V or the fsr side?
can it be lower value such as 470R or even 220R?
above 2.5 to the full range of 5V? I will check it at home later but if I understand it right it still should get me the full range just with less current?
Will all the FSRs be located close to each other?
at the arduino side yes.
at the FSR side not so much. I would say between 30cm to 1 meter apart
Yes.
can it be lower value such as 470R or even 220R?
You could make it 1 ohm provided the wires don't melt or the power supply doesn't burn up. Why draw draw more current?
above 2.5 to the full range of 5V?
See the graph in the datasheet.
would say between 30cm to 1 meter apart
Then you might be able to use just one ground wire.
For the wire, you can use thin stuff like AWG 26. Even ethernet cable will be OK.
Thanks! I will do as you suggested - adding 510R or 470R resistor in series with FSR and arduino 5V.
This graph?
So basicly with 10k resistor as I have now At maximum force I’m getting maximum of 3V (?). This will explain why I never get to 1023 at the arduino reading. the addition of 510R resistor won’t effect much of the reading right. This addition of 510R to the 10M of the FSR is negligible right?
edit: how does it possible to change this logarithmic change of the reading when pressing the FSR (as presented in the graph) to more of a linear curve?
Yes it does.
the addition of 510R resistor won’t effect much
Correct.
to more of a linear curve?
It would be difficult to do with analog circuits but of course you can do it in software. Most people only use those sensors to indicate crude force settings like small, medium, large.
First one is correct, 470R connected to Vcc
how can it be made in Arduino?
what should I look for?
I guess I need to change something in this part:
int sensorValue = analogRead(SIG_pin);
// Check if the sensor value has changed
if (sensorValue != previousValue[i]) {
// Check if the change is greater than the filter value
if (abs(previousValue[i] - sensorValue) > filter) {
// Update the previous value
previousValue[i] = sensorValue;
You don't need it to be linear so I won't go into how to do it.
If you want to know, start a new topic.