ver 1.0.4
This commit is contained in:
parent
53fa7562ec
commit
0203be988a
Binary file not shown.
|
|
@ -2,48 +2,43 @@
|
|||
|
||||
Servo serv;
|
||||
|
||||
//Global variable
|
||||
int pin = A0; //input Velostat pin
|
||||
int pinServo = 9; //servo pin
|
||||
|
||||
float sensorVal;
|
||||
float voltage;
|
||||
float voltageCal;
|
||||
float voltageScale;
|
||||
float angle;
|
||||
float Weight;
|
||||
float weight;
|
||||
|
||||
//Calibration
|
||||
float offset = 2.585;
|
||||
float scale = -0.0008;
|
||||
float bias = 11;
|
||||
//float scale = 54.54;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
serv.attach(pinServo); //attach servo pin
|
||||
pinMode(pin,INPUT_PULLUP);
|
||||
|
||||
pinMode(pin,INPUT_PULLUP);
|
||||
digitalWrite(pin, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensorVal = analogRead(pin);
|
||||
voltage = sensorVal * (5.0 / 1023.0);
|
||||
|
||||
//voltageCal = voltage - bias;
|
||||
//voltageScale = abs(voltageCal / scale);
|
||||
//voltageScale = (scale*voltageCal)-offset;
|
||||
voltage = sensorVal * (5.0 / 1023.0); //Convert the sensor value to output voltage
|
||||
|
||||
angle = voltage*54.54;
|
||||
//angle = map(voltage,0,3.3,0,180);
|
||||
//Weight = (voltage-offset)/scale;
|
||||
angle = map(voltage, 0, 3.3, 0, 180);
|
||||
//angle = voltage*scale; //calculating the angular value
|
||||
|
||||
weight = 3.304-voltage/0.436; //calculating weight using calibration curve equation
|
||||
|
||||
//Serial Printing
|
||||
Serial.print(sensorVal);
|
||||
Serial.print(" , ");
|
||||
Serial.print(voltage);
|
||||
Serial.print(" , ");
|
||||
Serial.print(Weight);
|
||||
Serial.print(angle);
|
||||
Serial.print(" , ");
|
||||
Serial.println(angle);
|
||||
Serial.println(weight);
|
||||
|
||||
|
||||
serv.write(angle);
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue