My robot

Lesson 2: Sensors & LED

Your robot sense the world using sensors. Sensors are like humans' eyes, skins and ears, which allow us to understand the environment. LEGO EV3 robot has 4 sensor ports as we mentioned before. You also have four different types of sensors, ultrasound sensor, color sensor/light sensor, gyro and touch sensor.

Sensor port assignment

The default sensor assignment is:
  • S1: Color sensor
  • S2: Color sensor
  • S3: Ultrasonic sensor
  • S4: Gyro sensor
To initialize a new sensor assignment, sentences like following can be used at the beginning in the English code:
  • There is a color sensor at S1.
  • Connect a color sensor to S1.

For example,
Connect a touch sensor to S1.
The robot goes forward.
If the robot touches anything, the robot stops.

WARNING

Place the new sensor assignment later in the English code might not be recognized , and would confuses the robot resulting in erroneous program.

Sensor usage

In order to let your robot sense the world, you can say something like:
  • Ultrasound sensor:
    • Get value: Read distance from the ultrasound sensor.
      In this case, the number returned will be saved in a parameter called distance. So you can also say: Read xyz from the ultrasound sensor. The name does not really matter.
    • Use it as "eyes": If the ultrasound sensor sees anything in 10 inches, ...
      In this case, the sensor will check if there is any obstacle within certain range. So called "eyes" are not able to tell the difference between shapes and colors. The robot will only know how far the object is.
  • Color sensor/light sensor: The LEGO EV3 color sensor can measure the reflected red light and ambient light from darkness to brightness, which is a little bit tricky to use when facing rooms with different lighting conditions.
    Luckily, it can detect 8 colors: black, white, blue, green, yellow, red, and brown.
    • Reading colors: Read color from the left color sensor.
      In this case, the number returned will be saved in a parameter called color. So you can also say: Read xyz using the color sensor. The name does not really matter.
    • Use it as "eyes": If the right color sensor sees blue, ...
    • Two color sensors can be used to track lines: If the color sensors see a black line, ...
QUESTION: can you track a line just using one color sensor? (Answer is YES, but how?)
  • Gyro sensor:
    • Using degrees: The robot turns left for 50 degrees
    • Or, check the degrees the robot has turned: If the gyro sensor has turned for 50 degrees, ...
  • Touch sensor:
    • To feel the environment: If the touch sensor touches anything, ...
  • LED:
    • The built-in LED on the LEGO EV3 robot is embedded around the buttons. It has 3 colors: green/ red/ orange, and 3 modes: ON/ flash/pulse.
    • Solid on: The LED turns on in red. OR, Set the LED color to green.
    • Flashing: The LED will be flashing in red.
    • Pulsing: The LED pulses in green.

👈 Previous: Lesson 1 🏠 Homepage 📚 Lesson plan 👉 Next: Lesson 3