Reading data from dynamometer noise issues?

Hello, i'm currently working on a project on Arduino UNO, dynamometer and an inductive sensor. Everything should work like this: when inductive sensor senses anything, at the same time data from dynamometer shows on serial monitor, number of detections by inductive sensor also is displayed. I connected inductive sensor through transoptor to arduino, because it works at 6-36V(I will show the picture below on how it is connected). Dynamometer is connected through RS232 to TTL converter to virtual rx and tx on arduino. I wrote a software and everything seems to be working, data is read from dynamometer only when something is detected by inductive sensor, however this data is not always correct. I also have a display on dynamometer so i can tell. Let's say there is 0,5Nm on dynamometer display, when i put metal in front of inductive sensor monitor serial data on computer is showing 0,0Nm, but if i do this 3-4 times, monitor serial data on computer starts to show 0,5Nm, sometimes it catches the same value from dynamometer and sometimes not so much. I thought that maybe it's the issue with some delay, but there is another problem - sometimes some random value like 50, or 20, or 5 is showing on serial monitor on laptop while there is completely different value on dynamometer. So to sum up, it's kinda working, but there is some noise perhaps? I've tried many things and nothing seems to correct the reading. Im at dead end, i really would appreciate anyone suggestions. Here is the code that i'm using:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(4,5); //rx, tx
#define InductiveSensor 13 //inductive sensor pin

String str;
float x;

int sensorCounter = 0;
int currentSensorState = 0;
int previousSensorState = 0;
bool label = true;
String datalabel1 = "Number of detections";
String datalabel2 = "Dynamometer value";

void setup()
{
Serial.begin(9600);
mySerial.begin(4800);
pinMode(InductiveSensor, INPUT);

}

void loop()
{

while(label) {
Serial.print(datalabel1);
Serial.print(",");
Serial.println(datalabel2);
label=false;
}

currentSensorState = digitalRead(InductiveSensor);

if (currentSensorState != previousSensorState) {
if (currentSensorState == LOW) {
sensorCounter++;

Serial.print(sensorCounter);
Serial.print(",");

if(mySerial.available()) {
str = mySerial.readStringUntil('\n');
x = mySerial.parseFloat();
Serial.println(mySerial.parseFloat());
delay(5);
}

} else {

}
delay(10);
}
previousSensorState = currentSensorState; //zliczanie liczby obrotow

}

About this part:
if(mySerial.available()) {
str = mySerial.readStringUntil('\n');
x = mySerial.parseFloat();
Serial.println(mySerial.parseFloat());
delay(5);
}

I didn't use simple Serial.println(mySerial.read()) because it showed data in ascii format, so i had to convert it. I would also like to mention that there seems to be no noise if i use Serial.write(mySerial.read()) - also i don't need to convert that one - but i don't know how to apply that to my code so that only one verse of data is being read on serial monitor.

Here is the display from my serial monitor:

Number of detections,Dynamometer value
1,0.00
2,0.00
3,0.00
4,0.00
5,0.00
6,0.00
7,0.00
8,0.00
9,0.67 - value detected after 8 inductive sensor activations, why?
10,0.60
11,0.65
12,0.80
13,0.75
14,0.80
15,75.00 - noise?
16,1.10
17,1.15
18,5.00 - noise?
19,1.20
20,1.00
21,1.15
22,1.05
23,1.05
24,1.05
25,1.40
26,1.30
27,1.25
28,1.30
29,1.20
30,1.45
31,1.00
32,11.15 - noise?
33,0.95

Here is how i connect inductive sensor:

uklad transoptor

There appears to be zero capacitive filtering on your circuit.

Thank you for your reply! I also tried to add 100nF capacitor between 3 and 4 leg of transoptor and it didn't help at all. Any other suggestions? There seems to be noise even if I only read data from dynamometer with inductive sensor excluded from the code.

Are all the ground pins connected to each other? All of them

Hi,
Have you got the RS232 lead shield/gnd connected at both ends?

Tom.. :smiley: :+1: :coffee: :australia:

There's how it is: on RS232 to TTL converter => VCC pin to 5V on arduino and GND pin to GND on arduino. Transoptor => 3rd leg of transoptor to GND on arduino, 4th leg of transoptor to 5V on arduino, it seems that only the GND of the 9V battery which is powering the inductive sensor is not connected to arduino, however it is physically disconnected from arduino due to transoptor, or maybe i should connect it to arduino GND? Im a beginner when it comes to electronics in general, correct me if i'm wrong please:) Also i would like to highlight that each GND connected to arduino is connected to separate GND pins on arduino side(2 GND slots in total,) i assumed that they are interconnected in general?

Hi,
A circuit diagram would be worth a thousand words.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

You're right, i should've posted this in the beggining, also i've been thinking - maybe it's not about the hardware but the software? Maybe the way im decoding the ascii code coming from dynamometer is the issue? When the dynamometer is showing 0.00 the serial monitor is also showing 0.00 all the time(data being sent continuosly), the noise comes into place only when i try to pull on the dynamometer so that the value of dynamometer is increasing, also if i use serial.write(mySerial.read()) there seems to be no noise no matter how i pull the dynamometer, noise is showing only if i use my decoding part of serial.println code, is it possible to apply serial.write to my code so that only one verse of data is being shown on serial monitor while inductive sensor senses anything? With serial.write i don't need to decode anything, value on serial monitor is the exact same as the data shown on dynamometer display

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.