00:00:03 | Hey, what's up, everyone? So this video, I wanted to be a little bit different format, so I made a YouTube short about some of my first experiences with Arduino. I initially wanted to try to get an addressable LED strip working, and I also wanted to make sure that the Arduino was capable of powering a stepper motor. |
00:00:26 | I was able to watch a few YouTube videos, and I was able to figure out how to get the addressable LED strip working. And I also got the stepper motor working with a stepper motor controller that I bought specifically for the Arduino. So those are two separate YouTube shorts that I put out. And if you want to see those, you can definitely check them out on my channel. |
00:00:46 | As always, please like and subscribe if you want to see more of this. But as many of you know, if you've been watching along, following along, I'm building a robot that is capable of using artificial intelligence to recognize numismatically interesting coins. That means coins that I want to add to my own penny collection. |
00:01:07 | The challenge of that I showed in a previous animation is that I really want a stepper motor to move the coin forward, and then we're going to have to light the coin from different angles and then retract the coin. So that is going to require two stepper motors as well as a bunch of LEDs on that addressable strip. So the challenge in today's video is |
00:01:33 | to really get those two things working together. I really want to be able to connect two stepper motors and have a big, long string of addressable LEDs connected to the same circuit and try to get them all coordinated. So without further ado, let's get going. So in my first video, you saw that we had built this circuit. |
00:01:58 | I just went on ebay and I bought some breadboards. And this is pretty simple. It was powered by USB through these two connectors. The positive lead here is red, and the negative lead is black. That is 5 volts in from the USB port. And I was just using the USB port on my laptop here to power up this board. |
00:02:22 | Now, across those two leads, you can see that the negative power rail here continues all the way vertically here. And same with the positive, those rails run vertically along the breadboard here. In parallel with that, we have a capacitor, which I believe is 100 microfarads. That is to reduce the amount of fluctuations on the five volt power rail. |
00:02:51 | And we are taking that 5 volts out and plugging it directly into the LED strip. So that would be the white and the red wires on the LED strip itself. So in this case, we're using an addressable circle light here, but each one of these lights is addressable very similar to how those LED strips are addressable. Now, as far as the data line is concerned, |
00:03:19 | that takes data you can identify which pin you're going to take data in on the Arduino board using the software, we were taking a data pin, I believe it was, pin 2 on the Arduino and running it through a resistor. I will put the resistance, the Ohm level of this resistor up on the screen so that you can see it, because I don't really remember what it was, but that just goes through a resistor |
00:03:45 | again, to reduce the amount of power going through this wire and then ending up to the data line, which is the center green wire on this particular LED strip. The challenge with that is to combine it with this second board that I've created from what I've gathered on YouTube University. I don't want to power any of these devices directly from the Arduino board because I am concerned that I will burn out components on the Arduino. |
00:04:17 | But basically I'm powering everything from a nine volt cable that comes in from a power adapter, which here in the US is 120 volts and that gets stepped down and converted to DC so that we have 9 volts. And the positive is the center pin on this particular outlet, that also has a power switch here that I can turn on and off. |
00:04:45 | So right now the power is off to the board, but again, that 9 volts here comes in on this particular rail. And I have the center post going to the positive rail. Again, which runs vertically on these breadboards and the negative side again, runs vertically along this breadboard. Here I have a transistor, I believe that's a 7890 transistor |
00:05:12 | that brings positive 9 volts into one side of the transistor and it takes the negative lead from the nine volt rail and puts that into the center pin. We're still calling that ground. So from the transistor we're taking the other positive lead and we're moving that to the positive rail on the five volt side and we're connecting the ground, the negative lead to the negative rail. |
00:05:40 | So across any two points on this rail, you'll get 5 volts, and across any two leads on this rail, you'll get 9 volts. So we took this nine volt power coming out of directly basically from the rail here. We're going into the voltage input, the VIN pin on the Arduino and the negative is going to the ground on the power rail of the Arduino. As far as the motor controller is |
00:06:14 | concerned, there is a nice diagram, there's a spec sheet that goes along with this particular controller and I can post a link to that in the description. But basically you're controlling the four input leads of this controller board with four pins on the Arduino. The Arduino has output pins 11, 10, 9, and 8, and those are in turn going to input pins 1, 2, 3, and 4 on this particular controller board. |
00:06:40 | Now, this stepper motor is already wired up for this particular controller and I'm going to turn this on in a , but you can see that once I turn this on, the ARDUINO is already programmed to move this stepper motor. So you see the ARDUINO power on the controller board power on, and I believe the motor is programmed to rotate in one direction, one full revolution, and then rotate back the other direction. |
00:07:15 | So that'll just keep doing that back and forth according to the programming that I have. So like I said, the challenge now is to combine these two circuits. I want to combine this Addressable LED strip and put it on the same circuit as the stepper motor that I have controlled here already. So what I'm going to do is I'm going |
00:07:35 | to take all of the leads that are currently on this board and move them over to this board that has both 9 volts and 5 volts going into it. So I really need to be careful here because I want to make sure that I'm not adding 9 volts to something that should only get 5 volts. And I don't want to add 5 volts to something that requires 9 volts to operate on this board. |
00:08:01 | We have a five volt rail only. I'm going to take that capacitor off and I'm going to stick it onto the five volt rail on my ARDUINO breadboard here and I'm just going to remove the two power cables from that board and I can actually get rid of them because this rail is already powered with 5 volts. We're going to take this resistor out |
00:08:26 | of this breadboard and we'll stick it over here on this breadboard. And again, I will try my best to upload a circuit diagram so you can see exactly what I'm doing. But now we just have an orange wire here that's going to a resistor, it's jumping across the break. We're going to take the other side |
00:08:45 | of that data cable and connect it to the other side of the resistor. And I'm going to choose a position that's near the capacitor, but it doesn't really matter where also that's plugged in this capacitor again should just smooth out the voltage across that five volt power route, but it shouldn't affect the motor controller. So we make sure that the red is plugged |
00:09:15 | into the positive and the negative is plugged into the ground. And so we have now successfully, in theory, we've successfully moved this LED addressable LED strip over to the same circuit that is now powering the stepper motor. Okay, so the stepper motor controller and the Addressable LED strip both use 5 volts for their power supply. |
00:09:48 | The only thing that's really using 9 volts right now is the ARDUINO itself. So we're powering the ARDUINO with 9 volts and we are using 5 volts to power both the stepper motor controller and also the Addressable Led strip here. I think what I'm going to do is I'm just going to swap these data cables so that they're on opposite sides of the breadboard. I'm just going to move their position just |
00:10:15 | so that it's a little easier to get that data line over to the ARDUINO. So we're going to take that again on the other side of the resistor here, and we're going to jump that over to and I'm just going to pick a pin arbitrarily, but I'm going to choose pin 2. So now we have the LED strip, which in theory is going to be powered, or data from pin 2 is going to be given |
00:10:43 | to the LED script and data from Pins 11, 10, 9, and 8 they will be used to power the stepper motor controller. Now that we've combined both circuits onto the same breadboard here, we need to basically do the same thing in the software. So I'm going to go over to the laptop and combine both pieces of software. So right now this is showing the stepper motor controller software. |
00:11:12 | I'm actually going to save this file as a different file name, just so we don't get confused here. But we're going to call this "Eight_LEDs_Plus_Stepper." And you saw that I copied the code from the LED version, and I'm just going to paste that in here, just arbitrarily, because I'm going to use pieces of each of these. |
00:11:42 | Now, I really haven't done much to either of these pieces of software that I downloaded from two separate YouTube videos. I've just taken the setup code from each and made sure that was in the setup block. And I've also taken the main code from each of those separate pieces of software and pasted them into the main code of this combined document. So that's what we're going to be doing here. |
00:12:06 | Now that we have that set up, I'm just going to plug in the ARDUINO to the USB port. I'm going to download that to the ARDUINO, push it out to the ARDUINO to program it, and we'll see what happens. What should happen is that we should see some lights light up on the LED strip here, and then we should see the motor |
00:12:25 | turning, and I can get a little bit more specific and fine tune that about how each one of those works and what order they do that in after. But I want to just make sure that this is kind of working nicely together, and we'll see if it releases any magic smoke. So one second. Here goes nothing. I'm going to plug the USB cable in, |
00:12:51 | and I'm also going to power it on. And then we're going to upload that to the ARDUINO. Okay, so it's working. I'm actually surprised by that. You can't really see this on camera too. Well, you might be able to see it from this angle a little bit better. But I have one light programmed to be white, |
00:13:15 | one programmed to be green, and another let's see if I can cover these things. Can see them, so you can't really see it on screen. But one light is green, this light is white, and that light is blue. And also you can see that the stepper motor is still working. So basically the code is working. Now we have the LED, the addressable LED |
00:13:40 | strip, and the stepper motor both being controlled from the same ARDUINO board. So that's great. We know that code works. Now we just want to tweak the code a little bit to make sure that we get things going in the proper sequence of events. So as I showed in a previous video, I created an animation that showed the basic sequence of events that I want to have happen. |
00:14:01 | So as you can see here in this animation, the coin is going to be pushed forward over two cameras. Where those cameras are located, I'm also going to have lights above and below the coin so that it can be lit from different angles. So we're going to rotate the stepper motor in one direction, one full revolution. We're going to address the LED strip so that each light turns on in sequence. |
00:14:29 | Then we're going to rotate the stepper motor in the opposite direction to retract the slider. And at some later date, we will add a second stepper motor that will turn the coin sorter for us. So that's the sequence of events, all of our setup will remain the same. I'm just going to move this down a little bit. |
00:14:49 | As you can see in this void move, we have the LEDs lighting up, and then we have the stepper motor doing stuff, but these are actually doing these nonstop. So the ARDUINO is constantly sending out signals to all of these things. But like I said, we want to have the stepper motor move in one direction. And we're calling that, we're going to say clockwise. And then we want the lights to light up. |
00:15:16 | So I'm going to take this light code here and I'm going to move that in between the two loops of the stepper motor. So let's see how that goes. Now we have the stepper motor moving clockwise for one revolution. And then we have a delay of 500 milliseconds. Next we are going to address the LEDs and we have different colors here. |
00:15:45 | Like I said, this is a white light. I'm going to change all of these to white because we're going to address these individually. There are eight of them, so we're just going to repeat this code. 1, 2, 3, 4, 5, 6, and 7. So that's 8 LEDs total. |
00:16:12 | So zero through seven. And we can do this in a loop, but for now, I just want to see. We're going to put a delay in here. We definitely need to make this a loop, but for now, I'm going to do stupid programming and not make it a loop just to see if this works. I want to make sure that the idea is there. |
00:16:38 | I think actually, I'm going to, for now, I will just comment these out just to make sure that the first three LEDs work. And I think what I want to do I'm not exactly sure how to turn those off. There must be a FastLED command to stop sending the signal to each of these. But I think for now, let's just see how this works. My theory right now is that the first |
00:17:09 | light will show for half a second, then the second light will show white for half a second, then the third light will show for half a second. I think we'll see how that goes. But let me plug this in. Push this code back out to the ARDUINO verified. And that seems okay. I'm going to save this, |
00:17:31 | and then we will push it out to the ARDUINO and see what happens. So we're moving the stepper motor. One revolution in theory, which is great. So you saw these lights come on in sequence, and then the motor rotated back the other direction. So the thing we need to figure out now is how to turn these lights off. |
00:17:56 | But the code is basically working. We got it to rotate clockwise, and then we got the lights to turn on in sequence. Then we need the lights to turn back off. So we'll get that working next. And ideally, we put those in a loop so |
00:18:16 | that it just triggers each light and each camera action eventually. But we want to trigger the light, trigger a picture, then move to the next light, trigger a picture, so on and so forth. Okay, I'm going to unplug the USB cable this time, and then I'll turn the power off. Okay, I'm going to do a little bit of googling to figure out what the command is |
00:18:44 | to turn off the LEDs so it looks like you can actually set the pixel to black, which would be all zeros in the RGB spectrum. Or you can send the code "FastLED.clear" to the ARDUINO board, and that will clear all of the LED strip. So let's try one of those methods here, and we'll see how that goes. And we're going to do that after the delay. |
00:19:12 | So we're going to delay for 500 milliseconds and then clear it. So hopefully this will work. And again, we won't do it in a loop right now, just for simplicity sake, and because I'm too lazy to figure out how to do the loop right now. But we will get that working. |
00:19:32 | Okay, so in theory, that's what we need. We need the first LED addressed at "0" to be white. And we are going to show that and then we're going to wait half a second and then clear all of the LEDs. So that's what this command does. We could actually set this LED |
00:19:53 | back to all zeros, but again, we won't do that just yet. So let's turn that back on. We'll plug this back in. Once we get our little chime there. We know that the ARDUINO is working. We're going to verify our code, |
00:20:14 | and we are going to push that out to the ARDUINO. So it's loading good. We're going to rotate the stepper motor one complete revolution, turn these lights on one at a time. It looks like we're doing pretty well, except we got this one LED that stuck, so we need to turn that off, |
00:20:57 | and I think that might be because we need to have another "FastLED.show" after the last time we clear. So we clear all of the pins of the data being sent to them, and then we show that they're clear. Okay, good. So let's verify that one more time, and we are going to send that to the ARDUINO. |
00:21:34 | You'll see everything stop here and then it will start up again. So we started about here. We want to do one complete revolution. Good. So our Led is doing what it's supposed to do now, too. You'll see the [three] LEDs come |
00:21:59 | on in sequence, so I'm pretty happy with this so far. I'm going to get that LED code in a loop so that it lights up all eight of these lights before turning the motor back over. But otherwise, I'm pretty happy that we have working code and we have a working circuit, so I'm pretty happy with that, considering my background in ARDUINOs is not that great. |
00:22:24 | So we'll see how that goes. All right, so I've done a little Google research, and I understand a little better how to do this loop for the RGB lights here. We're going to make a for loop. Right now, the way this works is it's going to count zero through seven in this loop, and in each loop, it will turn on each light, respectively. |
00:23:12 | It'll turn it on white, it'll show the light for half a second. And at this point, we actually want to trigger the camera, trigger the camera there. And then we're going to turn off the light in sequence, so it's going to go through all eight lights on the LED strip, and then it will turn the stepper motor one revolution backwards. |
00:23:44 | Okay, so now that we have the code set up, I'm going to turn the board back on, and I'm going to push that new code out to the ARDUINO, check our code and save it. And then we're going to push it out and hopefully . . . See this pause. That's about where it started. So this is 2048 steps. It looks like it did make a complete revolution. |
00:24:21 | And you can see now that each of the eight lights are coming on in sequence, and then the stepper motor will go back counter clockwise, one complete revolution. Oh, good. So 2048 steps seems to be one revolution. So we got that right. |
00:24:42 | I don't know where I downloaded that from, but that seems to be accurate. So that's great. Okay, so I'm pretty excited about that. It seemed to work out pretty well. As you can see, the motor is turning one direction, the lights are coming on in sequence, and then the stepper motor is turning back in the opposite direction. |
00:24:59 | So those are all really the pieces that we need for the mechanics of the machine to work. The only other thing that we need to figure out is how to trigger the camera. And I think that's going to require a Raspberry Pi, which I already have purchased. But we will have to get the ARDUINO now |
00:25:17 | to talk to the Raspberry Pi in order to get the camera to trigger. We'll also try to run the AI from the Raspberry Pi as well to see how quickly that will work. But for today, I think that's enough for this video. If you like this type of content, I hope you'll leave a comment down below that you'll hit the like button for this video, and that you'll also subscribe |
00:25:38 | to the channel so you can see how we're making out here. If you have any questions about how I did any of this, please leave a comment down below, and I will try to answer them in the next video. Or I will answer your comment down below. Until next time, I hope you have a great day, and I look forward to seeing you in the next video. |
00:25:50 | Thanks, everyone, for watching. I appreciate this. I appreciate your support, and I really look forward to making the next video. Thanks everyone! Bye. |