Color Controlled LEDs

Color Controlled LEDs

Hello everyone! For this project, we will show you how to create a basic color controlled LED pattern guided by color recognition using the VIA Pixetto vision sensor, three LEDs (with sockets), four Grove cables, an expansion board, and an Arduino board. The LEDs will perform three different light patterns. The LED (light-emitting diode) is a semiconductor light source that emits light.

Alright, let’s get started!

The guide will involve four simple steps:

Step 1: Configuring the VIA Pixetto

Step 2: Assembling all components for the color controlled leds

Step 3: Programming the VIA Pixetto with Blocks

Step 4: Uploading the code to the Arduino board and saving the project

Step 1

You need to configure the VIA Pixetto to recognize three different colors.

First, connect the VIA Pixetto to your PC using a Micro USB 2.0 cable.

When the green, blue, and red LEDs are lit, this means the VIA Pixetto is successfully connected.

Open the VIA Pixetto Utility and configure the VIA Pixetto to recognize the colors red, blue, and yellow.

Once you have finished configuring the VIA Pixetto, test it to make sure it can detect red, blue, and yellow objects.

Step 2

Put together all the components to build the Color Controlled LEDs. These include the VIA Pixetto, three LED lights (with sockets), four Grove cables, an expansion board, and an Arduino board.

First, attach the expansion board to the Arduino board via the pin header connectors.

Secondly, connect a Grove cable to each LED (LED 1, LED 2, and LED 3) through its sockets.

Then, attach the LED 1, LED 2, and LED 3 to the Grove connectors labeled D2, D3, and D6 respectively on the expansion board, which in turn is attached to the Arduino board.

Next, connect the Grove cable to the VIA Pixetto.

Then, attach the VIA Pixetto to the Grove connector labeled ‘UART’ on the expansion board.

Step 3

You need to program the VIA Pixetto with Blocks so that the LEDs will activate and perform the different light patterns when detecting red, blue, and yellow objects.

First, open the VIA Pixetto Junior application.

A. First Layer of Blocks

Select the first layer from the Control category, which is the ‘setup’ block.

Add the ‘initialize vision sensor RX# () TX# ()’ block from the Vision Sensor category.

Place it within the ‘setup’ block. This block will relate information to the VIA Pixetto vision sensor.

Select pin ‘0’ and ‘1’. This makes sure there is a connection between the Arduino board and VIA Pixetto vision sensor. RX means Receive, and TX means Transmit. We recommend using pins ‘0’ and ‘1’, because it is more reliable.

B. Second layer of Blocks

From the Control category, select the ‘if () then’ block to create an event. Next, go back to the Vision Sensor category and select the ‘object is detected’ block. Insert the ‘object is detected’ block inside the ‘if () then’ block. This makes the VIA Pixetto report that it is detecting an object via a command from the Arduino board. If this condition is true, the block inside will activate the event.

Color Controlled LEDs

Next, program the blocks to control the LEDs’ behaviour. You want to make sure that when the VIA Pixetto detects an object, the LEDs will perform the specific light patterns.

To make this true, use another ‘if () then’ block from the Control category to create an event. Insert the second ‘if () then’ block into the first ‘if () then’ block.

Color Controlled LEDs

● Light Pattern #1

Create the blocks for light pattern #1.

Select a ‘logic’ block from the Logic category. Then, select the ‘object type’ block and ‘red’ block from the Vision Sensor category. Insert an ‘object type’ block and ‘red’ block into the ‘logic’ block. Then, set the ‘logic’ block to ‘=’ sign.

Color Controlled LEDs

Put the ‘logic’ block inside the second ‘if () then’ block. This makes the VIA Pixetto report that it is detecting an object that is red. If this condition is true, the blocks inside will activate the event which is light pattern #1.

Color Controlled LEDs

Next, select three ‘LED light pin () status ()’ blocks from the Output Unit category and put them together.

Set the pins to pin 2, 3, and 6, and then set each status to ‘high’. This makes the three LEDs turn on.

Color Controlled LEDs

Then, insert the three ‘LED light pin () status ()’ blocks into the second ‘if () then’ block.

Color Controlled LEDs

Next, select a ‘delay ()’ block again from the Control category. Set the ‘delay ()’ block to 200 milliseconds, and then put it underneath the previous block.

Color Controlled LEDs

Next, duplicate the three ‘LED light pin () status ()’ blocks and the ‘delay ()’ block that you have created earlier.

This time, set the status of the ‘LED light pin () status ()’ blocks to ‘low’.

This makes the three LEDs turn off. Then, keep the ‘delay ()’ block to 200 milliseconds.

Color Controlled LEDs

Then, insert them into the second ‘if () then’ block as shown in the diagram below.

Color Controlled LEDs

You have successfully created the blocks for your light pattern #1.

● Light Pattern #2

Create the blocks for light pattern #2.

Click on the gear icon on the second ‘if () then’ block to open its scrolling menu, then drag the ‘else if’ block underneath the ‘if’ block for the next event which is light pattern #2.

Color Controlled LEDs

