字幕列表 影片播放 列印英文字幕 Welcome to DIY Tryin. Build something new. I'm Patrick Norton. I'm Michael Hand. We were going to bring you the most amazing confluence of aluminum gas welding and lemons today. But that failed horribly. Yes. Yes, it did. So instead, Arduinos. Yay! What's an Arduino? So Arduino is a microcontroller that you can program to do tons, infinite things. It's a controller or a microcontroller. There's, like, 32,000 variations of these, from BASIC PIC Stamp through Arduino. Some people use Raspberry Pi. I'm thinking the cover of Make Magazine this month has 300,000 different controllers inside of it. I mean, a controller controls things, right? Yeah, exactly. So like I said, it's something that you can program to do a whole range of things. So in this case, we're going to show off how to control high-powered applications, or do high-powered applications, with this little low-powered Arduino. And what's crazy is by combining some kind of controller, like the Arduino, and some software you can probably download off the internet, probably will have to download off the internet, you can make things do things-- like automate a dorm-room entertainment system, or make sure some lights get turned on every time your garage is opened, or that a song plays every time your cat sits down on its bed. It's just-- the limit is your imagination. Exactly. Controller boards, you can pick them up at Radio Shack now. You got yours off of-- I got mine off of eBay, I think, for $12. Because it's cheap and they all seem to work, in my experience. This is good. So what's with the Flying Spaghetti Monster homage of wiring? OK, so beyond the microcontroller, we also have this relay board. This is an eight-channel board, so that means that we can power eight different things this way. Well, you can turn eight different things on or off. On or off, so a relay board is super old school, in that it's just like a remote-controlled switch that this is a physical switch that's switching on and off. There's a chance every time you turn the headlights on in your car, a relay is actually doing the switching. I mean, these are basically-- as far as electronics are concerned, this is Stone Age technology. So these are cool, that it's looking for a 5-volt signal. And when it gets that 5-volt signal, it turns on. And by turning on, I mean it closes the connection, and then closes the loop. Yeah, you send voltage in this end. It does magic. It closes the switch at this end. And I love reading the specs-- 10 amps, 250 volts AC, 10 amps, 30 volts DC. That means 120 volts, 220 volts, as long as it's not higher than 10 amps, 30 volts DC, as long as it's not higher than 10 amps-- anything up to that maximum. That's really awesome. That's a lot of juice to work with. Yes. So the way I have this set up is that I have a ground going to the relay switch. And then I have pins 2 to 9 here-- that equals eight, right? I think so. Yeah, pins 2 to 9, that those are controllable, so that I can say OK, send a signal. And then when it gets that signal, then it'll turn on. Hence the controller part of the Arduino, but there's more purple wires. Yes, so this-- I have it set up so that it has an external power supply. Because from what I understand, with these big, eight-channel boards, the Arduino doesn't have enough power or enough amperage to turn all of them on or off at a time. So I don't want to burn out my board. So I have this external supplier that will supply the power to actually close the gates. Like, one to four relays you found that you can supply off the board without burning it out. Yeah, exactly. Then things like sketchy. Then I just was scared. What are we controlling, and how are we controlling it? Is that where the software comes in? This is where the software comes in. So right now, we have some LED lamps plugged in here. And that's a 12-volt load. This is 12 volts, which is still way more than the Arduino can do. It can do five volts. And then we also have an AC application here. We have a fan plugged in here. Don't worry. This is safe, not like last week-- hopefully, we think-- or the week before last week. So let's jump into the software, and I'll show you how this is actually connected. Cool. How this is powered. First, you need the actual Arduino software, which you can find at Arduino.cc. It's downloads for, I think, Mac, Linux, everything. Intel Galileo. So once you have that downloaded, you'll see you have this cool little software here. And the nice thing about Arduino especially is that smart people have figured out how to do whole lots of things already. Yay. So I found on this Arduino dash info dot Wikispaces dot com, someone already wrote code to control a relay. AKA Arduino power. Yes, so I just straight copied and pasted this code into our Arduino software here. I'm going to say it, because it's my job-- is that legal, Michael? Probably, they put it on the internet. It's generally accepted and cool. OK. Just saying. So the way you actually send code to the Arduino is that you make sure you have it connected to your computer. So this just has a USB cable. So first of I'll compile the software, and then I'll upload. So if you're getting errors here, you probably have to select the port that you want to be on. Things are happening. In this case, I have the USB. But it worked. And as you can see, this code cycles through. It turns on all the switches, and then turns them off. It doesn't have to cycle them. It's just what this particular application is doing. Yeah, so this is very basic on how you get an idea of what things in the code you actually need. And then from there, you can start playing with the code. So in this case, it's setting to be, like, a one-second delay. If we want to get crazy, we can set it to be, like, 40 milliseconds. Which, when I-- You'll break my fan. So I just sent it. It'll take four seconds. And then, oh, awesome. And the thing I love about the mechanical relay is you can hear them switching over. So I'll just let this go for the rest of the episode. (DRUMMING) OK, maybe not. A little annoying. So instead I have this code that I kind of expanded a little bit. It's definitely not the cleanest code ever, but I'm sorry everyone. It works. So another cool thing you can do with Arduinos, is-- that last application, you could take this. It's all self-contained. It doesn't need to be connected to a computer. So you can just power the Arduino and it will cycle through that forever, if you want. You could have a crazy light display, or you could use it to control neon light transformers or something. Yeah, but if you want to have it so that it's listening for something, so now I brought in a serial port. So that the Arduino has a port that you can send commands to, and then doing that, it'll do whatever you set it to do. So I have it set up so that it's listening for different keys. So if I hit one, it'll turn on the first relay. And if I want to turn it back off, I hit one again. So switching physical universe things on and off your computer, I don't know why I still find this incredibly fascinating. So the serial port can be very, very useful if you want to send commands to your Arduino. And hey, while I'm still here, you should check out Audible. Go to audiblepodcast.com/diy and you'll get a free audio book of your choice, and you'll help support the show. Nice segue, huh? So part of the reason you got involved with the relays was so that you could do stuff. We're going to do something kind of exciting in the next few weeks with hard science again, not controlling lights, but controlling something else. Screaming may be involved. We'll go more in depth with that, but I can show you a little-- just to finish this off, I have it set up so that I have a Python script here listening for numbers. So I could be, like, bum bum bum bum bum bum light show. Ladies and gentlemen, would you like to learn how to make things do things, and just learn how to get your diy on? Please subscribe to DIYTryin.com or YouTube.com/DIYTryin. I love how it through to the fan. That was beautiful. At DIY Tryin on the Twitters. And rumor has it, there may even be a place to hang out with us on Reddit. And if there is, you'll see it down below. And if you're on YouTube, please comment down below. I'm Patrick Norton. I'm Michael Hand. We'll see you next week on DIY Tryin. What did that look like, Liz? It looked really good. Oh, my god.