Streamed live 13 July, 4:45 pm AEST
Click to toggle workshop transcript
Good afternoon. Thank you so much for once again joining us in the EduKits interactive coding experience. I’m your host, Michael, and I’m delighted to bring you the fourth workshop in this series.
Today we’re going to be looking at two different inventions you can build with the amazing Annoyatron. And I’ll get to what those are in just a moment, a few things I’d like to talk about and I bring these up at the start of every one of these sessions.
Firstly, there will be a Q&A session at the end of today’s live stream. You can send us your questions or comments using the email address which is displayed on your screen now. That’s [email protected]. You can also find this email address in the sidebar of the stream page on our website where you’re watching the live stream right now.
Of course, as always for our customers who are watching on the recording because we do record and upload all these live streams to our stream website. You can of course still send us questions to this live stream email address, we just obviously won’t be able to get to those questions on today’s stream. Now you can access this recording at any time afterwards, even if you are watching live, you can watch any of the other recordings so far.
We already have three up in this series for you to take a look at and now it’s time to get into what we’re doing today. So we’ve got two different inventions today. The first one is the burglar alarm. This is an exciting way to protect your bedroom from intruders like pesky siblings. You can also try it out on parents, grandparents, maybe pets, if you’ve got pets at your house, that’s going to be lots of fun.
And we also have the electronic cricket. This is a devious little invention. It makes cricket sounds and it’s almost impossible to find because you put it in a dark room and it has a light sensor. So when you turn the light on to go find it, it detects the light and it turns off. So they’ll look around and they won’t be able to locate where the sound is coming from.
So now it’s time to take a look at the parts we’ll need for the inventions today. And I am trying to speed through this a little bit because there are a lot of parts. But I mean it doesn’t seem like it, we’ve only got two inventions. But yes, let’s take a look.
As always, grab out the Brain Board, which is the brains of the operation. It’s what we code and it controls everything that happens with the invention. You’ll also need the blue USB cable which connects the brain board to your computer. Grab out the buzzer which is a very common part of most of our inventions. It’s the black cylinder with two legs and a little hole in the top for the sound to come out of. You will also need to grab an LED. Like always it doesn’t matter which color you pick. The colors are all the same. We have different colors in our kit like red, yellow or green. one of these.
You will also need this new plastic component and it’s called a breadboard. Now don’t get it confused with the brain board. This is the brain board, this is the bread board. You don’t chop bread on it though. Not ideal. That’s not what that’s for. I’ll show you what it’s for later on. You’ll also need this ultrasonic sensor. Now ultrasonic is essentially a frequency of sound that the human ear can’t hear. And we use this to measure distance. It has two little speaker devices on its surface and those kind of look like a set of eyeballs essentially. This is going to be for our burglar alarm.
You’ll also need the light sensor or the light dependent resistor which we used two sessions ago in session to, and you will also need the resistor that goes that we use alongside that. Finally, you will need a bunch of cables. I’ll pull one out to show you. You’ll notice that it has one end has a pointy end and the other end also is a pointy end, so it’s pointy on both sides.
In the past we have used wires that are pointy on one end and have a hole on the other, but that’s not this week. So we have one of those cables, another one, so that’s two, three, four, five, and six. So you’ll need six of those cables. I’ve made sure that I’ve picked all different colours and this is so that it’s easy to see exactly what’s connected to what.
I said this in the, I think the first time we used the wires, but they’re all pretty much the same. It doesn’t really matter if you’ve maybe lost a wire or you want to use different wire colors to be more colorful. They’re just wires with different colored bits of plastic on them. So grab all of those things out, hit pause if you need a bit of time, and then you can just resume and we’ll get to putting together the first one.
So we’re going to be building the burglar alarm invention first, but I’m going to take a little bit of a detour which is a bit unusual for these workshops, but I want to take a closer look at exactly how the breadboard component works because it is a bit tricky and a bit counterintuitive at first. Let’s jump to the overhead cam in a moment, but let’s first create a new invention in Code Kit.
What we’re going to do is create a blinking LED and instead of plugging it, plugging its ends into the cables and putting those in the breadboard, we’re going to plug it into the breadboard. So let’s give that a go. Oh, oops. We’re doing the coding first. There we go. Load Code Kit. You can find a link to that in the sidebar of your stream page. You can also click on it in the top menu of the EduKits website.
We’ve got a blank project here, and I’m going to first of all drag an input/output. I’m going to set PWM pin and we’re going to select 9 and set it to 100. So essentially we’re going to be plugging our LED into pin 9, we’re going to set the power to 100, I’ll duplicate this and we’ll turn it to 0 so that will essentially be off. And then I’ll grab a timing block and I’ll stick a delay between the two. And I’ll change this to 500 milliseconds, which is half a second.
I’ll right click, duplicate that again, and then we have a break. So essentially, what’s happening here is we are turning the light on, waiting a short bit, turning it off, and waiting a short bit again. So it’s going to turn on, off, on, off. It’s going to flash. That’s the code we want.
So I’m going to clear off the things we don’t need, essentially everything except the brainboard, the breadboard which is the white one, the LED and two of those cables. I’m going to plug in the brainboard to the blue USB cable and then we’ll head over back to the software.
I’ll copy this code and change to Arduino software. I’ll paste in the new code and upload it. Okay, so we’ve just uploaded a bit of code that is meant to make an LED blink, but we haven’t got this LED connected so nothing’s going to happen. Our job now is to wire this up so that the LED blinks and we’re going to do that using the breadboard.
Let’s take a look. So you can see on this breadboard we have a number of holes on there and those holes are a little bit like the holes on the brain board in that you can slide different components or wires into them to connect different things. I’m particularly interested in the rows along here and you’ll You’ll notice that there is a divider down the middle, and that separates these two sides. You can imagine that they’re two totally separate sides. And then if you see, there’s horizontal and vertical rows and columns. So the horizontal rows go along this way along the board. This way, this way, this way, and this way. And there’s heaps of them.
Now I’d like you to take this LED and you’ll notice that it has a shorter and a longer leg. I want you to stick the longer leg into this hole here at the very top and I’ll move it along to the edge so it’s the row closest to the middle divider on the left side and then we’ll stick the shorter leg in the hole below it. So the top one’s in the first row, and then, sorry, the longer leg’s in the first row, and the shorter leg is in the next row down. So I’ve slid that in. There we go.
Now here’s where things get interesting. I’m going to connect these two wires. So this yellow, sorry, this red one’s going to go to pin 9, and this black one’s going to go to ground, 10, 11, 12, 13, ground. And we’re going to connect this wire to power, to the pin, so it should start blinking if it’s connected correctly.
So take this black wire and insert it into the breadboard in this row here, which is the second row from the top. Now just pop it on the end there. And do the same thing for the red wire, but put it at the very top row. So the same column but the top row. And you’ll see that the LED starts to blink.
Now here’s something interesting. I’m going to take this red wire and I’m going to move it down a column. So I’m moving it inwards this way towards the center, towards the LED flag. I’ve done it again and the light’s still flashing. And once more. So what that means is that there’s actually a little piece of wire running underneath each row in this breadboard. So any two wires or any two components or legs or whatever that are connected to the same row will be connected electrically. So you can have a circuit like that. And we’re going to use this concept when we connect everything together for our burglar alarm.
So now it’s time to take a look at what the burglar alarm does, how it works, and then and we’re going to put it together, code it, and test it out. I’m pretty excited, so let’s get right to it. So how does the burglar alarm work? What’s happening? Well, it’s actually pretty simple. In the burglar alarm, we’re checking to see if there’s an intruder, and we do this with the distance sensor. So if someone comes too close to the distance sensor, so if we detected a distance that’s kind of less than usual, So if someone comes close, walks past, enters your room, whatever, it’s going to activate and that’s going to in turn set off a loud and annoying sound.
I think it’s time to build it now. We’ll need the ultrasonic sensor, which senses the distance, and we’ll also need the buzzer, which allows us to make the noise. And we’ll connect those two things to the breadboard. Practice your breadboard skills now. So the first thing I’m going to do is disconnect this entire project from power, because we don’t need the power right now. I’m also going to disconnect these wires here. We don’t need those for the moment, and take the LED out.
Now, I’m going to bring back the ultrasonic sensor, the buzzer, and this time I will need every single one of those wires back here, and it will be time to connect them. Now, we normally slide the buzzer into these holes here on the brain board, but we’re not going to be doing that this week. I’m going to be lining up the buzzer with this breadboard, take the short leg of the buzzer and put it in the top row and then put the short leg into the row facing downwards. Essentially, the legs are kind of like facing this way into the board, not facing this way. you want them this way going down. Okay, now I’ll take the, which color wires will I use? I will use the gray and the, let’s do the white, gray and white for this one.
And I will connect the gray one first to the same row, which is the very top row. And I’m going to connect that to ground, more GND. So that’s eight, nine, 10, 11, 12, 13, ground. I’ve counted up the pins, which is a useful way to make sure you have them connected correctly. And then we’ll grab the white, the white wire. Now you’ll need to give it a space of two, of two holes on the breadboard. So one, two, and on this third one, so that’s fourth row down from the top, You’ve just connected the white wire to, and I’m going to connect this to pin number 11. So I’ve plugged it into 11 like we normally do.
Next is the ultrasonic sensor. I’m going to take this ultrasonic sensor and slide it in to the other end of the breadboard, and it’s just going to be in the middle. put it in here and you can see how it looks.
Now if you look at the front of the ultrasonic sensor, you’ll notice that there’s a bunch of words on here, a bunch of letters, and you can see they say VCC, Trig, Echo, Out, and Ground, or GND. You probably can’t see them in the stream here, but you’ll be able to see these when you’re looking yourself on your own, on your own ultrasonic sensor. They are a bit small in the screen here.
I’m now going to connect the wires to them. Now on the other side, I’m going to line up these wires on the same row as the different pins. So the first one is VCC. So I’m putting that wire there, and I’m going to bring it over here to the five volts, the five volts one, which is ground, ground, five volts. That’s there. I am then going to connect this next one, which is the tree, and it’s going to go to pin number nine. So I’ll move that over here, pin number nine. Then we have echo, which is going into pin number 10. That’s between the other two wires over here, the yellow and the white. If I can slide it in, there we go. And lastly, the output, sorry, the ground. We’re going to skip the output, don’t need to put anything in there and I’m going to take it straight over to the other side next to that red wire and you can see we now have the entire invention assembled.
So that means it’s time to head over to the code and get started with coding the invention. We’re going to be using Code Kit like before, so this time though we’re going to be starting with a new project. We already have a bit of code in here, that was from our last one and I’m going to click this trash can icon and hit OK to delete all the blocks because we don’t need those other ones. I’m now going to start off by making the annoying noise with the buzzer.
We’ve done this before so it shouldn’t take us too long. I’m going to go into Input/Output and drag a Set Buzzer block. We’re going to change it to 11 because that’s where our buzzer is connected and we’ll leave it at full 40Hz. I’ll duplicate this block, put it underneath, and we don’t need that, we want to turn the buzzer off. We need to give ourselves a break from that noise. And put 11 on there, and then we just add a bit of timing in between those two. A small delay, which means that there’s actually a short delay between the two noises. Okay, so we’ve got, we’ll change these to 250 milliseconds each, copy this, and then head back to the Arduino application.
Now that last bit of code was for the breadboard test, you might want to create a new sketch and save it. This is going to be for the burglar alarm. alarm. Okay, I’ll paste in the new code, hit upload, and I forgot to plug in the brain board so it won’t work. The brain board’s all plugged in now so it should be good. I’ll hit that upload button and we should hear in just a moment an annoying sound. There we go. That’s really annoying. So I’m going to disconnect that from power for the moment and we’ll take a look at the code to figure out what we need to do next.
So you can see that we have this buzzing noise and it’s annoying but it is going on all the time so we need something to trigger it only when there’s someone walking past which is really the beauty of it. The first thing I want to do is go into logic. Now we can find an if block and if you drag this over the top of the blocks you currently have you’ll notice a little yellow divider line appears over the top. You can also see a shadow wrapping around the entire set of blocks.
If you drop that there it’ll snap around the other blocks. What this means is that all of the blocks here will only run if a certain condition is met. That’s what the if part means. And you can see up here we have a little cut out and there’s nothing in there. And that’s the condition. So we can drag some kind of condition in here. So for example, under logic you can see this one here. There’s a little cut out on the left and a cut out on the right and an equals sign. And I’m going to drag that into the hole there.
And I’m going to change this to less than. Okay. And then I’m going to grab an input and output, just bear with me, and I will grab a sensor distance block. Lastly, I’m going to go under maths. You might need to re-enable it if you’re like me and you disabled it earlier. Most of you won’t have that problem though. Okay. Go on under maths and I’m going to click and drag that number block in there. Okay, so we have a number and I’m going to change this to 30.
So what this means is that the brain board is only going to make noise out of the buzzer if something’s closer to the sensor than 30 centimetres. That’s what the 30 means. So let’s copy it, let’s upload it to the board and see how it goes. Now it’s uploaded and the first thing you’ll notice is that there’s no sound. But we can essentially trip this burglar alarm just by putting our hand in front of it, like so. And you’ll notice that the alarm goes off. It works just as expected.
And you can change that distance just by changing the number under the sensor distance. So right now it’s set to less than 30 but you can change that number to whatever you’d like. So now we’ve built that invention, it’s time to move on to our next one which is the electronic cricket.
So the way this works is like we discussed before, there’s a cricket sound and this only happens when it’s dark. So we have a light sensor that checks whether it’s dark or not. If it’s dark, it plays the sound. And if it’s not dark, then it’s quiet. And the reason that is so is so that people can’t find it. They turn on the light to try and find the cricket noise and it turns off. So it’s practically impossible to detect and find.
So let’s jump over to the assembly and I’ll disconnect this from power and I will pull out all these wires because all we need is the buzzer. We’ll slide that into pins 11 and ground so that’s 9, 8, 9, 10, 11, boom. Buzz is in and we’ll do that connection with the light sensor and the resistor the exact same as we did before. So we’ll insert the light sensor into A0 and 5V. So that’s A0 and 5V is here. And then we’re going to connect the resistor to A0 as well, but this time ground, GND over there. Now we’re fully connected and we can get to coding this.
So again, I’m going to click on the trash can icon and we’ll delete all the blocks from Code Kit. We want to start blank. I’m going to essentially make a cricket sound to start off with. And to do that we’ll need to grab our favorite blocks which are the buzzer blocks. So I’m going to set the buzzer on pin and we know from experience that this is pin 11. Okay, now we’ll also want to stop the buzzer noise so we’ll stop the sound and it’s on pin 11 too. Okay, so So we have a sound that turns on but then instantly turns off, so we need a delay in order to break that up. I’ll change this to 30 milliseconds. And I’ll right click and duplicate this and we’ll change this to 10 milliseconds. Now I’ll make this a bit more high pitched and we’ll change this to 5000. And you’ll see what that does in just a moment.
So let’s copy this code, head over to Arduino, create a new sketch, paste in the new code and upload to the board. It will prompt me to name the sketch so I’ll just call it Electronic Cricket. Hit enter and it will now upload. Now I’ve just plugged the board in. It’s uploading now and in just a moment it should be on the board. My computer’s a bit slow today for some reason. Okay, there we go. You can hear that sound. So it’s kind of and it kind of sounds like a cricket, but I think we can do better.
So let’s go back to Code Kit. I’m going to delete that turn buzzer off. We don’t want the buzzer to be off. Let’s duplicate this top block, stick it in between, and I’m going to change this value down to up to 10,000. Okay, copy it, switch back, paste, and time to upload again. Okay, the sound does get a bit annoying after a while but that’s how it’s meant to be. Okay, now that is a cricket noise. We’ve done it, we’ve created the amazing cricket noise.
Now all that’s left to do is to trigger that only when there’s no light. So let’s grab our if block, which allows us to only do a certain action if a condition is met, and we’ll bring in this comparison block from before. So we have our two values and we can compare them. And we’ll do a less than again, and this time we’re going to drag in a light sensor value. So if the light sensor value is less than, we’ll grab a number in from this math section and we’ll make this less than 200. Okay, so if the light sensor is less than 200, we’re going to have this cricket sound. Okay, let’s copy the code, paste it in and upload it. Okay, it’s uploading now and is uploaded. Now there’s lights on that you can see but we’ll turn these, I’ll just cover my, use my hand to cover the light and you’ll notice it makes a sound.
Now I’m going to disconnect this because you can instantly see there’s a problem with this. Because I removed, we removed the block that turns the buzzer off, it just stays on forever. And we’re going to fix that right now. Because obviously there was no sound, so we didn’t turn the buzzer on unless there was light, but there’s nothing to turn it off here. So I’m going to stick in a loop block here, and this means that we’re going to repeat our cricket sound a few times when there’s light. We’ll stick this in here, change it to five, and then we’ll stick a stop sound button, sorry block. So that means every time we make a sound we eventually have to stop it and that’s the way it should be so that it doesn’t annoy us eternally. We’ll then change this to 300 milliseconds, copy and we’ll upload that to the board. I’ll plug this in, let’s hit upload and we’re compiling, uploading, bam, there we go. So let’s see what happens. I cover the sensor and it’s making a cricket sound. Move my hand away. Brilliant. That’s working exactly as it should.
So that’s pretty much that part of the invention done, but you can change the light sensor value if it’s not working for you, and you can also have a play around with these different buzzer values to create the most annoying sound you can. So now that we’ve built the two inventions and learned about some exciting new sensors and parts that come in your amazing Inuit trunket, it’s time to go to the Q&A session and take a look at some of the questions and comments you all have been sending in to our [email protected] email address.
We are running a bit close, a bit tight on time today, so I won’t be able to get through too many, but I’ll try to get through as many as I can before we switch over to replying to those on email.
So the first one is, can I connect my brain board to both the computer and a 9V battery? And I think that’s actually an important question for some of the inventions we’ve built today. I didn’t mention it, but on the Annoyatron website, on the EduKits website, there’s instructions on how to connect this brain board to a 9V battery clip. Essentially, there’s a barrel jack on here. You see there’s the two ports. There’s the silver one for the USB, and there’s one over here. And that’s where you can plug in your nine volt clip. So there’s a connector that goes in there, you pop it, you pop it in there, and then on the other end you stick your nine volt battery on there. And that allows you to run this invention away from the computer. So you can hide your burglar alarm in your room without needing to run a cable there, ’cause the cable’s quite short with this kit. And you can also have the electronic cricket somewhere and you can hide it maybe in a bookshelf or somewhere dark. You might have to stick a little bit of tape, black tape over the lights though because that might give away its location. But the answer is yes, you actually can connect power from the computer and power from the 9-volt battery. There’s actually a switch inside that protects it from overloading the power when that happens and it just switches to the power coming from the computer. So the connection goes through the USB when you’ve got both of them connected, just so you can upload the code.
On to the next question. I can’t see the messages option in Code Kit. How do I unhide it? Well, we did go over this in our Code Kit section in our session in part two. And I think it’s really important to go over it again. We have the block loader under the settings icon. And you can see we have all the options for the different block categories. and there’s check boxes there which allow you to show and hide the different categories. So if you don’t have messaging, if messaging looks like this and there’s no check in the check box, you can click on it and you’ll see it reappears. You click the close button and it will refresh, the page will refresh and suddenly it should appear in your sidebar. There you go. You’ll now have all the options for messaging and all the different blocks that come with it.
Okay, and now I think we’ll go on to our last question for today. And it says, “The 200 value isn’t working. I can’t hear the cricket chirping.” So I think what’s happening here is their light sensor is slightly different to my one. So everyone’s sensor is slightly unique. They’re all the same type of sensor, but tiny little differences in the way the plastic is manufactured in it will mean you have a slightly different value. So what you might need to do is try a slightly higher value. Yes, a slightly higher value than 200, so maybe 300 or 400, slightly higher number, and keep on copying and uploading until it works. But when it does, it’ll be very exciting.
So thank you so much for coming along to this workshop. This is the fourth workshop in the series. There will be another few workshops coming down the track. It’s been a pleasure presenting for you and thank you so much for sending in questions. Have a great afternoon and enjoy the first week of school if you’re here in New South Wales.