empowering creative people

Videos / Circuit Playground Express Workshop - Chapter 4 - Using the Sensors

There are eight different ways we can interact with the Circuit Playground straight out of the box, and no limit to the sensors and devices that we could connect externally

Search Videos

Related Content



Hi, welcome back to the Circuit Playground Express online workshop, in this section we're going to talk about the sensors and how we use them in how we program with them. 

So, there are a few sensors that we're going to focus on in this section and it's going to be the thermometer, our capacitive touch sensitive pads and our buttons, our microphone, our light sensor and our accelerometer. Now there is also an infrared transmitter and receiver on the Circuit Playground Express, but we'll go over that in a later section.

So, right now I have a sketch running, where we're taking live data from the thermometer and displaying it on a graph on the wheel lights. So, it's about 25 degrees in here, so the graph ends at about that relative position with 40, being all lights lit up and zero being no lights lip. Which brings me to my first point there are two types of data that we can use within MakeCode, there's what we call events and there's live data. So, if we look at MakeCode. I've got two examples of temperature using an event on the right and live data on the left. So, the event types are in these brackets and anything that's in an event it's waiting for the criteria for the event to be met and then it will play everything in its bracket once. So, when the temperature gets to 40 degrees, then we'll play the red lights will pause for two seconds and then we'll turn the lights off. Now one of the disadvantages to events is that if the temperature remains above 40 degrees it won't continuously turn the lights on, it'll just play once and then it'll need to drop below 40 and come back up before it will trigger again and on the left we have what we see on the board, which is we're graphing the live input the live data of the temperature in Celsius and we're graphing up to 40 degrees.

So live data is nice because it takes the real-time raw data input from the sensors and it allows you to plug it straight into your program, so you wouldn't be able to use these two at the same time I just have them up as an example so we'll get rid of these and we'll move on to our next sample which is our buttons and our touchpads so again we have a live data type which is in these small blocks and if we look and look up the input menu, we see that the first five are our events and then after that we have our live data and then we've got a few different options for controlling or setting parameters for inputs here, but those are really used specific so we won't cover them now.

So, here when pin A is pressed and when pin 3 is clicked, which is essentially the same thing it's just different terms. So, the capacitive touch pads, let's download that to our board. So using the live data and an "if" statement, when button A is pressed the lights, will turn blue, so if we look at the live event type we've selected pin A3 which is a capacitive touch pad so when pen A3 is touched the lights will turn blue for two seconds and then they will turn off again so when I touch pin A3 or anything connected to pin A3 it turns the lights blue and then they turn off again. So, this can be nice this could be a nice way to do button clicks using the events because that's something that resets every time and if you want to eliminate the possibility that it'll just run continuously, if someone is holding down the button then the event is a good way to do that sort of input.

So, for this next example, we're graphing the sound level live input and as you can see on the board as I talk it takes the input from the microphone and lights of more lights based on how much volume it detects and we have an event on loud sensor turn all the lights red. So, if we're to get rid of this graph loud sound and just leave our event then whenever there's a loud sound detected it'll turn the lights on and then turn off if there's continuous loud sound though it will play it only once and then turn it off.

So, in our next example, we're going to be doing light level. So again, we're just going to graph it, so the light level is fluctuating around the, let's say 75 out of 100 marks. If we cover it up, then less light up but it tries to start our animation. So again, an example of live data coming from the light level coming in and then we have an event "on light dark" which shall play and animation. So, if we want to do something with an event like this, whenever the board becomes momentarily dark, it'll play a rainbow animation but again it needs to become very bright before it will reset. So in here is not bright enough for this to reset the event so it can detect darkness again and play so especially with the on light event, I would say for the light sensor use the live data and a conditional statement to make something play when it's dark because it's more it's more configurable as well you could also change this to bright or dark if you'd like.

The last sensor we're going to talk about is the accelerometer. So in this example I have the live data of the acceleration on the x-axis up to 500 being graphed, so it doesn't display much when it's not moving but when the board's moved in the x-axis which is left-to-right relative of the board here we see it displayed as a graph and why not so much because that's what not what it's detecting currently, just X. Also, you can read it if it's tipped using the live data from the x-axis and if we're to get rid of our graph and leave just the less just our shake event then whenever the board's shaken, then it'll play an animation. So, it's able to recognize a shake or some quite a few different events such as tilt up, tilt down, freefall or like three six or eight Gs. So that's when it's accelerating up to eight gravities which you'd have to be swinging it around at the end of a string or something. So free fall could be a good one if it would detect when it's dropped. So, when it's not detecting any gravity so there's a lot of different options within the event type for accelerometers but again you can create all those same conditions using the live data and some conditional statements but depending on your program this might work out a little easier for you.

So that wraps up my section on the different sensors and how to use them within your code within MakeCode. In the next section, we're going to talk about how to make some music.