Force Sensor

02 Nov 2011

Beginner to C++, but I have some experience with java. I am looking to make a program to take a voltage input from a force sensor on one of its pins. Then I need to translate that voltage into a force. So after testing the sensor I would come up with a calibration curve that when I plug the voltage into it, an accurate force is the output. I then need to take that force output and display it on a LCD screen. So far I have found bits and pieces of the program on this website. I have also programmed some stuff myself, but just not confident it will work. Any input will be appreciated. My program is pretty simple right now, but I don't think the end result will be too complicated just need some help. The file is my program that I have done so far in a text doc. Thanks! /media/uploads/drew21/pinch.rtf

02 Nov 2011

A few suggestions:

  • You need to add the TextLCD library to your project.
  • The LCD can use any other unused I/O pin, so there should be no conflict.
  • The value of voltageIn on the ADC input will be a value between 0.0 and 1.0 so multiplying by it 5 will never give you a value greater than 5.
  • You can include short code segments in your posts, nicely formatted. See the Editing tips link underneath the post entry box, on the page you are posting on. Here is an example:

#include "mbed.h"
#include "TextLCD.h"

Hope that helps you move along a bit further.

02 Nov 2011

you have

double voltageIn = ain; 

you need

double voltageIn = ain.read();

you have

double force= voltageIn*5; //better calibration once tests performed 

to get the actual voltage, try..

double actualVoltage = voltageIn * 3.3; 

or 

double actualVoltage = ain.read() * 3.3;

hope that helps a bit.

I'm a beginner in C myself.

09 Nov 2011

Thanks for the responses they have really helped. I am running into some problems with my program once again. I want my LCD screen to display numbers out to 2 decimal places. In java I know you can do something like "%1$.2f" to round a number. Is there similar code for C++. In addition, when I try to compile my program it says that the LCD can't display doubles. How can I get around this?

lcd.printf("The maximum force over 5 seconds is: '\n" <<maxForce<<);//maxForce is a double

Also, I want the mbed to continually read the voltage in for five seconds, and display the countdown on the lcd at the same time. My fear is that if I add a timer to the loop the voltage will only be checked once a second. Is it possible to avoid this?