a1tQ2000009VJVqIAO

Course: AI LAB- Level 2
Intro to I-O with Magic Box

  • 6-12 grade
  • Intermediate

Lesson Description:

Sensors are all around us helping control various forms of automation in our daily lives. They range from simple proximity sensors that activate automatic doors to the light sensors in your car that automatically turn on and off your headlights. These sensors provide the needed feedback that help control various devices.

Sensors in an industrial environment work in the same manner. They can inform an operator when a machine is low on coolant or help add intelligence to a robotic arm that allows workers to safely work side by side with it in the same environment. This activity will explore how inputs and outputs work and how they may be programmed.


KEY VOCABULARY

  • Sensors
  • Inputs
  • Outputs
  • Magic Box
  • Digital
  • Analog
  • Normally Open (NO)
  • Normally Closed (NC)


EQUIPMENT & SUPPLIES

  • Dobot Magic Box
  • Digital - 2-Button Input Module
  • Analog – Potentiometer Module
  • LED Module
  • Common Sensor Cables
  • 12V Power Cable and Supply
  • USB C to A Cable

image description

Lesson Modules


Teaching Tips:

SECTION 1 – WIRING the MAGIC BOX AND SENSORS

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

Step 1 – Gather Components

For this activity, you will need:

  • 1x Magic Box
  • 1x USB-A to USB-C Cable
  • 1x AC/DC Power Adapter (12 V)
  • 3x Common Sensor Cables
  • 1x Dual Button Sensor – PORT 2
  • 1x Potentiometer Sensor – PORT 4
  • 1x LED Module – PORT 6
Components laid out

Step 2 – Wire the Magic Box

Wire the Magic Box with sensors as shown.

The LED has two ports, one is an input, and one is an output used to connect multiple devices together. Be sure to plug it into the Magic box using the port that is farthest from the LED’s.

Helpful tip 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.

Magic Box wiring diagram

SECTION 2 – DEFINING INPUTS AND OUTPUTS

INPUTS – Defined as any data or signals that a robot receives that provides feedback about its environment. Information that is brought “into” the controller.

Examples: Sensor Values, Signals from another Device or Robot, User Commands.

OUTPUTS – Defined as an outgoing device or signal that is controlled by the robot. An output is often something that the robot can turn on or off like a light. An output can also be a value that is produced by the robot’s programming.

Examples: LED, Sound, Motor ON/OFF, Motor Speed and Direction Control, Electromagnet, Vacuum Gripper.

Input/Output Input/Output

SECTION 3 – DEFINING DIGITAL & ANALOG INPUTS

DIGITAL INPUT / SIGNAL – Defined as a signal that can only be read in one of two states: YES or NO, ON or OFF, TRUE or FALSE, HIGH or LOW.

Digital sensors are often wired as either Normally Open (NO), or Normally Closed (NC). When a digital sensor is wired NO, no signal is received until the sensor is triggered. Once the sensor is active, it reports a high or true signal to the controller. Most often this signal is controlled by electric current or voltage (voltage present or not present). Sensors wired NC work in the opposite state.

Examples: Limit Switch, IR Photoelectric Sensor, Inductive Sensor

ANALOG INPUT / SIGNAL – Defined as a type of signal that has a range of values. This value is often affected by the intensity or magnitude of a measured external quantity (something found in the robot’s environment like light or sound).

Examples: Potentiometer, Color Sensor, Humidity Sensor, Light Sensor

Input/Output Input/Output

SECTION 4 – CONNECTING the MAGIC BOX to DOBOTLAB

Step 3 – Open DobotBlock Lab

Open up DobotBlock Lab in the software.

Input/Output Input/Output

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.

