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; Servo serv;
//Global variable
int pin = A0; //input Velostat pin int pin = A0; //input Velostat pin
int pinServo = 9; //servo pin int pinServo = 9; //servo pin
float sensorVal; float sensorVal;
float voltage; float voltage;
float voltageCal;
float voltageScale;
float angle; float angle;
float Weight; float weight;
//Calibration //Calibration
float offset = 2.585; //float scale = 54.54;
float scale = -0.0008;
float bias = 11;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
serv.attach(pinServo); //attach servo pin serv.attach(pinServo); //attach servo pin
pinMode(pin,INPUT_PULLUP);
pinMode(pin,INPUT_PULLUP);
digitalWrite(pin, HIGH); digitalWrite(pin, HIGH);
} }
void loop() { void loop() {
sensorVal = analogRead(pin); 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 = voltage*54.54; angle = map(voltage, 0, 3.3, 0, 180);
//angle = map(voltage,0,3.3,0,180); //angle = voltage*scale; //calculating the angular value
//Weight = (voltage-offset)/scale;
weight = 3.304-voltage/0.436; //calculating weight using calibration curve equation
//Serial Printing //Serial Printing
Serial.print(sensorVal); Serial.print(sensorVal);
Serial.print(" , "); Serial.print(" , ");
Serial.print(voltage); Serial.print(voltage);
Serial.print(" , "); Serial.print(" , ");
Serial.print(Weight); Serial.print(angle);
Serial.print(" , "); Serial.print(" , ");
Serial.println(angle); Serial.println(weight);
serv.write(angle); serv.write(angle);

BIN
~WRL1986.tmp Normal file

Binary file not shown.