Go Down

Topic: interfacing a sensor (Read 2959 times) previous topic - next topic

kavya_mc

hello....
In my project, I need to read data input from a pressure sensor npc 1220, and send some sort of indication to arduino everytime when the output of the sensor changes.I have done the first part. Is it possible to create interrupt,to inform the microcontroller when the sensor value changes? or is there any other method?
i have attached the sensor datasheet if necessary.
thankyou

hiimzackjones

I'm not an expert so take my advice lightly. In your case I would write code that compares the difference between what the sensor was and what it is. set your current value to a variable and then delay some amount of time then save the value again to a different variable. Then take the two and subtract them. If the answer is not 0 it has changed. Depending on how sensitive the sensor is, you may not want to make it compare it to 0 but say if the absolute value of the difference is greater than some value. For instance start your comparison at 1,(  if firstValue - secondValue > 1 then do blah) if it is still too sensitive move that number up incrementally to adjust until you are happy with it. As far as actually writing code to read the sensor, I cant really help you. This part of the code should be relatively simple compared to actually getting the data. Hope this helps!

kavya_mc

hi..thanks...i got some idea

kavya_mc

hi to read data from my code i wrote the code as below,
void setup() {

  Serial.begin(9600);
}

void loop() {

  int sensorValue1 = analogRead(A0);
    int sensorValue2 = analogRead(A1);
    Serial.println("voltage value=");
    Serial.println(sensorValue1);
    Serial.println(sensorValue2);
  delay (1000);
}
am getting the output as below. It is very inconsistent and random...as per theworking of my sensor he voltage values must increase when the pressure increases. Is there any mistake in prgramming or the way that i have connected the sensor to board? i connected +out pin to A0 and -out pin to A1.
any suggestion will be helpful
thankyou
my output:

voltage value=
374
379
voltagevalue=
359
365
.
.
.
.
.
voltage value=
42
43



Grumpy_Mike

How have you wired it up?
You can't just wire the outputs to the arduino inputs you need some form of bridge exciter.

kavya_mc

yes sir I have connected the sensor outputs directly to arduino.......
can you please tell me what the bridge exciter circuit is.?
Also I wanted to know if the PC can detect two arduino boards simultaneously connected to it?
thank you

Grumpy_Mike

On page 2 of the data sheet at the top there is a diagram. Everything inside the dotted line is your sensor. Everything outside the dotted line is your exciter circuit. In this case it consists of an amplifier and voltage reference that powers or excites the bridge circuit.
However the data sheet also says you get 50mV full scale output from the bridge. That means that at the maximum pressure output you will only get a reading of 10 from the arduino's A/D converter. So it is not very suitable for direct connection.
This sort of sensor needs an amplifier if it is to be of any practical use.
This is a link to the sort of amplifier circuit you need:-
http://www.flickr.com/photos/33177304@N03/4666641155/

Quote
Also I wanted to know if the PC can detect two arduino boards simultaneously connected to it?

Yes it can but only one can talk to the serial monitor built into the arduino IDE. The second will have to use another terminal emulator like freeTerm.

kavya_mc

i connected 2 arduino uno boards to laptop and tried loading blink sketch by opening 2 arduino IDE windows. it worked on one board with COM 15. but for the other its not. i tried selecting COM 4,5,6,9,10,11. but it is showing the error as "avrdude: stk500_getsync(): not in sync: resp=0x00" what should i do so that I can work on both boards simultaneously?

michinyon

I don't understand,  when you say you want to read the sensor,   and then send a message to the arduino if it changes.

Isn't it the arduino which is reading the sensor?   Do you want to send a message to another arduino,  when it changes ?

michinyon

You have connected your sensor wrong.

The connections + and - of the sensor,  you should connect the -ve to your arduino ground  and the +ve to your arduino analog input pin.

You will then read the voltage output by the device.

The other problem is,  the output of this device is 50 millivolts at full scale.   On the arduino analog input,  this will give you a reading of between 0 and 10  (  counts out of 1023 ) only,   because the full range of this device is only 1/100th part of the full analog input range 0 to 5 volts.

The actual values you got, are the difference between your sensor1 and your sensor2 ,  which is 5 or 6 counts on the examples you got,   so it actually looks like it is working.

You can improve the effective A/D range by understanding and using the arduino AREF pin.    You could also use an external amplifier circuit using an op-amp  to increase the size of the signal which the arduino is receiving.





retrolefty

Quote
The connections + and - of the sensor,  you should connect the -ve to your arduino ground  and the +ve to your arduino analog input pin.


That is not how one reads a low level differential output from a Wheatstone bridge circuit. Grounding the -ve pin will just severally unbalance the bridge. See the ground connection at the bottom of the circuit, that is the only connection to be made to an arduino ground pin. The measurement to be made is the difference between -ve and +ve, not the absolute voltage of either of those pins, as they are both at nominally 1/2 of the excitation voltage applied to drive the bridge. An instrumentation type op-amp circuit is needed to both perform the differential measurement between -ve and +ve plus to add gain and also to convert the resulting analog output measurement voltage to a single ended type suitable for reading with an arduino analog input pin.

Lefty

Grumpy_Mike

Quote
You will then read the voltage output by the device.

The point is that there is no voltage output from this sensor because the OP has not connected any excitation voltage to the other two ends of the bridge.
I am not sure why he and michinyon are ignoring the links to my diagrams, I went through all this in the late 80s, but if you want to find out for your self then go ahead. Just don't copy what I said and pretend it is your own work, and then get it wrong to boot.

kavya_mc

sir, i connected a simple opamp amplifier as per the circuit diagram in the data sheet and verified the result. Am still getting random interger values.(both positive and negative)and i referred the circuits in the  link that you sent me. but can you please tell me which circuit to use among them?
i have attached the circuit i tried to read the sensor with. The amplifier A1 that i used was non inverting opamp . output was random integers. can you please suggest any modifications?
thankyou

Grumpy_Mike

Quote
i have attached the circuit i tried to read the sensor with.

No you attached the circuit that is in the data sheet. What did you use? It has to be different because that circuit shows no power supply connection.

Quote
can you please tell me which circuit to use among them?

These were diagrams that accompanied an article.
http://www.doc.mmu.ac.uk/STAFF/A.Wiseman/Acorn/BodyBuild/BB86.html
It is BB37, but basically you need the big one with lots of bits in it.

kavya_mc

ok sir, one last doubt, should i connect the amplifier circuit thatyou suggested in place of A1 in the datasheet or at the output of the sensor?
thankyou for your replies and patience

Go Up