FSHS Robotics

Back to Outline

FSHS Robotics C Course

NXT: Setting up Motors and Sensors

Set up a sensor in RobotC

Go to the top menu, select Robot > Motors and Sensors Setup. Switch to the Sensors tab.

There are four sensors that correspond to ports 1 to 4 on your brick.

  1. For S1 (Sensor 1), type in a name such as sensorLeft, and change the type to Light Sensor > Reflected Light (Active).

  2. Connect a light sensor to port 1.

  3. Click OK.

You should now see the following on your code:

#pragma config(Sensor, S1, sensorLeft, sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

That means you’ve set it up correctly! If you ever need to change the sensor name, the third parameter (sensorLeft) can be edited right there, or by going back into Motors and Sensors Setup.

Set up a motor in RobotC

  1. Top menu: Robot > Motors and Sensors Setup. Switch to Motors.

There are three motors for NXT and four motors for EV3 that correspond to ports A to C or A to D respectively.

  1. For motorA (Motor A), type in a name such as motorLeft. You don’t need to change anything else. Reversed checkbox will reverse the motion, if your robot goes backwards.

  2. Connect a motor to port A.

  3. Click OK.

You should now see the following on your code:

#pragma config(Motor, motorA, motorLeft, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

That means you’ve set it up correctly! If you ever need to change the motor name, the third parameter (motorLeft) can be edited right there, or by going back into Motors and Sensors Setup.

You can also do the same for any other motors and sensors you plug in to your robot. Make sure you code so that the motor in the code corresponds to the correct motor connected to the brick!

© Fort Street High School Robotics