ver 1.0.4

This commit is contained in:
Vattana 2023-05-21 09:16:38 +02:00
parent 53fa7562ec
commit 0203be988a
3 changed files with 12 additions and 17 deletions

Binary file not shown.

View File

@ -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);
digitalWrite(pin, HIGH);
}
void loop() {
sensorVal = analogRead(pin);
voltage = sensorVal * (5.0 / 1023.0);
voltage = sensorVal * (5.0 / 1023.0); //Convert the sensor value to output voltage
//voltageCal = voltage - bias;
//voltageScale = abs(voltageCal / scale);
//voltageScale = (scale*voltageCal)-offset;
angle = map(voltage, 0, 3.3, 0, 180);
//angle = voltage*scale; //calculating the angular value
angle = voltage*54.54;
//angle = map(voltage,0,3.3,0,180);
//Weight = (voltage-offset)/scale;
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);

BIN
~WRL1986.tmp Normal file

Binary file not shown.