a1tQ2000009ZTefIAG

Course: AI LAB- Level 2
Color Sensor with Magic Box

  • 6-12 grade
  • Intermediate

Lesson Description:

A Color Sensor is an analog input device that allows technologists, engineers, and others, to add an additional level of intelligence to their programs written  for a robot.  These types of sensors can be used for processes that require the need to distinguish between different products, detect data coding, or even determine if a product may have a defect that is distinguished by varying color. 

Color sensors can often be found in automation processes that involve textiles, paints, food, printing, and even pharmaceuticals. 


KEY VOCABULARY

  • Color Sensor
  • Magic Box
  • Input
  • Analog


EQUIPMENT & SUPPLIES

  • Dobot Magic Box
  • 12V Power Cable and Supply
  • Color Sensor
  • USB C to A Cable
  • LED Module
  • Printed – Color Test Template
  • Common Sensor Cables

image description

Lesson Modules


Teaching Tips:

PROCEDURE

SECTION 1 – WIRING the MAGIC BOX AND SENSORS

Caution: NEVER wire anything to the Magic Box while it has power on. ALWAYS turn it off before making connections or damage to the Controller could occur. Be sure to ask your instructor if you have any questions.

  1. For this activity, you will need:
    • 1x Magic Box
    • 1x USB-A to USB-C Cable
    • 1x AC/DC Power Adapter (12V)
    • 2x Common Sensor Cables
    • 1x Color Sensor – PORT 4
    • 1x LED Module – PORT 6
  2. Wire the Magic Box as shown to the right
Wiring diagram for Magic Box and sensors

Caution: MAKE SURE THE TAB IS PRESSED DOWN ON THE WHITE CONNECTOR WHEN DISCONNECTING ALL SENSORS!!! It is very easy to damage the sensors if the white connector is pulled or tugged on without pressing down the small white tab to release the cable from the sensor housing. 

SECTION 2 – CONNECTING the MAGIC BOX to DOBOTLAB

  1. Open up DobotBlock Lab in the software.
DobotLab DobotBlockLab
  1. Once all of the wiring is done (sensors connected), power ON the Magic Box
  2. No robot is necessary for this activity. Delete both the Magician and Magician Lite Devices.
    Note: This will send you over to the Sprite tab once there are no devices loaded.
  3. Click back on the devices tab and click on Choose a Device
    Device selection screen
  4. Select the Magic Box
  5. Connect to the Device
    Device selection screen
  6. For this activity, you will need to add an EXTENSION to use the MAGIC BOX.  Click the EXTEND icon in the bottom left corner. 
    Click on “+ Add extension” for the AI SENSOR KIT.
Device selection screen Device selection screen Device selection screen Device selection screen Device selection screen Device selection screen

SECTION 3 – EXPLORE COLOR SENSOR

The color sensor can produce two different sets of values. 
1. The sensor can identify the color of the object and return a set of RGB values
2. The sensor can identify six preset colors and return a true value if one of these colors are detected.
BLACK, WHITE, RED, GREEN, BLUE, YELLOW

ANY GREEN 
PORT 

PORT 1-6

Wiring diagram for Magic Box and sensors

SKILL BUILDER 1 – FIND INDIVIDUAL VALUES FOR RED / GREEN / BLUE

  1. Drag over a Color Sensor Color Value block from the AI SENSOR KIT toolbox

    This block will report a separate numeric value for the amount of R, G, B the sensor sees.
  2. Change the PORT value to the port you are using
  3. Next, create three separate VARIABLES RED / GREEN / BLUE
  4. Create the program to the right.

    The 0.2 MICROWAIT will slow down the program. It only allows a new sensor values to be pulled (looked at) every 0.2 seconds
  5. Print a copy of the Color Test Template
  6. Run the program and document the values reported to the variables by the sensor.
Color Sensor Port RED/GREEN/BLUE Color Test Template

Are the values reported to the variables the same or close to the typical values used in industry for each color? 

Is there a pattern to the numbers reported that can be used to alter the variables (a computation / formula) to show a value that better represents the values expected? If so, what formula computation could be used for the variables? 

Using the grey scale colors, what type of values are reported when no red, green, or blue values are present? 

SKILL BUILDER 2 – DETECT KNOWN COLORS

  1. Drag over a Color Sensor Detected Color block from the AI SENSOR KIT toolbox
  2. This command will report if a specific color is present.
    BLACK, WHITE, RED, GREEN, BLUE, YELLOW

  3. Change the PORT value to the port you are using
  4. One way to use this block is to create sets of IF/ELSE statements. If the color is TRUE/PRESENT set the variable to 1, else set it to 0

Color Sensor Block
  1. Using the same program from TEST 1, create additional variables for the remaining colors (six total).
  2. Create an IF/ELSE statement for EACH color
  3. Helpful tip Ensure the PORT number matches the port you are using and that the color is different for each Statement.

    In previous activities, the SET VARAIBLES have been set to INTERGERS (whole numbers) to represent YES (1) and NO (0). Notice in the example to the right, STRING values (text) can also be used.

  4. Link all of the IF/ELSE statements together inside a FOREVER Block
  5. Insert a small 0.2 second MICROWAIT at the begging of the program to slow the cycle down
  6. Color Sensor Port Blocks
  7. Run the program and document if the colors are seen correctly (circle YES or NO).

Check the “Consistently Box” if the correct color is reported by the sensor (all the time or almost all the time)
or 
Check the “Inconsistently Box” (sometimes) if the value reported by the sensor is often incorrect or sometimes does not read and report the color at all.

Color Sensor Variable Creation Color Sensor Port Blocks Color Sensor Port Blocks Color Sensor Port Blocks

Teaching Tips:

CHALLENGE

SECTION 4 – USE the COLOR SENSOR TO CONTROL THE LED

  1. Use the values reported by the color sensor to control the color of LED1

    As the color sensor is held over the Color Test Template, the color of the LED 1 will change color to match the color seen (sensor reports RED, LED becomes RED).
  2. As an added level of intelligence to your program, have the variables show the value received as well.
Color Sensor Port Blocks
  • The LED will show no color when black is received.
  • Do not use the grey scale for this activity.
  • Do not use ORANGE and MAGENTA for this activity.

Continue to test your program until it works as needed. 

If your set up did not work correctly the first time, what did you have to do to make it work?

CONCLUSION

  1. How accurate was the color sensor at displaying RGB values?
  2. How accurate was the color sensor at determining colors from the color test template?
  3. Would you be able to determine the color of the cubes provided by your instructor using this color sensor? Defend your answer, and then try it.
  4. Explain how you might be able to use the robot with the color sensor. What tasks will you be able to do with it?

GOING BEYOND

Finished early? Try some of the actions below. When finished, show your instructor and have them initial on the line.

  • _________  1. Get some colored cubes from your instructor. Write a program to determine the color of the blocks (hint: this is already done) Test it. How accurate is it at determining block color?
  • _________  2. Program the LED to mimic the color of at least 4 different color blocks. Example: (Red Block? Red LED turns on, ect.)