An introduction to coding with an Arduino | Do Try This At Home | We The Curious

In 2018, the second stage of the European Space Agency’s ExoMars mission will deliver a rover to the surface of Mars. The ExoMars rover will travel across the Martian surface to search for signs of life. In order for this robotic rover to navigate the landscape of another planet on its own someone needs to write the code to tell it what to do. But what on Earth is code? And how do you go about using it at home? Well today, we’re going to give you an introduction to coding with an Arduino. Heather: We’re joined by At-Bristol’s new Tinkering Officer, Beth, hello! Beth: Hello.
Heather: So, you’re here today to teach me what an Arduino is? Beth: I am. I’ve brought one along with me. This is an Arduino. It is essentially a robot’s brain. We’ve got robots, much like our little chap over here, our little rover. And he’s got an Arduino on him, and that’s his brain. But he’s got a whole lot of other stuff as well as you might be able to see. Things like these, his little eyes down here. That is telling the Arduino brain, “I can see something.” And he’s got a clap sensor so he can hear sounds. And that is telling the Arduino, “I’ve heard something.” And then the Arduino then takes all that information, you have to tell it a set of instructions through using code, and that will tell the wheels what to do. You’ve got different parts of the Arduino. We’ve got these pins along the side, where we plug in our various sensors. And this bit in the middle, that’s the kind of clever bit. This is my prototyping rover, this is what I use when I just want to try stuff out. Nothing is fixed. Nothing is soldered on here.
Nothing is glued down. He’s held together with elastic bands and little clip-on wires and things. Beth: Make some sort of loud noise like a clap. [clap] Beth: He’s off! Heather: Aaaah!
Beth: [laughing] Heather: How do you get him to come back?
Beth: [laughing] Beth: This time, you see his little eyes?
Heather: Yeah. Beth: Once he’s heard the loud noise, and he starts to run, get your hand down in front of him and we’ll see how that goes. [clap] Heather: Aaah! That’s so cool! Beth: He does a little turn to get a new angle.
Then we can go again. [clap] [Beth laughing] Beth: So he can tell how far away your hand is. Beth: And once your hand gets within ten centimetres, he should stop. Beth: Code is the way that we give our instructions to the robot. He only understands very kind of simple stuff. So you really need to spell it out when
you’re talking to him. You can’t just say, “run forwards”. You have to say, “turn your wheels this much for this amount of time”. So, in this particular case, the language he understands is a programming language called ‘C’, and it’s quite a low-level language. So, you really need to explain what you’re doing when you’re working in ‘C’. But, I’d say that’s where online tutorials
come in very handy. Because a lot of the time people will say,
“just upload this block of text.” And you go, “Alright, I’m gonna upload that block of text, I’m not going to question it all that much.” And surprisingly, you will actually learn from that. It might feel a bit like, “oh this is bit cut and paste, I’m not sure I’m really ‘coding’ at the moment”. But, you know what, the more times you do that, then you’ll eventually start to recognise it. And then you might go, “oh, I tell you what, he’s not running for as long as I wanted him to run for”. And then you look through and you might spot a number. And you think, “OK, let’s make that number a bit bigger.”
And you run it. AND HE GOES MAD!
And you go “OH I SHOULDN’T HAVE DONE THAT!” And you put it back to normal, and you go,
“OK no it’s fine, it’s better now.” And then you try changing a different number. And lo and behold, you’ve started doing some basic coding at that point. Heather: So can we do some coding now?
Beth: Absolutely! Beth: So we’ve got him plugged into our computer now. This is the Arduino ‘IDE’, which stands for
‘Integrated Development Environment’ So, it’s a bit clever, it does a lot of stuff for you which is very nice. Let’s change some numbers. Pick a number and change it and we’ll see what happens. Heather: That ‘8’ there.
Beth: [laughs] OK! No, we can do it, we’re gonna totally change it. Beth: What number do you want it to be?
Heather: 14
Beth: It is now the number 14. Heather: I have no idea what this is going to do.
Beth: Let’s see what this does. Beth: It’s uploading.
[clap] Heather: Oh. Oh!
Beth: [laughs] Beth: So what seems to have happened here is that one of his legs has stopped working [laughs].
Heather: Awwww. Heather: So he’s going around in circles?
Beth: He’s only going to go ’round in circle from now on. Heather: Hang on, so why was it ‘8’?
Beth: This is how we learn about coding. Beth: So, that ‘8’ was the number of the pin that the leg was attached to. Beth: And so you’ve now told it a different number so it doesn’t know where the leg is. Beth: It’s trying to send information out of ‘pin 14’,
but there’s nothing on ‘pin 14’. Heather: I feel sorry for him. Heather: So if you want to do a project at home, with an Arduino, where do you start? Beth: So the first thing you’ve got to do out is work out what you want your little rover to do. And work out what you need to buy for it. So, do you want it to be able to see?
Do you want it to be able to hear?
Do you want it to be able to move? Buy those parts. Once you’ve got those you need to work out how they actually plug in to the Arduino. Once you’ve got everything plugged in right, you need to know how to code it. Heather: If I bought this I wouldn’t know that I’d have to do that. Beth: But what you would do is you would Google it. Heather: And then that would tell me I’d have to do it.
Beth: And it would tell you what you’d have to do. Heather: Or it would just give me the coding already? Beth: No-one knows this stuff off the top of their heads. No-one buys one and goes,
“Oh, clearly I have to write distance-trig number two”. Everyone who’s ever bought one of these has gone and looked it up and thought,
“Alright, how does this work then?” So that – that chunk of text just here – I have found on the internet. And I have put it in my code so that I may find the distance in front of one of these. And the real key is kind-of figuring it out in your head what you want it to do. So, it’s kind-of like a logic puzzle. “If – you hear a clap – then – do this.” And you can kind-of lay it out in that way. And it’s laying out those steps in your head that’s really the tricky bit of the code when your start out. There’s tutorials out there if you want to do through things step-by-step. Or if you just want to do a little bit like what I did and just have an idead go for it and try things out, then your can do that too. Beth: There’s actually a lot of similarities between our little rover here and the big one that’s gonna go to Mars. The actual Mars rover is going to need a way to interact with it’s surroundings. It’s going to need to be able to sense what’s out there. Just in the same way that our little Mars rover senses what’s in front of him. The rover on Mars is going to need to be able to interact with the terrain, it’s going to need to be able to move.
It’s going to need something like the wheels we’ve got. And it’s going to need the brain that ties all of that in together. Which in our case is our Arduino. So someone, somewhere has written the code that tells the ExoMars rover what to do. And that person will have started from somewhere.
No-one innately knows how to code. So it’s projects like this where you’ve got a simple objective, a simple robot, where you can really learn and just try things out,
get things wrong, mess it up. That could lead to one day making code that is driving a rover around the surface of Mars! If you enjoyed this video, click like and share it around. Or click on my mini-rover here to subscribe. Why not check out this video and see how to make a scribble-robot. And if we’ve inspired you to try science at home, send us your photos on facebook or twitter. Thanks for watching! Heather: So this looks pretty… [laughing]
Beth: It does look pretty! You’re right!

Leave a Reply

Your email address will not be published. Required fields are marked *