Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by Rich!

Reading Analog Port

Need help with what steps are missing when making a decision during an "IF" leg

# Two IR units, Front_IR and Rear_IR will be monitored for
# possible collision from objects in front or behind a
# a moving robot

# Once detected then drive motor control will be adjusted
# to avoid collision

$Front_IR = GetADC(ADC0)
$Rear_IR = GetADC(ADC1)

# Normal values for an ADC port are from 0 to 255
# Collision value should be 100 or less
$Collision = 100

# Now we start up the robot at a low speed - 0 is stop
# and 255 is Max
# Read the ADC port value

$Read_Front = $Front_IR

IF ($Read_Front <= $Collision)


No matter what the ADC0 port value is, the GOTO is not performed when the port value changes from 196 to 3.


Upgrade to ARC Pro

Get access to the latest features and updates with ARC Early Access edition. You'll have everything that's needed to unleash your robot's potential!

AI Support Bot
Related Content
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
United Kingdom
Try changing the READ_ADC part to;


$Read_Front = GetADC(ADC0)

I suspect, although am not entirely sure that the $Front_IR variable is only actually checked at the very start of the code and the value stored, then by using $Read_Front = $Front_IR all you are doing is saving the same value that was once got.

In other words;

$Read_Front checks the ADC port and returns a value of 120.
$Read_Front is now 120
When you use the code $Front_IR = $Read_Front you are saving this 120 to $Front_IR too. So the ADC value is only really gotten once and then the variable remains the same throughout the script.

If you wanted the values of the IR sensors read multiple times in the script and wanted to save coding you could do a small sub routine;


$Front_IR = GetADC(ADC0)
$Rear_IR = GetADC(ADC1)

Then where you need to check the values simply



The script will jump to the label, perform the GetADCs then return to where it was.
Your suspicion was correct Rich, The statements were getting a reading and storing it and the same value was used for decision making and since once the ADC port value was saved the script did not revisit the ADC port and update the values.

That explains why the IF statement worked if I held my hand up to the IR sensor and then started the script. Thanks for the helpful clues.