The Adafruit Circuit Playground Express comes packed with onboard sensors, in this tutorial we will learn about using the temperature sensor in MakeCode. MakeCode is great for a simple project because its block-based interface and pre-built functions do most of the work for you! While using MakeCode the thermometer can return the temperature in Celsius or Fahrenheit.
Hi, Steven here from Core Electronics. I'm here today to talk to you about how to make a visual thermometer, for Adafruit first circuit playground Express and today we're going to use MakeCode to code it.
So, if we take a look at our board, the thermostat on the circuit playground Express, is in the top right corner and it's marked with a little thermometer gage and this is our end goal for today is we'll have a wheel of Lights on the board, that will display the current temperature between 0 and 40 degrees and the lights will light up to a relative position on the wheel indicating the temperature and they'll be from a blue to red gradient and as you can see its most of the way through the wheel, because it's hot in here. But just to give a little demonstration I've got a heat gun, so we'll heat it up a little bit, so you can see the lights will go up in real time and we've programmed it in so if it exceeds 40 degrees all the lights turn red. So, let's look at the code.
If we go to the MakeCode website and open circuit playground Express, we can get the Adafruit version and start a new project. So, the first step that we want to do to program the board is add in some a logic loops. So, we're going to use an if-else loop. So, we'll go into logic select the conditional of if-else and the condition we want here is, to include the lights turning red when it exceeds 40 degrees. We're going to start with that, so we'll say if the temperature is greater than 40 degrees, so what I did there was I went into the logic portion, I picked a comparison. So, this is something greater than or less than something else and our input is going to be the temperature. So, we'll just select input and grab temperature in Celsius and since it's a bubble shape, we can replace this number with it. So, if the temperature in Celsius and will change this is to greater than or equal to and change the value to 40 degrees. Then we want the lights to all turn red, so we'll select lights to grab the colour wheel show ring and put that in our if statement. So now as it is whenever the temperature gets to 40 degrees, all the lights will turn red on the board.
To make the temperature viewing ring of lights whenever it's below 40 degrees, we use something called a graph. So, we go into lights and we see here, graph up to zero and we drag that into the else portion because it's there bubbles we can again select the input of temperature, replace the first zero with, the temperature in Celsius and set the upper limit of the graph to 40. So, if you wanted to detect a larger range say go up to 80 degrees Celsius, then you would set that here and the lights would illuminate to be a percentage of from zero to that upper limit, but I don't really recommend trying to sense temperature, if anything that hot because you'll probably melt your board.
So, this is our full code in entirety right now, as you can see on the virtual board here there's a thermostat that's appeared in the top left, so we can simulate different temperatures and it'll appear on the virtual board, including over 40 degrees where it turns all red. So, something else that's nice about the MakeCode interface, is the console simulator. So if we click on the console simulator here, it gives us a graphed history of the temperatures that we've read using the sensor and this isn't terribly useful for this project because it's a false reading this that's going into it that it's recording, but if you have multiple inputs and you wanted to see them simultaneously then this could be really helpful. So now let's put it on the board.
What we want to do is just download our file in the bottom left and we'll select save file, now we want to grab the file out of our downloads, will enter bootloader mode on the board, so just push the reset button in the middle of the board, now play boot drive appears in our devices and drives in this PC or my computer or whatever it is on your computer. We just drag our file into the play boot drive and now it's loaded on the board.
So that's all it takes to load the program on our board you know it's ready to go we can unplug it from the computer if we like to plug it into a battery and take our project with us wherever we like.
So here it is completely free even computer, now something else that could come in handy for a project like this, mentioning the serial monitor earlier in the standalone Windows app version of the MakeCode for Adafruit editor. So, if you go to the Microsoft App Store you can download MakeCode for Adafruit and as you can see, it's a very familiar looking interface, it's the same, except it has one extra feature that's alive console. So we have the same program here that we've made before but now, in the Windows app and the Windows app also has another advantage of being able to be used completely offline, where the normal interface uses a web browser and once it's been loaded once and saved to your favourites, you never need the internet again but you do need the Internet initially in order to connect.
So, we can go to show console device and now this will plot the actual temperature as it reads it live, so let's get out our heat gun again and see it's plotting spikes as the heat hits it and we have the range right now between 32 and 37 degrees, 32 is the minimum because like I said it's really hot in here and there we go we hit 40. So, it went all red, now one of the cool things about the show console device is we can now export this data to an Excel spreadsheet and then that could be used however you might like. All the data is available here with time and value stamps.
So, one more word about the Microsoft app version of the MakeCode interface is if you want to load your code onto your board you don't need to download a file and drag it into your circuit playground express. It does it automatically when you hit download if your board is connected, it automatically places it on the board and your board restarts and it's running off your new code right away. So that takes an added step out of the process.
Well, thank you for watching our tutorial on a visual thermometer with the Adafruit circuit playground Express and MakeCode. Stay tuned if you want to find out about more ways to program using the thermometer, I'll have an upcoming tutorial showing how to do a similar program with circuit Python and of course we'll have more tutorials coming for the circuit playground Express in our tutorial section on Core Electronics.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.