Step 4 – Power On & Initial Connections

  1. Once all of the wiring is done (sensors connected), power ON the Magic Box
    • Dual Button Sensor – PORT 2
    • Potentiometer Sensor – PORT 4
    • LED Module – PORT 6
  2. You do not need a robot for this activity. Delete both the Magician and Magician Lite Devices. Note: This will then default to the Sprite tab once there are no devices loaded.
  3. Click back on the devices tab and click on Choose a Device.
  4. Device selection screen
  5. Select the Magic Box.
  6. Connect to the Device.
  7. Device selection screen
  8. For this activity, we will need to add an EXTENSION to use the MAGIC BOX. Click the EXTEND icon in the bottom left corner.
  9. 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

Teaching Tips:

SECTION 5 – EXPLORATION ­– DIGITAL INPUTS & with OUTPUTS

SKILL BUILDER 1 – LED MODULE – DIGITAL OUTPUT

Step 5 – LED Basics

  1. The first device used in this activity is the LED OUTPUT MODULE.
  2. From the AI SENSOR KIT toolbox, LIGHT CATEGORY, drag over the LED RGB and LED STATE blocks.
    Settings: PORT 6, LIGHT 1
  3. Now turn on the FIRST LED as RED for 3 seconds, then turn off the LED STATE and end the program.

The values to the right are examples of the values used to establish a specific color for the LED Module. The combination of R255 G0 B0 sets the color RED

Helpful tip TEST your code, troubleshoot if necessary.
Be sure the LED module is plugged in correctly and the port is called out correctly.

Helpful tip Can you make the LED display a color like Chartruese? Or Cyan? Look up what those colors are on the internet and see if you can make one of these colors with one of the LED’s!

Device selection screen Device selection screen Device selection screen

Step 6 – Multiple LEDs

Next turn on all three LEDS, 1 = RED, 2 = GREEN, 3 = BLUE for 3 seconds

From the AI SENSOR KIT toolbox, LIGHT CATEGORY, drag over the LED RGB and LED STATE blocks.

Device selection screen

If the program does not call for the LED Outputs to turn OFF at the end of the program, they will stay on even after the program has ended.

Helpful tip Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it until it does.

Can you make the LED display one after the other for ½ a second each? Can you make the LED’s “chase” one another? How?

Device selection screen

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

SKILL BUILDER 2 – DUAL BUTTON – DIGITAL INPUT

Step 7 – Button Variables

  1. The second device in this activity is the DIGITAL DUAL BUTTON INPUT MODULE.
  2. Since the DUAL BUTTON MODULE is an Input signal, we need to create a way to “SEE” the values that the sensor is reporting to the Magic Box (ON/OFF, 1/0).
  3. Create TWO new variables (RED and BLUE) and set their initial values to ZERO.
Device selection screen Device selection screen

Helpful tip As long as there are check marks next to the variables you created, they should appear in the SPRITE window.

Input/Output Input/Output

Step 8 – IF / ELSE Logic

  1. Setup two separate IF/ELSE Statements.
  2. CONDITIONS: If the Button is pressed, set the Variable to ONE, else set it to ZERO.

  3. From the AI SENSOR KIT toolbox, SENSOR CATEGORY, drag over the DUAL BUTTON MODULE blocks and place it inside one of the IF/ELSE Statements.
    Settings: PORT 2, RED
  4. This will serve as the condition for this statement. These sensors are wired NORMALLY OPEN (NO).
    BUTTON PRESSED = TRUE (ON, 1)
    BUTTON NOT PRESSED = FALSE (OFF, 0)

  5. Next, setup what we want the IF STATEMENT to DO. Drag the SET Variable block into both parts of the IF STATEMENT.
    STATEMENT IS TRUE = VARIABLE is 1
    STATEMENT IS FALSE (ELSE) = VARIABLE is 0

  6. Repeat this process for the other IF/ELSE statment (or duplicate the first one and change the values).

  7. You need to continuously evaluate these sensors to see when they are true and false. To do this, we will put them inside a forever loop
Device selection screen Device selection screen Device selection screen Device selection screen Device selection screen