Next, select a ‘logic’ block from the Logic category. Then, select the ‘object type’ block and ‘blue’ block from the Vision Sensor category. Insert an ‘object type’ block and ‘blue’ block into the ‘logic’ block. Then, set the ‘logic’ block to ‘=’ sign.

Color Controlled LEDs
Color Controlled LEDs

Put the ‘logic’ block inside the ‘if () then else if then’ block. This makes the VIA Pixetto report that it is detecting an object that is blue. If this condition is true, the blocks inside will activate the event which is light pattern #2.

Color Controlled LEDs

Next, select six ‘LED light pin () status ()’ blocks from the Output Unit category, and four ‘delay ()’ blocks from Control category.

Arrange the six ‘LED light pin () status ()’ blocks, and set the pins and status as follows:

Color Controlled LEDs

Then, set the four ‘delay ()’ blocks to 200 milliseconds.

Next, put all six ‘LED light pin () status ()’ blocks and the four ‘delay ()’ blocks together. Then, insert them into the ‘if () then else if then’ block as shown in the diagram below.

Color Controlled LEDs

You have successfully created the blocks for light pattern #2.

● Light Pattern #3

Create the blocks for light pattern #3.

Click again the gear icon on the second ‘if () then’ block to open its scrolling menu, then drag the ‘else if’ block underneath the ‘else if’ block for the next event which is light pattern #3.

Color Controlled LEDs

Next, select a ‘logic’ block from the Logic category. Then, select the ‘object type’ block and ‘yellow’ block from the Vision Sensor category. Insert an ‘object type’ block and ‘yellow’ block into the ‘logic’ block. Then, set the ‘logic’ block to ‘=’ sign.

Color Controlled LEDs
Color Controlled LEDs

Put the ‘logic’ block inside the ‘if () then else if then’ block. This makes the VIA Pixetto report that it is detecting an object that is yellow. If this condition is true, the blocks inside will activate the event which is light pattern #3.

Color Controlled LEDs

Next, select twelve ‘LED light pin () status ()’ blocks from the Output Unit category, and three ‘delay ()’ blocks from the Control category.

Arrange the twelve ‘LED light pin () status ()’ blocks, and set the pins and status as follows:

Color Controlled LEDs

Then, set the three ‘delay ()’ blocks to 100 milliseconds.

Next, put all twelve ‘LED light pin () status ()’ blocks and three ‘delay ()’ blocks together. Then, insert them into the ‘if () then else if then’ block.

Color Controlled LEDs

Then, select another ‘delay ()’ block. Set the ‘delay ()’ block to 600 milliseconds, and then put it underneath the previous block.

Color Controlled LEDs

Next, duplicate the twelve ‘LED light pin () status ()’ blocks and three ‘delay ()’ blocks that you have created earlier. Then, insert them into the ‘if () then else if then’ block underneath the ‘delay 600 milliseconds’ block.

Color Controlled LEDs

Select the ‘repeat while’ block from the Control category. Then, select the ‘object is detected’ block from the Vision Sensor category. Insert the ‘object is detected’ block inside the ‘repeat while’ block.

Color Controlled LEDs

Then, put the ‘repeat while’ block underneath the ‘if () then else if then’ block as shown in the diagram below.

Color Controlled LEDs

You have successfully created the blocks for light pattern #3.

Review the composed blocks. Double check the pins, and the delay time values to make sure they are correct.

Step 4

Upload the code to the Arduino board and save the project.

A. How to upload the code

  1. Connect the Arduino board to your PC using the Micro USB 2.0 cable.
  2. Click the ‘No Hardware’ dropdown arrow on the top left corner of the VIA Pixetto Junior application, and then select the ‘Arduino UNO’ to start establishing the connection.
  3. Click on the ‘Not Connected’ dropdown arrow. A pop-up screen will appear. Click the ‘Connect’ button to establish the connection. You can use the ‘Refresh’ button if the USB connection is not found on the PC. The COM port is set to COM9 (Note: The COM port number may vary depending on your PC’s configuration).
  4. Click on the ‘Go to Editor’ button to go back to the VIA Pixetto Junior application.
  5. Click the ‘Upload’ button on the right side of the VIA Pixetto Junior application to upload the code to the Arduino board. Wait until the ‘Upload Success’ message appears before unplugging the cable.

B. How to save your project

  1. Click on the icon next to the ‘Project’ to open its scrolling menu.
  2. Select the ‘Save Project As’.
    When you click on the ‘Save Project As’ a window pop-up will appear on the screen and you can name the project ‘Color Controlled LEDs’. Feel free to choose whatever name you like.
  3. Create or find a suitable folder to keep all your projects.

Now that you have connected the VIA Pixetto vision sensor, attached the LEDs, and uploaded the code to the Arduino board, it is time to do some test with your Color Controlled LEDs.

Have fun with this project and do not forget to share your own blocks creations with us on Instagram, Facebook, and Twitter at #VIAPixetto!

Share this blog post!

Share on linkedin
Share on twitter
Share on facebook

Leave a Reply