360 angle sensor working 0-5 Volt where 0 Degree is 0 Volt and 359 Degree is 5 Volt. I am trying to limit minimum and maximum working positions with two potentiometers.
eg. Sensor is installed with 5 degree offset, so i need to use first potentiometer to give a value of 0, then rotate to sensor 100 degree (so total 105 degree), then need to use second potentiometer to give a value of whatever i want between 1 and 500. I want to keep values between 0 and setpoint value according to rotation of the angle sensor.
Stuck in code :
// Analog Sensor is installed in rotational axis joint of Arm
// The Arm shall move to Zero Point and set to 0 with Minimum Potentiometer (whatever value get from Analog Sensor)
// The Arm shall move to Maximum Point and set to Maximum Value with Maximum Potentiometer (whatever value get from Analog Sensor)
// Maximum Value shown is in centimeters
// System Reset
// Measure with Angle Sensor
// Maximum Measurement is 500 centimeters
const int minPin = A0; // Potentiometer for Zero Point
const int maxPin = A1; // Potentiometer for Max Point
const int sensorPin = A2; // Analog Sensor 0..5V for Angle Measurement (0 V = 0 Degree...5 V = 359 Degree)
int minValue = 0; // Sets Minimum Value
int maxValue = 0; // Sets Maximum Value
int sensorValue = 0; // Sensor Value
int minOffset = 0; // Minimum Measurement Value 0
int maxOffset = 500; // Maximum Measurement Value 500
int calculated = 0; // Calculated Value
void setup() {
Serial.begin(9600);
}
void loop() {
minValue = analogRead(minPin); // Read Potentiometer for Minimum
maxValue = analogRead(maxPin); // Read Potentiometer for Maximum
minValue = map(minValue, 0, 1023, 0, 500);
maxValue = map(minValue, 0, 1023, 0, 500);
Serial.print("Min: ");
Serial.println(minValue);
Serial.print("Min: ");
Serial.println(maxValue);
sensorValue = analogRead(sensorPin); // Read Analog Angle Sensor
sensorValue = map(sensorValue, minValue, maxValue, 0, maxOffset);
Serial.print("Sensor: ");
Serial.println(sensorValue);
calculated = ((maxValue - minValue) / sensorValue);
Serial.print("Calculated: ");
Serial.println(calculated);
delay(500);
}
Stuck in code :
Stuck how ?
What happens when you run the program ?
How are the pots wired ?
It does not give me right values, minimum pot mid leg is connected to Analog 0 and maximum pot mid leg is connected to Analog 1, the sensor is connected to Analog 2
Do the maxValue and minValue values look OK before and after you map() them ?
Do they change appropriately when you move the pot wipers ?
How exactly are the pots wired ?
Minimum Pot : 1st-GND / 2nd-A0 / 3rd-5V
Maximum Pot : 1st-GND / 2nd-A1 / 3rd-5V
I only use pots for calibration, on every next restart of power on-off i do not use.
I have revised the code a bit, but still not like the way that i want 
// Analog Sensor is installed in rotational axis joint of Arm
// The Arm shall move to Zero Point and set to 0 with Minimum Potentiometer (whatever value get from Analog Sensor)
// The Arm shall move to Maximum Point and set to Maximum Value with Maximum Potentiometer (whatever value get from Analog Sensor)
// Maximum Value shown is in centimeters
// System Reset
// Measure with Angle Sensor
// Maximum Measurement is 500 centimeters
const int minPin = A0; // Potentiometer for Zero Point
const int maxPin = A1; // Potentiometer for Max Point
const int sensorPin = A2; // Analog Sensor 0..5V for Angle Measurement (0 V = 0 Degree...5 V = 359 Degree)
int minValue = 0; // Sets Minimum Value
int maxValue = 0; // Sets Maximum Value
int sensorValue = 0; // Sensor Value
int minOffset = 0; // Minimum Measurement Value 0
int maxOffset = 0; // Maximum Measurement Value
int calculated = 0; // Calculated Value
void setup() {
Serial.begin(9600);
}
void loop() {
minValue = analogRead(minPin); // Read Potentiometer for Minimum
maxValue = analogRead(maxPin); // Read Potentiometer for Maximum
minValue = map(minValue, 0, 1023, 0, 400);
maxValue = map(maxValue, 0, 1023, 0, 400);
Serial.print("Min: ");
Serial.println(minValue);
Serial.print("Max: ");
Serial.println(maxValue);
// sensorValue = map(sensorValue, 0, 1023, 0, (maxValue - minValue));
// minOffset = minValue;
maxOffset = maxValue - minValue;
sensorValue = analogRead(sensorPin); // Read Analog Angle Sensor
sensorValue = constrain(sensorValue, 0, maxOffset);
Serial.print("Sensor: ");
Serial.println(sensorValue);
Serial.println();
delay(500);
}
In above example, i set minimum potentiometer to value 100, and the maximum potentiometer to value 400, so i can measure between 0 to 300 accordingly, and after some point it never measures over 300 as i limit the value.
The limit on end seems work but not for the start 
In above example, i set minimum potentiometer to value 100
How and where do you do this ?
UKHeliBob:
How and where do you do this ?
I get the value by turning the minimum potentiometer, the 500 is also set by turning the maximum potentiometer. I am able to read minimum and maximum offsets with two potentiometers.
Did you try to change the constain minimum value ?
sensorValue = constrain(sensorValue, 0, maxOffset);
Always 0 ?
Yes, i tried with constrain to limit minimum and maximum but did not worked 
The schema as follows :
https://ibb.co/dArLXS