Helpful tip Notice that the IF/ELSE STATEMENTS do not have repeat arrows at the bottom of them. IF STATEMENTS will only be evaluated at the start of each loop. If they are true, they will run the entire process inside the IF portion, FALSE, everything inside the ELSE portion. IF STATEMENTS then move onto the next section of code (NO REPEAT). Both of our Statements do not have a perceivable time needed to run the code and move on, this will allow both buttons to be pressed at the same time and both return true conditions.


Add a Micro Wait inside the Forever Loop.

Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it until it does.

Device selection screen

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


SKILL BUILDER 3 – POTENTIOMETER KNOB – ANALOG INPUT

Step 10 – Potentiometer Reading

  1. The Third device used in this activity is the POTENTIOMETER KNOB INPUT MODULE. This device is an analog input.
  2. Since the POTENTIOMETER MODULE is an Input signal, create a VARIABLE as a way to “SEE” the values the sensor is reporting to the Magic Box.
  3. Create a new variable (POTENT) and set its initial value to ZERO. This will clear out any initial values for this variable.
  4. Next inside a FOREVER LOOP block, assign the variable’s value to the sensor’s value.
  5. From the AI SENSOR KIT toolbox, SENSOR CATEGORY, drag over the KNOB POTENT VALUE block.
    Settings: PORT 4
  6. Drag the sensor’s value into the SET VARIABLE block.
  7. Place a SMALL MICRO WAIT (0.2) after setting the variable to the sensor’s value before it repeats the loop.
Device selection screen Device selection screen Device selection screen Device selection screen Device selection screen

Helpful tip Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it until it does.

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

  1. What was the Highest Value the sensor reported?
  2. What was the Lowest Value the sensor reported?
  3. Which direction increases the value (CW / CCW)
  4. Device selection screen

CHALLENGE
SECTION 6 – CONTROL OUTPUTS WITH INPUTS

Challenge Scenario:  ALL of the conditions below are in the same program

  • When the BLUE button is pressed, LIGHT 1 will turn BLUE
  • When the RED button is pressed, LIGHT 3 will turn RED
  • The corresponding lights will be OFF when the corresponding buttons are NOT pressed
  • Divide the POTENTIOMETER High value into thirds –
  • **NOTE – Use GREATER THAN, LESS THAN, and possibly the AND OPERATORS for the next portion to create the needed conditions (Hexagon Shapes) for the analog sensor?
  • When the POTENTIOMETER value is in the bottom third or the top third, LIGHT 2 will be WHITE
  • When the POTENTIOMETER value is in the middle third, LIGHT 2 will be YELLOW
Device selection screen

Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it until it does. SHOW YOUR INSTRUCTOR WHEN THE CHALLENGE IS COMPLETE

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


Teaching Tips:

CONCLUSION

  1. What type of values are reported from analog sensors?
  2. What type of sensors would be would you find in an automated vehicle? List as many as you can think and identify them as analog or digital.
  3. What type of sensors might a robot use/need to allow people to work near the robot or inside its work envelope?
  4. What are the RGB values for

    MAGENTA:    ORANGE:    GREY:

GOING BEYOND

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

  • RED BUTTON is pressed, LIGHT TURNS RED, but only for 3 seconds (even if the button is still held)   _________
  • ALL three lights are off unless, the red button and the blue button are pressed and held as well as the potentiometer is at its lowest setting.
    If all three conditions are met, make all three lights turn magenta… until the three conditions are not met again.   _________
  • When the RED BUTTON IS PRESSED make the 3 LED’s “chase” one another to the right as RED. When the BLUE BUTTON IS PRESSED, make the LED’s “chase” one another to the left 5 times as BLUE.   _________
  • When the POTENTIOMETER is in the FIRST THIRD OF ITS TRAVEL Turn on the LED TO RED. When the POTENTIOMETER is in the MIDDLE THIRD OF ITS TRAVEL Turn on the LED TO YELLOW. When the POTENTIOMETER is in the LAST THIRD OF ITS TRAVEL Turn on the LED TO GREEN.   _________