Build Your First Robot (for $30) | James Holmes | Skillshare

Build Your First Robot (for $30)

James Holmes

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
5 Lessons (17m) View My Notes
    • 1. Introduction

      1:04
    • 2. Building a Simple Robot

      3:57
    • 3. Getting Started with Arduino Coding

      4:27
    • 4. Simple Motor Control

      4:01
    • 5. Controlling Electric Drill Motors

      3:33

About This Class

If you’re trying to get started with robotics, electronics or coding, this video series is aimed at you. We’ll talk through some of the basics of building a robot, the software involved, talk about important principles for control such as pulse width modulation and how these principles apply to bigger projects.

Useful links:

Music: http://www.bensound.com

Transcripts

1. Introduction : Hi, I'm James, I'm an engineer and I've been interested in electronics and robotics for as long as I can remember. And my jobs have been lucky enough to work on everything from autonomous robotics to automated medical diagnostic systems. And I think it's a really exciting time to be involved in engineering. You're just getting started with electronics, robotics, or coding than this video series is aimed at youth. We're gonna talk through the basics of building a simple robot, some of the software involved and introduce important concepts like pulse-width modulation. Along the way, you can use these videos to inspire your own projects. Or if you'd like, you can get hands-on and build your own simple robot home for around $30. And because I'm sure you're already dreaming of bigger and better projects. Later in the series, we'll talk about building on what we've learned to control bigger and better style. If you just look into your toe in the water, will also cover some simpler projects along the way like this little LED Christmas lights sequencer, which you can put together at home for very little money and just have a gun. So whether you are an absolute beginner or novice looking for your next project, hopefully you'll find this series interesting and it'll help take your learning to the next level with all that Hathaway that's mixed up and building our first robot. 2. Building a Simple Robot: In this video, we're going to cover the basics of building a simple robot like this and explain what each of its parts of doing. So let's get to it. Core of our robots going to be discussing, and it's got two motors underneath. One connects to each wheel so we can drive each wheel independently upfront because spitting caster wheel on the top, we've got batteries to power the robot and an on-off switch, switch on and off. We're going to add to this jazzy a brain to tell the robot when to move, and a way of controlling these two. Notice this is an Arduino circuit board and it's going to form the brain of our robot. It's based around this chip, which is a microcontroller that takes inputs from the outside world like listening to when buttons are being pressed and provides outputs like telling motors to switch on and how fast to go. We can power from a battery pack just by connecting the black wire to the ground pen, my controller down here, and the red wire to be in over here. And see you devise lights up and the online comes on. I said that the Arduino can be used to control motors. But first, let's make sure we can control this LED. I set the Arduino, blink pin nine over here. So if we connect our LED between ground and pin nine, we should see it light up and start flashing away. There's a little bit of software involved in this, and we're gonna talk about that in the next video. The arduino boards great for controlling small outputs like switching LEDs on and off. But it's not designed to drive something more powerful like a motor. To drive our motors. We could connect each motor to a battery pack just by using a switch, but rather than a person turning the switch on or off, we want to let our Arduino control how fast the matrix turning and whether it's going forwards or backwards. To do this, we're gonna connect the motor vajra motor controller and use our Arduino to tell the mode controller what to do. This is I'm motor controller board is capable of controlling motor currents up to four amps, which means in the future, you'll be able to handle much bigger motors than the ones in this little robot. The connected mode controller. We apply power to the front here. So this is where our batteries connected in. And then we can connect the motor to each side here in order to tell the motors how fast to go, whether to go forward or backwards. We use these pins here and these are what we're going to connect to our Arduino. So we're gonna connect the motor via the out one and out two pins, and then connect the Arduino via three more pins. These pins tell the motor when to go forwards, went to go backwards, and how fast to go. Just like before we need to provide power to the Arduino through the V-in pin and ground. And we need to provide power to the motor controller by our ground and plus 12 volts pen. Making all of these connections is just a case of plugging in each word in turn and taking care to make sure we get them all in the right place. If anything doesn't work after connecting up, it's worth going back and checking all of the collections go to the right point on each board. The white collars here aren't important. They just help make it easier to trace the connections through. Once everything is connected up, we can insert the batteries. And now using some software on our Arduino, instead of just controlling an LED, we can control the motor to connecting our second motor is just the same as before, are two wires that go to the motor and three wires that go to the Arduino to control it. Once we've got everything hooked up, our Arduino can control both of the motors, robots, we're ready to start driving itself around. Finally, to stop these boards, move it around and then to hold them in place with some of their sticky back velcro. We've now got all the parts connected up, ready for our robot to drive itself around like this. In the next video, we'll talk about some of the software I'm using here to tell it what to do. Thanks for watching. I'll catch you next time. 3. Getting Started with Arduino Coding: In a previous video, we put together the hardware for this simple Arduino control robot. In this video, we're going to cover some of the basics of working with the Arduino and explain some of the software to get some LEDs blinking. We load software onto the Arduino board using a program called the Arduino IDE, you can find this software bug Googling Arduino and following the links the Arduino website, check the download section of the site and click to download the installer. Installers are available for Windows, Mac, and Linux, or pick the right one for your machine. The download shouldn't take long, and then you can run the installer to get things set up. Once the installation is complete, the Arduino icon should appear on your desktop and you can plug in the board via USB and launch the program. From this window, we can type in code and uploaded to the board to see it run. And we're going to start by loading an example, by going to file examples basics and then selecting blinked will look out this example works in a minute, but to start off, I'm just going to click the upload button in the top bar and have a look at what happens on the Arduino board. So we get message here to tell us that this is compiling and then uploading. And when it's done, this little LED by this pin 13 starts to flash on and off. Now, I know this doesn't look like much, but it's all being controlled by that software we just loaded. So let's take a closer look at how it works. This is the code we just uploaded, the top section here, our comments on what the code is and what it does. The top line here says that it turns an LED on for 1 second, then offer 1 second. The next section down here is called the setup function, and it runs once every time the software starts. In this example, the subfunction is only doing one thing which is setting pin 13 of the Arduino as an output so that we can send a signal out of the Arduino into the LED to turn it on and off. The final part of this code is called the loop function that gets run over and over all the time that power is connected to the Arduino. The loop function In the Blink example only has four lines. The first line says digitalWrite 13 high, which turns the thing connected to pin 13. On. The next line is delay 11000 or wait for 100 microseconds, which is 1 second. The third line feeds digitalWrite 13 low or turn the thing connected to pin 13 off again. And the final line says delay 11000 again, or wait for another second. These four lines of code are going to get repeated over and over all the time that power is connected to the board. To get a better feel for how this code works, lets make a small change and test it. As an example, let's take the delay from 1000 milliseconds and change it 200 milliseconds or 1 fifth of a second. Since the code will be waiting less time between turning the LED on and off, this change should make the LED blink a lot faster. Clicking Upload and taking another look at the Arduino, we can see that they see melody is blinking five times faster than it was before. This simple trick is an easy way to control the timing of not just LEDs, but in future videos we'll see how we can use it to control motors as well. Controlling timing will come in handy, but there's only so much you can do with one LED. So that's another connection to a different pen. So we can look at controlling multiple things at once. We can control any of the pins on the board, but let's have another LED to pin eight. The connection to this go between eight here and ground on the right. Next up, we're going to need to modify the code to control this LED versus change will be in the setup function before we had pin 13 as an output. And now we need to add another line of code set pin eight is now put in the same way. Inside the loop function. Let's add two new lines, wants to in the new LED on and the other to turn it off. And just to show that these are working independently, let's meet the new LED on when the old borons off and vice versa. So while we're at it, let's tweak the delay one more time and change that to a 2.5th. And then we can try this code on the board. So I'm just going to click upload one last time. And then by checking out the board, we should see that we now have two LEDs blinking alternately. By playing around with the delays, we can create patterns like this. And by adding more pins are more LEDs. We can even create sequences like this one which should be perfect, some custom Christmas lights. In this video, we talked about how to live software onto an Arduino microcontroller. We've loaded some examples and we modify those examples to blink a couple of LEDs on the board. Jakarta description for a bit more information, and I'll catch you next time. 4. Simple Motor Control: In previous videos we've looked and how can you suffer it control simple stuff like MDs. But in this video we're stepping up tomorrow. I'm going to talk about how to control the speed and direction and introduce some important concepts like pulse-width modulation. And now we can use that to get a robot even for the first time. We're going to start by reintroducing a remote control that we use to build the robot in, BUT aren't we use what's called an L2 98? And before we dive into programming again, that's just recap how we connected up in the first video. Like controlling LEDs. Each motor requires three connections to control it. To understand more about how these connections work, we need to take a look at the data sheet for the microcontroller. The date she tells us everything we need to know about as popped like the voltages designed to operate from how much power can handle, what the connection to doing inside the chip. The detail of how the ship works is beyond the scope of this video. The main thing we need to understand, these TTY connections control the direction that my disc spins by turning on and off certain parts of the chip. And then this connection controls how fast limits should ten to make them much spin forward, we pull one of these pins, Hi, I'm one of these pins low. And to make the motor spin backwards, we do the opposite. So this pen is low and this one is high. See what this means for our software, I'm going to stop. I'm making a note of which pain is connected to which the TTY connections controlling the direction get pins 23. And the connection controlling motor speed is connected to pin nine. In the setup part of our program, we need to define each of these outputs from the aqui known as the signals are coming out to the Arduino and then into the microcontroller. Once these is setup to make them much spin forward, we said the directions as we described earlier. So one direction pin is high and the other is low. And then we can set them to turning by pulling the speed pin high. Asked with the LED example in a previous video, we can use delays to control the timing of behavior. So I'm adding a 2.5th delay than pulling speak in low to stop the motor. And remember everything in this loop function where P over and over again, uploading this code, we've not on motor running and we can control when it starts and stops. So far, we can control the direction of the Motown, such as spinning. But it's also really useful to control its speed. And for this, we'll use a technique called pulse-width modulation. Rather than keeping the speed pin permanently high for all the time that we need to know to spinning, we're going to talk very quickly, high and low, to effectively stop and stop the motor thousands of times per second. The length of time we leave the micro ohm versus the time we leave off will dictate how quickly the motor's spinning. This fraction of Tom, the metrics on during each period is called the duty cycle. And encode is represented as a number between 0255, setting the duty-cycle to 0 the speed pin always stays low and the metro stopped setting the duty cycle to 255. The speed pin always stays high and the motor spins faster speed. Setting the duty cycle in the middle of a 127, the speed pin quickly toggles between high and low and the motor spins at roughly half speed. We can set the duty cycle anywhere between 0255 to get exactly the boat speed we want. Back in the software we controlled teach cycle using the animal bright command. So we just need to modify the lines where we set the speed up and we can now set it to any value we want to control speed being controlled a second motor in exactly the same way, just using three new pin. So that's out those into the software. Now, with these lines added, we've got everything we need to get a robot moving. Using these few commands, we can control the speed of the robot and also steer. By running the left-most is slower than the right. The robot will turn to the left by running the right motor slower, the robot will turn to the right. We can even get the robot to turn on the spot by running OneNote forwards while the other one runs backwards. Putting this all together, we can create sequences that will get our robot following any path we want. And that's it. I hope you enjoyed this video. We've covered some of the basics of motor control and got robot moving. In the final part of the series, we're going to look at controlling more powerful motors for bigger and better projects. So I'll see you in the next video. 5. Controlling Electric Drill Motors: In this video, we're going to take another look at the LTE 98 mode controller and see if we can use it to control the motor in this drill. What I love about the modes is in electric drills is that they're powerful enough to start moving bigger and heavier objects. But they get a lot more interesting when we can program them to move whenever we want. Control less speed and even connect them to remote controls. That's where I mode controller comes in. When the drill turns, an electric current flow from the battery pack through the motor coils in order to have enough power to cut through wood or metal, the motor in the drill can draw currents of several amps. To handle the large motor currents, we're gonna use the LTE 98 motor controller and connected between the battery pack and the drill motor. To tell the mode controller how fast the motor should turn and which direction it should go. We can use some small control signals from an Arduino microcontroller. The arduino also requires power, which we can take from the same battery pack. The motor connects via the outworn and out two pins on the mode controller. And we'll connect to the Arduino via pins to 39. We can power the Arduino through the ground and V-in pins. And we can power the motor controller virus ground and plus 12 volt connection. To connect up the motor. I'm opening up the case work of the drill so we can get access to the motors connections. It would be best to remove the motor entirely for this. But for a quick test, I'm going to connect a promoter using a couple of crocodile clips and place the drilling neutral. To get our motor spinning. We're going to need some software. I've covered getting started with arduino software and know the video. So let's just dive straight into the code. First thing we need to do is define our control signals pins to 39 as outputs. And we'll do that in the setup function. In the loop function we'll add code to make the motor spin forwards using pins 23. Notice pin two is high and pin three is low. To make the motor spin backwards, we set these the opposite way round. We can then use the analog write command and pin nine to set the motor speed. The motor speed can be set to any number between 0255, we'll set it to 200 here as an example. Once we set the motor speed will have the code wait for 1 second, then will slow the motor down to 50. Wait another second, and then repeat this code in the loop. Once the code is done and click the Upload button to load it onto the board. When we connect a battery pack with software starts to run and the motor runs quickly for 1 second, then slowly for 1 second over and over in a loop. Just like we set it to. By expanding on this code will be able to get the motor to run forwards or backwards at any speed we want. Upset that I draw mode can draw currents of several amps and I let loyalty 98 merge controller is only designed to provide two amps continuously from each of its motor outputs. And it will get very hot when it's working hard. Luckily, instead of using the L2 98 drive to 2AB motors, we can combine its outputs to drive one larger forum motor. Instead. To do this, we have to connect together the outputs of both motors and also connect the Arduino to the inputs for both motors. But once we've done this, we can drive a single motor with up to four amps. In this video, we've managed to control an electric drill motor using an Arduino and remote controller. By experimenting with the software, we've got everything we need to get some simple robots moving. Check out the description for links to the parts and code used and our catch you next time.