How to Synchronize Sound with LEDs using Color Recognition

Hello everyone! For this project, we will show you how to synchronize sound with two LEDs guided by color recognition using the VIA Pixetto vision sensor, two LEDs, expansion board, piezo buzzer, Grove cable and an Arduino board.

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 Sound Synchronize LED

Step 3: Programming the VIA Pixetto with Blocks

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

Step 1

You need to configure the VIA Pixetto to recognize different shapes to control two servo-motors.

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.

Sound Synchronize LED

Open the VIA Pixetto Utility and configure the VIA Pixetto to recognize a blue object.

Once you have finished configuring the VIA Pixetto, test it to make sure it can recognize a blue object.

Step 2

Put together all the components to assemble the Sound synchronize LED. These include the VIA Pixetto, Grove cable, piezo buzzer, two LEDs expansion board, and an Arduino board.

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

Sound Synchronized LED

Then, attach the two LEDs to the Grove connectors labeled D2 and D6 respectively on the expansion board, which in turn is attached to the Arduino board. Lastly attach the piezo buzzer to the Grove connector labeled lab D4.

Sound Synchronized LED

Next, connect the Grove cable to the VIA Pixetto.

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

Sound Synchronize LED

Step 3

You need to program the VIA Pixetto with Blocks so that the LEDs will blink and it will synchronize with the sounds created by the piezo buzzer when detecting a blue color object.

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.

Sound Synchronize LED

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

Sound Synchronize LED

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.

Sound Synchronize LED

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.

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.

Select a ‘logic’ block from the Logic category. Then, select the ‘object type’ block and ‘red’ block from the Vision Sensor category. Then, change the ‘red’ block to ‘blue’.

Sound Synchronized LED

Insert an ‘object type’ block and ‘blue’ block into the ‘logic’ block. Then, set the ‘logic’ block to ‘=’ sign.

Sound Synchronized LED

Put the ‘logic’ block inside the second ‘if () then’ block. This makes the VIA Pixetto report that it is detecting a blue color object. If this condition is true, the blocks inside will activate the event, which is to make the LEDs blink in a pattern while the piezo buzzer creates a sound.

Sound Synchronized LED

Next, select the ‘emits sound on the pin () on frequency (Hz) () for time (ms) ()’ block from the Inout category. Set the pin to ‘4’, and then set the frequency (Hz) ‘620’ and for the time (ms) ‘200’. This makes the piezo buzzer create a sound.

Sound Synchronized LED

Then go to the Output Unit category and select the ‘LED light pin () status ()’. Duplicate it, in the first block select pin ‘2’ and set the status to ‘high’. The second block select pin ‘6’ and set the status to ‘high’. Insert it underneath the ‘emits sound on the pin (4) on frequency (Hz) (660) for time (ms) (200)’.

Sound Synchronized LED

Then, select a ‘delay ()’ block from the Control category, and set it to 150 milliseconds.

Sound Synchronized LED

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

Sound Synchronized LED

Next, duplicate the ‘emits sound on the pin (4) on frequency (Hz) (660) for time (ms) (200)’, change the ‘LED light pin (2) status (low)’, ‘LED light pin (6) status (low)’ block and change the ‘delay (300)’ milliseconds block that you have created earlier.

This makes the LEDs turn off and the piezo buzzer create the same sounds with a longer delay time.

Then, insert three two blocks into the second ‘if () then’ block underneath the ‘delay (150)’ milliseconds block.

Sound Synchronized LED

Next, duplicate the same blocks that we’ve just made and change the ‘LED light pin () status ()’ to ‘high’.

Make sure the ‘delay’ block is duplicated too. This will make the LEDs turn on and the piezo buzzer create a sound when the VIA Pixetto detects a blue object. Insert it underneath the ‘delay 300’ millisecond block.

Sound Synchronize LED

Next, duplicate and change the frequency in the ‘emits sound on the pin (4) on frequency (Hz) (510) for time (ms) (200)’ block, change the ‘LED light pin (2) status (low)’, ‘LED light pin (6) status (low)’ block and change the ‘delay (300)’ milliseconds to ‘100’ milliseconds block that you have created earlier.

This makes the LEDs turn off and the piezo buzzer create the same sounds with a shorter delay time.

Sound Synchronize LED

Then, insert the blocks into the second ‘if () then’ block underneath the ‘delay (300)’ milliseconds block.

Sound Synchronized LED

Duplicate the same blocks, then change the on frequency (Hz) to ‘660’, change the LED status to ‘high’, and the ‘delay ()’ to ‘300’ milliseconds.

This makes the LEDs turn on and the piezo buzzer create the same sounds with a longer delay time.

Sound Synchronized LED

Then, insert the blocks into the second ‘if () then’ block underneath the ‘delay (100)’ milliseconds block.

Duplicate the same blocks, change the on frequency (Hz) to ‘770’ then change the LED status to ‘low’, and the ‘delay ()’ to ‘520’ milliseconds.

This makes the LEDs turn off and the piezo buzzer create the same sounds with a shorter delay time.

Then, insert the blocks into the second ‘if () then’ block underneath the ‘delay (300)’ milliseconds block.

Duplicate the same blocks, change the LED status to ‘high’, then change the on frequency (Hz) to ‘380’, for time (ms) ‘250’ and the ‘delay ()’ to ‘200’ milliseconds.

This makes the LEDs turn on and the piezo buzzer create the same sounds with a shorter delay time.

Then, insert the blocks into the second ‘if () then’ block underneath the ‘delay (550)’ milliseconds block.

Duplicate two ‘LED light pin () status ()’, keep the same pin ‘2’ and ‘6’ but change the status to ‘low’. Next change the ‘delay (200)’ milliseconds to ‘500’ milliseconds.

This makes the LEDs turn off while the piezo buzzer create the same sounds with a longer delay time.

Then, insert the blocks into the second ‘if () then’ block underneath the ‘delay (200)’ milliseconds block.

Next, go to the Control category and select the ‘repeat while’ block.Then, go to the Vision Sensor category to select the ‘object is detected’ block and insert it into the ‘repeat while’ block section.

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

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 to control two servo-motors 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 ofthe 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 COM8 (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 ‘Sound Synchronize LED’. 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 buzzer and two LEDs, and uploaded the code to the Arduino board, it is
time to do some test with your Sound Synchronize LED.

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