 In this episode, we will be using a webcam, some LEGOs and a computer to learn about computer sensing. Hello! Welcome to Make Time! My name is Gabriel and I'm a studio guide at the Studio Makerspace that's part of the Long Beach Public Library. Today we're going to be learning about computer sensing. And I'm going to show you a really fun way that you can apply this technology at home using your computer, a webcam and some LEGOs. I'm also going to show you a video sensing project that we created at the studio in the library. But first, have you ever thought about how computers or robots sense the world? To learn about this, let's think about how us humans sense the world. The most commonly known sensors are taste, smell, touch, hearing and seeing. We have specific body parts like our ears, nose and eyes that can take in information from the outside world. This information is directed to the brain where it is synthesized into our own experiences. Similarly, computers and robots are able to sense the world around them using a wide range of sensors. You can think of a microphone as an ear, a button as a way of feeling touch and a camera as an eye. But these sensors wouldn't matter without a way to process the information. So programs can be developed with instructions telling the robot or computer what to do with that information. For example, self-driving cars. They use a wide range of sensors including video cameras. These eyes take data from the outside world and a program inside the onboard computer responds to the input, like if a car sees a thing, avoid the thing. This allows the car to navigate around streets and avoid obstacles. For today's project, we will use this very same concept to create a musical instrument. Let's get started. For today's project, you'll need the following. You'll need a computer connected to the Internet. If your computer doesn't have a webcam, you'll need a USB webcam. You'll also need some Legos of various colors. And if you don't have Legos laying around, you can use colored paper or anything colorful you might have. I'll start by plugging in my web camera. Open up the Internet browser and go to scratch.mit.edu. You can create an account if you'd like. I'm going to go straight into Create. Now I'm going to go to the code blocks on the left-hand side and at the very bottom I'll like add an extension. I'm going to add the video sensing extension. Once we do that, you'll notice that we can see the video feed in the window here. Let's find the video block that says set video transparency to and change it from 50 to 0. Click on the block and you'll notice the video feed changes a little bit. I'm also going to add one more extension and that'll be the music extension, which will give us access to instruments and different notes. Now we are ready to build our program. Let's start by getting rid of the scratch kitty. Bye kitty. Now I'm going to create a simple sprite in the shape of a long vertical bar. Make sure that it's centered and that its height fits the margin. Now that I have the shape, I'll make sure that its y-coordinate is set to 0. Now we're going to make this object detect colors from the camera. Go to the events category and drag a start block into the scripting area. In the control category, drag a forever block and snap it under the start block. Now grab an if then block and place it in the mouth of the forever block, like so. Let's go into the sensing category and drag in this diamond shaped block called touching color and drag it into the diamond shaped notch in the if then block. For this next step, let's get one of our Legos ready. You can see it in the video feed here. Click on the color in the touching color block. Now we're going to select the color from the video feed. Select the color picker and place it over the Lego and click. You'll notice the color matches the color of the Lego. We have our if. Now let's add the then. If this bar sees this color, I want it to play a note. I'm going to go to the music blocks and drag a play note block in the mouth of the if then block. Now if I click on the green flag over the layout window and I move my Lego block so it touches the bar, you'll notice that it plays a note. Let's have it play several notes. I'm going to duplicate this whole script by right clicking on the start script. I will open up this drop down menu and I'm going to select duplicate. I have three Legos of different colors so I'll make one of the scripts for each color. Now I'm going to go in and change the color information for each script. And I'll change the note as well. Now when I run the program, you'll notice that when I touch the bar with the different colors, it makes a different sound. The last thing I'm going to do is have this bar move from side to side. To do that, I'll get a start block, snap up forever block underneath. Then in the motion category, I'm going to add a move block into the mouth. And last I'll add an if on edge bounce block. So arrange your Legos in different ways and press the green flag. Now if it all works correctly, you've made yourself a fun little music sequencer using video sensing. Now I'm going to show you an evolution of this project. This is our musical Legos project. We created this at the studio as an entertaining way to show off the concept of video sensing. It uses this document raider, a laser cut Lego holder, and a computer. The Lego music maker has three types of instruments. Red for drums, yellow is electric piano, and blue is a synth pad. In this program, the white position of each block determines the note. A higher the Lego, a higher the note. Or in the case of the drums, the white position determines a different drum instrument. This idea started out just like a simple lesson that we went over today. And over time we kept improving it. I'll play around with it for a little bit. It's pretty fun. So this is the project that we came up with using computer sensing. I wonder what you can do with this idea as well. So that's it for today. Thank you for making time to watch Make Time and tune in next time for more creative projects you can make from home.