■ FIGURE 15:
Pot angle test.
Serial.print(“You set 0 degree to: “);
Serial.println(zero);
}
if(c == ‘b’) // get the 180 degree
// calibration value
{
// read the value from the sensor:
oneeighty = analogRead(sensorPin);
Serial.print(“You set 180 degree to: “);
Serial.println(oneeighty);
■ FIGURE 14:
void loop() {
Pot to ADC photo.
if(Serial.available())
{
char c = Serial.read();
if(c == ‘a’) // get the zero degree
// calibration value
{
// read the value from the sensor:
zero = analogRead(sensorPin);
}
delay(1000);
int val = sensorValue;
val = map(val,zero,oneeighty,0,180);
// the dial is reversed for what we want so we
// reverse the value to get the angle
//val = 180 - val;
myservo.write(val); // use converted angle
Serial.println(val);
❏ This program calibrates the pot to the dial angles by
accepting two commands: ‘a’ for the 0° position; and
‘b’ for the 180° position.
❏ Adjust the pot to point to 0°, then enter and send ‘a’ in
the serial monitor.
❏ Adjust the pot to point to 180°, then enter and send ‘b’
in the serial monitor.
❏ Adjust the pot to point to 90°, then enter and send ’r’ in
■ FIGURE 13:
the serial monitor to read the angle.
Pot to ADC
schematic.
❏ Adjust the pot to various angles and read the angles
with the serial monitor. Note the accuracy or lack of it
for these readings. You should get results similar to
those in Figure 13.
■ FIGURE 16:
Pot motion control
drawing.
72 July 2014