Это видео недоступно.
Сожалеем об этом.
Arduino Tutorial 65: Creating Useful Commands from IR Remote Buttons
HTML-код
- Опубликовано: 8 июн 2020
- You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In this tutorial we show you had to add an Infrared (IR) remote to your arduino project. This lesson shows how to map the HEX code coming from the IR module into useful commands.
You can get the kit I am using for this series at the following link:
amzn.to/2I7N4Ek
I strongly suggest picking up an arduino nano, since it can plug directly into the breadboard, making a portable system more practical. You can pick one up here:
amzn.to/2WXTC2M
As projects get more complicated in these lessons, you guys really need to get a set of breadboard jumper wires which allow you to make neater connections on the board in your projects. You can pick a pack of these wires up here:
amzn.to/2XrY5Kq
In addition as projects get more complicated, you are going to need a bigger breadboard. This is a reasonable one here:
amzn.to/2IY4d3M
You can get the code and other details on our WEB site HERE:
toptechboy.com...
[Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. This means if you visit the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers.]
#Arduino
You have kept me motivated throughout this series creating value for me every step on the way! I wish you a long and happy life. I am by nature, frugal, so understand how truly appreciative I am.
Thanks! Really appreciate the support, it means a lot to me.
Did this before watching the video.
I placed the delay at the very last line so that as the remote is pressed, the String almost instantaneously prints in the serial monitor.
Thank you for this Sir Paul!
Thats a GREAT Idea. Also lowered the delay to (100) and now it is "super snappy"
Great lecture. Hardware differences made it necessary to go another way, but I got it working and the possibilities are obvious.
Thanks for another great tutorial Paul. I love working along with you in your natural, relaxed style. I did the assignment by building on Tutorial 40, controlling the DC motor using push buttons, and using the nano rather than the uno. Looking forward to the robot car tutorials. Keep up the great work!
Thanks again Paul. I ended up getting over my little cheap remote not working consistently and mixing up the data every now and then so I decoded the tv remote in my hotel room instead and used that haha. It was working spot on every time and made the project just that little bit easier.
Excellent!
Maybe I will be able to figure out the remote on my garage door opener using your complete analysis!
I did the homework. Have got my robot car from Amazon ready for the new tutorials.
Thanks Paul.
Hey Paul, I know you have moved on to bigger/better things these days, but are there any future plans for more Arduino lessons? I am sure many of us would greatly appreciate that AND work along with your videos. There are so many great things one can do with these amazing microcontrollers!!! I would love to see a build series where you build a project and we work along with you. Either way, you are an amazing person and an EXCELLENT teacher. Thank you for all the effort you have put into these wonderful lessons.
I need to redo the arduino lessons at some point and maybe go into more advanced projects.
@@paulmcwhorter Please do, That would be wonderful :D :D :D You could give us a parts list at the beginning of each lesson so that we can work along with you.
@@paulmcwhorter I would also love to see some tutorials on more advanced projects and skills!
Awesome!! Also, please don't be afraid to ask us to buy some new pieces that are not included in the elego kit. I bought the nano and the flat wires and i tell you, they make a huge difference!
I am legend, and your tutorials make it easier!
thank you paul
LEGEND!
I am legend. Great tutor again - it is really better if we do our home work in advance, then the lectures are really smooth.
Yes I did this as homework. I reduced the 1500mS delay to 750mS, for a faster response, and also added a line to print "End of List", to confirm that the list has been parsed. Thanks for another great video. Looking forward to controlling the fan and motor.
Nice work!
I managed to get it to work ok. Found that you can shorten the number of code lines be having only one "Serial.println(myCom);" after all the if clauses and before the delay. A very satisfying project.
You can use the "switch" statement to make the code much shorter.
What would the switch statement replace? Thanks.
@@roxleyldc it would replace all those if statements
You could use an array as well:
long IRButtons[] = {0xBA45FF00, 0xB946FF00, 0xB847FF00, 0xBB44FF00, 0xBF40FF00, 0xBC43FF00, 0xF807FF00, 0xEA15FF00, 0xF609FF00, 0xE916FF00, 0xE619FF00, 0xF20DFF00, 0xF30CFF00, 0xE718FF00, 0xA15EFF00, 0xF708FF00, 0xE31CFF00, 0xA55AFF00, 0xBD42FF00, 0xAD52FF00, 0xB54AFF00};
String txtButtons[] = {"PWR", "vUp", "Fnc/Stop", "Left", "Stop/Go", "Right", "Dn", "vDn", "Up", "Zero", "Eq", "St/Rept", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
...
for (int i = 0; i < 21; i++) {
if (IRCommand == IRButtons[i]) {
Serial.println(txtButtons[i]);
break;
}
}
Thank you so much! I decided to play with it and connected RGB LED and LED display!
It was so much fun, thank you!
I am happy that I bought a new breadboard and nano as you suggested!
Wishing the best for you and your family!
I am LEGEND. Added an additional function that contained a switch statement that printed what button was clicked that was based on the HEX code. Great tutorial. Onto #65
Hi Mr. Paul , im a fan of of your classes and your ability to transmit knowlege. Now Im basically on my own but i found a difficulty in the process to use two similar devices in arduino. There is no a clear explanation on how to configure and manage these situation , please include a class for this situation. You are the best teacher in these technology.
Now we're having fun. Loving this course.
Thank you Sir! Thanks to your videos by lesson 6 I was already able to make my own proyect and program... FYI, you are a great teacher!!
Am always grateful. Best teacher ever 💪
Got it working quite well had a bit of trouble at first thought it was my code but it actually was my circuit setup. I was also able to get the Power button to function as an on and off switch. A fun little project to make I will probably an LCD display to let the user know what fan speed and mode they are on.
Them: "The best Arduino tutorial doesn't exist!"
Paul McWhorter: "Hold my coffee"
Thank you so much for this tutorial sir. I've almost completed it and learnt a lot!
Good one!
Another great lesson and one that will be extremely useful to my students for their robotics projects, I am doing the homework tonight. It is extremely important to do the homework, trying it out on your own rather than copying code because you learn more from your mistake than you do from copying and pasting!! See you in the next lesson. Thanks again!
Fantastic!
Dear Paul, thanks for your great Arduino tutorials. I did the project of this lesson, and it worked correctly.
Sir, how to make library of IRremote to own..please 🙏🙏🙏 make a tutorial at this .....I have completed all tutorial of this series.. it's pleasure for me that you are my great teacher...
Nice stuff with IR, good job Paul
Lesson 66 is going to be very very interesting..Thank u sir..
great lessons i have learned lots
Gettng inside the mouth of the machine, almost like being a dentist, tooth by tooth😂. I had no idea, thanks, Paul!
Sir can you make a new raspberry pie tutorials
Waiting for your reply
#with love from india
yeah it would be helpful
I think it does exist in his playlist
Super project and I guess the most exciting project is coming next. The legendary Arduino magician is finally controlling everything by his programming magic, is not it? Thank you very much. God bless you.
I did the homework, it was fun.
Thank you Sir, waiting for the robotics tutorials.
yes I did the homework and had great fun playing with the program.
Ill always watch your tutorial sir you are really inspiring.. I learned arduino because of your tutorial. Keep it up sir
Hey Paul, thanks for this amazing Arduino Series. I was able to complete the assignment. Writing the code was simple as well as connecting everything. The only problem i had, which took me like 2 hours to solve, was everything seemed to work perfectly. My code did exactly what you asked to do:
Pressing power button, fan turned ON full speed forward.
Pressing rw button, fan switched direction backwards.
Pressing ff button, fan switched direction forward.
Pressing st button, fan turned OFF.
But when i pressed the vol+ or vol- (that was supposed to make the fan spin faster or slower) the fan would stop spinning and pressing the buttons on the Remote did nothing. After like an hour of checking my code and connections and even rewriting my code from zero, i decided to add a print inside the if statement and when pressing the vol+ or vol- button i realized it was not just the fan that stopped working but the whole program was crashing.
I honestly had no idea what could be causing this problem, but, after a while of thinking, i remembered that when i was reading the IRremote Github (to convert my 2.x program to 3.x) it talked about the IRremote Library and something about it using PWM. I suddenly wondered if maybe the IRremote was somehow messing up the motor when i tried to analogWrite a PWM value. I googled "irRemote library messes pwm pins" and, on the first search result, i found the solution to my problem!!
Turns out the problem was caused because i had connected my motor speed pin to digital PWM pin 3 and as the user Delta_G wrote as a response to the post "The IRRemote library uses timer 2. If you'll check, PWM is also messed up on pin 11. Pins 11 and 3 use timer 2 to drive the PWM. If it's being used for the IRRemote then they can't PWM."
I switched my motor speed pin to pin 5 and BOOM! Everything worked perfectly!
This assignment was a good one. I have learned so much thanks to you and i learn even more when i have to troubleshoot. Thank you for making this amazing Arduino Series. This is the code i wrote for the assignment if you would like to see:
#include //Includes IR Library
int IRpin=10; //Digital Pin where the IR Module Y pin is connected to
unsigned long code; //Variable to store the IR module value
String myCom; //Variable to assign a name to each Button on the Remote Control
int dir1=3;
int dir2=4;
int speedPin=5;
int mSpeed=255;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //Inicialize Serial Comunication
//Inicialize the IR Module
IrReceiver.begin(IRpin, ENABLE_LED_FEEDBACK);
pinMode(speedPin, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//We wait in the loop until there is data
while (IrReceiver.decode()==0) {
}
//When there is data, we store it in the variable code
code=IrReceiver.decodedIRData.decodedRawData;
if (code == 0xBA45FF00) myCom="power";
if (code == 0xB946FF00) myCom="vol+";
if (code == 0xBB44FF00) myCom="rw";
if (code == 0xBC43FF00) myCom="ff";
if (code == 0xEA15FF00) myCom="vol-";
if (code == 0xF20DFF00) myCom="st";
if (myCom == "power"){
digitalWrite(dir1, LOW);
digitalWrite(dir2, HIGH);
analogWrite(speedPin, 255);
}
if (myCom == "vol+"){
mSpeed=mSpeed+25;
if (mSpeed>255) mSpeed=255;
analogWrite(speedPin, mSpeed);
}
if (myCom == "rw"){ //Spin backward
digitalWrite(dir1, HIGH);
digitalWrite(dir2, LOW);
}
if (myCom == "ff"){ //Spin forward
digitalWrite(dir1, LOW);
digitalWrite(dir2, HIGH);
}
if (myCom == "vol-"){
mSpeed=mSpeed-25;
if (mSpeed
i struggled for over an hour trying to use the modern libraries, ended up so close. then i saw your breakdown and it really helped me with " code=IrReceiver.decodedIRData.decodedRawData;" that is what i needed to continue. thank you!
having advanced just a fraction beyond your teachings, I had to come back and ask you why did you teach us to use "if" statements for each button rather than using "switch/case"? same question for why you used "int" to identify each lcd pin rather than using "LiquidCrystal lcd = LiquidCrystal (7, 8, 9, 10, 11, 12)"?
I'd further add, that while this series has a most amazing, well designed tutorial, I'm a little disappointed that it didn't include any lessons on creating functions "void myfunction(){ }" They seem to be a pretty crucial part of Arduino programming. But I do recognize and thank you for including them in your Robot programming series!
After figuring out how to adapt to the version 3 IR protocols, I am legend.
I am a beginner, big fan of your videos so far .Can you make a short video on how to use a segment display or about a beginner breadboard projects. Thank you.
I think if you wanna turn on the motor you have to insert digitalWrite high/low in the code. I always had a thng for dc motors since I opened one from a racing track car back in around 1980. I saw 3 parts inside and I was fascinated. To this day I scrap them and save them.
I AM LEGEND because it is now version 4 with all kinds of different code's. I've got no errors anymore....
Paul i got this to work on my own but the code has changed since you made this video so I'm going to paste the new code below. I also did it a little different. I just printed the number instead of the word. All you'd have to do is replace the number with the word, or whatever you wanted it to print. Here's the new code as of 7/10/2022:
NOTE: your "IR number" may be different so youll have to check that for each button.
#include
IRrecv IR(9);
int led = 8;
String myCom;
void setup() {
IR.enableIRIn();
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
if (IR.decode()) {
delay(1500);
IR.resume();
}
if (IR.decode()) {
if (IR.decodedIRData.decodedRawData == 0xE916FF00) {
myCom = "0";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xF30CFF00) {
myCom = "1";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xE718FF00) {
myCom = "2";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xA15EFF00) {
myCom = "3";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xF708FF00) {
myCom = "4";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xE31CFF00) {
myCom = "5";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xA55AFF00) {
myCom = "6";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xBD42FF00) {
myCom = "7";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xAD52FF00) {
myCom = "8";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xB54AFF00) {
myCom = "9";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xBA45FF00) {
myCom = "pwr";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xB946FF00) {
myCom = "vol+";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xB847FF00) {
myCom = "func/stop";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xBB44FF00) {
myCom = "back";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xBF40FF00) {
myCom = "play/pause";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xBC43FF00) {
myCom = "fwd";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xF807FF00) {
myCom = "down";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xEA15FF00) {
myCom = "vol-";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xF609FF00) {
myCom = "up";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xE619FF00) {
myCom = "eq";
Serial.println(myCom);
}
if (IR.decodedIRData.decodedRawData == 0xF20DFF00) {
myCom = "st/rept";
Serial.println(myCom);
}
delay(1500);
IR.resume();
}
}
Thank you so much for posting this- Upgraded to library 3.9.0 and even though I followed the documentation the best I could , the new code changes still had me stumped. Your code posting cleared it up for me... Great to see a movement growing up around us !!
@@justmc62
Found another command
int command = IrReceiver.decodedIRData.command;
that provides a numeric value...
then built 2 arrays
int arrCodes[] = {69,70,21,71,68,67,64,7,9,25,13,22,12,24,94,8,28,90,66,82,74};
String arrButtons[] = {"PowerButton","VOL_UP","VOL_DOWN","FUNCSTOP","FF_LEFT","R_FF_RIGHT","PLAY","DOWN","UP","EQ","STREP","0","1","2","3","4","5","6","7","8","9"};
then searched the first array looking for the index
for(idxCode=0; idxCode You pressed:PowerButton
11:30:19.268 -> You pressed:9
Your tutorials are always interesting, sir! I always enjoy the way you teach. As your tutorials are the BEST and most easy to understand on entire RUclips, I do have a request -- can you plz add a tutorial on 8X8 LED MATRIX in this series? For me, it's a very interesting component but I always struggle to make the circuit as well as the code right..! Thanx in advance sir..!
discovered something. My Kit was missing the IR Receiver but had the Transmitter (remove controller). No buggy, sent for one and received both a receiver and another Transmitter. The button layout on the other Transmitter was different. They both looked VERY generic, like the had come out of the same molds etc, except one fascia was white and one was black with different placements of keys, but the same 3x7 matrix for the buttons. (21 buttons, some buttons missing or in a different place).
When checking codes I discovered that the codes were all identical in both removes, with a twist.
For example the "Zero" button on one gave a different code to the "Zero" button on the other remote, but the button at the same grid reference had the same 3 byte code. ie top left button on each remote gave the same code even though they were labeled as different buttons. So it seems that (at lease on these cheep remotes) its the grid position that determines the code of the button and not the button face value.
Damn, that was wordy, but not sure I could cut it down much without loosing clarity. Hope its clear what I'm saying! Is it?
Oh yeah, I did the homework plus some.
you sir have made me get 3 of the bords now and have made kits for displaying text on lcd screens when they get a dcc input and allso a high low input from a push swicth great work onces again
You got me on that one Paul. All was going great until the motor started and the IR stopped. Spent hours checking my wiring and code until I guessed it might be motor 'noise', cured it with 100uF on the supply near to the IR. Relieved to have watched your next tutorial. Keep em coming!
@@phillovegrove4704 Dude. I can't believe I found this comment! This is my exact issue. Also figured it was RF garbage from the motor. What's odd is that the first time I got this working, that issue was not present. I then brought the whole thing to my lady's house, had to troubleshoot after the move, worked on it, brought it back home, and today this problem starts. So bizarre. When the motor is plugged into the breadboard *and spinning*, the LED indicator on the IR sensor goes nuts, and the sensor stops receiving. Unplug the motor, sensor works. I will report back once I've tried the capacitor trick!
@@phillovegrove4704 Yeah, any interpretation of "100uf on the supply near to the IR" results in the IR sensor, or the Arduino, or the whole thing not powering on. I am observing the polarity of the capacitor--negative side goes to lower potential side of the connection...
Would you mind elaborating? ...2 years later?
Figured it out. The capacitor goes ACROSS the supply and ground (connects to supply and ground) at the IR sensor. 10uF did NOT work. 100uF DID work, as @Phil Lovegrove said.
However, since this problem started, my remote readings still are not perfectly clean like they were before. 80% good. Occasional garbage. What's odd is the funny readings seem to only be present in the serial monitor--the fan responds as programed.
Hey Paul, love your videos, do you maybe plan do a video on Bluetooth Moduls for Arduino, something like HC-05 ?
I did almost the same thing but I printed everything outside the if statements
Could you do more projects that combine multiple components? Also my main questions is could you do a series on the mega 2560 most complete kit. There are a few pieces in there I have no idea about but I want to. Here’s the list Max7219/LED matrix, DS3221 RTC module, IR receiver module, GY 521 Module, Rc522 RFID module and the prototype expansion board. Other videos aren’t helpful. It’s usually a fast forwarded shot of someone putting the components together then 30 secs of scrolling through their code without explaining why or how to set it up
i fixed up some code that works with the new library version
Thanks Paul.
I am Legand, all I needed to do is remove the Serial.print statement printing HEX Serial.print();I also put in an LED to turn on with remote.
I am legend! Did this one on my own!
Hey Paul, Are you planning to give RF tutorials for arduino? If yes, can you do a lora e32 module? Been a great help to all of us. Thanks so much and Keep it up!
Hey, hope your doing good. Great Video! I would like to know how you are recording the overhead shot of your Arduino boards. Do you use a tripod? I would like to setup something similar, where I record all my notes and work being done for school. Thank You for these amazing videos!!
Sir Can you Add a tutorial about " How to use Wireless RF 433MHz Transmitter and receiver Module " with Aurduino
I learned arduino because of your tutorial . You Are A legend in teaching this.
love from india
Hello paul, I have been trying to build an RC car using DPDT relays, and something on the internet said that using a diode creates a polarity on a relay, and I have not been able to find anything else about it on the internet except for the one thing I saw. So basically I want to ask you if you know anything about this, because I dont want to create a circuit to find out its all messed up. My specific questions are is there actually a polarity if I use a diode and if so, how do I know which side the polarity is on. Thanks for taking the time to read this.
For some reason, only the first 9 if statements seem to work.. , I see that Hexadecimal numbers on E-Lego remote is just 6 characters long, where as my TV remote's is 8 characters long. that could be the problem, i am beginning to think..
Hello Paul, can we write a password with the remote to send a signal?
I took two readings for every button.
if (cmd.value==0xFFA25D || cmd.value==0xE318261B){
myCom="You Pressed Power";
Serial.println(myCom);
}
I am getting good accuracy like this.
Your controller seems more constant on which value it hits than mine. I can get at least 3 for each button, depending on where I aim it. But I have an ir camera on my 3d printer so that might cause noise.
"switch" "case" statement makes for cleaner, simpler code.
Paul, pls tell range of this remote...
Everything works fine on my download but one legend at the beginning: When I press any button on the IR transmitter, a legend shows to the plotter saying “The function decode (&results)) is deprecated and may not work as expected! Just use decode () without a parameter and IReciever.decoded IRData . .” I don’t know what it means.
Sir, please make tutorials on RF modules. (nrf24l01 and else.)
Please do make a tutorial on Bluetooth module for arduino.
Thanks very much
Paul, in an effort to untether, I decided to output this sketch to my lcd display instead of using the serial monitor. So I included the lcd library, created the lcd object, connected the lcd screen to the nano on my big breadboard and re-assigned the IR pin to pin 6. However, I can’t get anything to print to the lcd! I kept the serial monitor going ( for debugging purposes) so I know the code from the remote is still working. Can I lcd.print(myCom) or is there a problem with lcd printing a string? Any guidance? Can everything we print to the serial monitor also be printed to the lcd display?
Paul, I found the problem! I reloaded the Hello World sketch to check my connections and I got a blank screen. So I went to your Top Tech Boy website for an lcd lesson, checked the schematic, and found that I had not hooked up the VSS or the VDD connections- everything else was right. Doah! Now it’s Giddyup! I’ve made comments in my sketch to always hook up those connectors which I hadn’t done before and consequently missed it going forward. Thanks Brother! God Bless You!
Thanks for the Tutorial,,,
I am wondering which kit to buy to follow your tutorials, I have narrowed it down to two choices, the one you recommended, and a similar one I found that looks like it has better value but for a cheaper price.
Here is the one I am inquiring about. - Smraza Ultimate Starter Kit
My question is, would I still be able to follow your tutorials accurately with the second link or should I get the exact kit you have gotten (with your affiliate link of course)?
Note: The reason I'm considering the second link is because it seems like it has a lot more cool sensors and motors.
I will order a kit and watch your tutorial as soon as you respond and can't wait - thanks for your help.
I am using Smraza super starter kit. There are minor differences in the kit he is using and the one I am using. Mine did not come with a L293D motor control chip or a DC motor. I picked those up off Amazon for cheap. The other component that is different is the remote. Everything else is the same.
Nice tutorial so far, but Sir, please can you make a video on how to load a bootloader to an ATMEGA 238 chip using an arduino UNO board?
I AM.... not... legend... Officially giving up and moving on to watch you do it, Paul.
Had this nearly completely working (only lacking speed control) 2 days ago. Then moved the setup to my lady's house. Something went wrong in transport. Troubleshooted. Figured that out--don't even remember what the prob was at this point. Brought it all back to my place. Something went wrong again in transport. Spent hours troubleshooting. When my volt meter graced the supply pin on the control chip + ground, the motor mystically started. (Lol.) More troubleshooting.
Decided to switch to the new big breadboard you recommended (this must contain less resistive metal than the Elegoo breadboard because the motor started singing when I powered it up--I've never heard it go so fast). Now I've got a strange RF noise issue (my guess, but seems to be right) blasting from the motor, seemingly jamming the IR sensor. I can power the motor on, but once it's running, the IR sensor's indicator LED goes crazy and the sensor won't...sense.
One lonely comment mentions what sounds like my new issue, says to use a 100uF capacitor, but vaguely describes where. A stackexchange.com post gets more specific. Finally cured *half* of the "RF noise" problem by putting a 100uF capacitor *across* the supply and ground to the IR sensor-the sensor's LED is no longer going buckwild, but still can't take input while the motor is running. Same stackexchange post said to try the Arduino's 3.3V supply for the sensor as well, as the motor is spewing AC noise along the 5V rail on my breadboard-taken with a grain of salt, until...
After testing, confirmed that the issue is 90% gone with a combo of powering the sensor from the Arduino's 3.3V, and using the capacitor across *that* and ground, right smack at the IR sensor. I say 90% because the range of the remote seems to be effected (like the sensor is still "trying to overcome the noise floor"), and I get occasional strange readings in the serial monitor, while the motor seems to respond to commands as expected... odd. Maybe I have to press a button twice every once in a while. Maybe the odd serial mon readings and the need to press a button twice *are* related, and I'm too fried to notice.
I'm really feeling like something is wrong, here. Mostly because this all worked fine 2 days ago, once I "figured out" the library version issue and rewired the whole thing. Didn't need the capacitor or the separate power supplies for the sensor and motor.
If anyone could shed some light on this, I would be extremely appreciative. Maybe the next video will address some of my issues.
A big issue on any project with a motor is noise. Try twisting the leads on the motor to form a little rope like structure, or put a capacitor between + and ground on the motor.
@@paulmcwhorter Bah! Can't believe I didn't think of the twisting. We use lots of twisted pairs in the audio world, in balanced microphone signals and ethernet! Thank you for taking the time to give me some pointers! Twisted those suckers tightly!
Also tried the capacitor both across the black and red motor wires and across the + and ground of the control chip. Tried 100uF and 10uF (one of those has to be what you meant, right?). The only place the capacitor seems to help, in my setup, is across + and ground of the IR sensor, as close as physically possible. The very best place I found, in terms of IR sensor performance, is just behind the IR pcb in the closest hole I can reach.
I also realized that I've probably been testing with the motor much closer to the whole circuit than I was before, hence the new interference. When I move the motor (and its wires) physically away from my breadboard, it makes a big difference. I also suspect that the big metal plate this bigger breadboard is on has something to do with it. If I tape the motor to the plate, even with the separate voltage regulation and capacitor right at the sensor, I cannot receive commands, and see noise on the serial monitor once the motor's running. I can put the motor even closer to the circuit and get everything working, as long as the motor isn't sitting on top of the metal plate. Still some noise in the readout, but I can easily ID valid commands, and so can the IR sensor.
So after lots of testing and troubleshooting trying to make speed control work (I un-gave up for a while), I've figured SOMETHING out...
For testing, I made a new variable to store serial monitor input, and modded each if statement to depend on that variable. The idea was to use serial monitor to take motor control input instead of the IR sensor + remote. I commented out these lines: 1) IrReceiver.begin in void setup, 2) the "waiting" while loop (changed it out to wait for serial input) 3) the block of code starting with "cmd=" and ending with "IrReceiver.resume()".
Everything works flawlessly. WTFork?
Then I uncommented specifically the IrReceiver.begin(IRpin) ONLY, and now any PWM value other than 255 for mspeed results in the motor turning off, and the system taking no input from serial monitor. When I was using the IR sensor and remote for control, I had the same issue--if I dropped the speed by one increment (-20 to 235, in my code) the motor would shut down and stop taking IR input.
(To be clear, my mulitple comments on this page are discussing different problems--a few with code (as this one is) and one's about RF interference from the DC motor. If you're confused by the last statement in the last paragraph, based on what you've previously read...)
SO... Everything works as expected taking input from serial monitor as control commands, but the moment I initialize the IR receiver, the speed control breaks and I can take NO kind of input--even when only using the serial monitor for input! Wut!
Anyway, I've re-given up, and am finally moving to the next video after a short break. This has been 4 days of my life and I feel like a failure!
I have the official Arduino kit and my remote is different got their in the end putting all the buttons in.
It would be easier, cleaner, and less error-prone to eschew the pile of _if_ statements in favor of an array and enums.
What lesson was that in?
Does anyone know if its possible to make the IR remote work even if the arduino isn't connected to your computer? I've been trying but it doesn't go...
It's definitely possible. Need to make sure everything has 5V and ground!
Made some typos but those were easy to find. Harder was finding why myCom was causing a failure to compile..... undefined in this scope error. Many scans through the lesson in still mode did not reveal problem, thinking it was not declared. Most of what I tried did not work. Finally gave up and went to toptechboy site and downloaded the code for the lesson, String myCode made all the difference! Could not find that in the video I was watching but had looked for it.
Lot of copy paste and all keys now report without the hex code printing. Comment one line to stop that.....quite impressive
I was able to get the homework done. I needed to watch a couple of the past lessons to review the DC motor control. I am having an issue with the Remote Controller, I am not able to get consistent codes from it. One in every 3 to 5 button presses will be the correct code for the button, the rest are nonsense codes. I guess this could be a problem with the IR sensor module. I have put a new battery in the controller but that didn't help. Has anyone else seen this issue? Not sure if I should get a new controller or a new IR sensor? Or maybe both? Thanks!
Hello, I had the same problem I used a delay of (750) right before resume(); Resume is the last line of code. Also mine is very sensitive in that if I don't point it correctly it will not receive correctly.
Homework:
#include
int infrared=3;
int wait=500;
String myCom;
int speedPin=5;
int dir1=2;
int dir2=4;
int minSpeed=110;
int maxSpeed=255;
int Speed;
int deltaSpeed=20;
int ON;
int spin;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
IrReceiver.begin(infrared);
pinMode(speedPin,OUTPUT);
pinMode(dir1,OUTPUT);
pinMode(dir2,OUTPUT);
Speed=0;
}
void loop() {
// put your main code here, to run repeatedly:
while (IrReceiver.decode()==0){
}
//Serial.println(IrReceiver.decodedIRData.command,HEX);
delay(wait);
if (IrReceiver.decodedIRData.command==0x45){
if (Speed==0){
myCom="ON";
Serial.println(myCom);
Speed=(minSpeed+maxSpeed)/2;
ON=1;
spin=1;
digitalWrite(dir1,HIGH);
digitalWrite(dir2,LOW);
analogWrite(speedPin,Speed);
Serial.println(Speed);
}
else {
myCom="OFF";
Serial.println(myCom);
Speed=0;
ON=0;
digitalWrite(dir1,LOW);
digitalWrite(dir2,LOW);
analogWrite(speedPin,Speed);
Serial.println(Speed);
}
}
if (IrReceiver.decodedIRData.command==0x46){
if (ON==1){
myCom="Speed Up";
Serial.println(myCom);
Speed=Speed+deltaSpeed;
if (Speed>maxSpeed){
Speed=maxSpeed;
}
analogWrite(speedPin,Speed);
Serial.println(Speed);
}
}
if (IrReceiver.decodedIRData.command==0x15){
if (ON==1){
myCom="Speed Down";
Serial.println(myCom);
Speed=Speed-deltaSpeed;
if (Speed
I am Legend, & late for work! gotta run.
I got the homework done. Is it considered cheating if I'm heavily using previous programs?
I have been stumped with this one. My remote will return various codes for the same button pressed. For example, If I press the 0 key 20 times I get 5 or 6 different codes, to make matters worse some of the codes are shared with other keys. Like both the 1 and 2 keys have the code '255' as one of their options.
Any ideas why this might be? I have copied your code line for line!
Hello, I had the same problem I used a delay of (750) right before resume(); Resume is the last line of code.
Success, I am Legend!!!
why are lessons 66 and onward private videos are they meant ?
He posts new tutorial vids every week on Tuesdays, so you’ll get it pretty soon
Amazon was to send me some DC motor chips and a can opener. Only the can opener showed up. Bummer, I will have some soup and wait.
I am Legend. Thanks
BooooooooooM ✨✨✨
Still getting FFFFFFFF read outs on my monitor display. Can some one help me fix this?
Present.
I have never seen a RUclipsr who has less dislike to like ratio than him...👌
I am legend!
I should get an award (or punishment) for most wordy comments.
GOLD STAR. There you got your award for being active member of the channel community. Well done.
Thank you so much for posting this- Upgraded to library 3.9.0 and even though I followed the documentation the best I could , the new code changes still had me stumped. Your code posting cleared it up for me... Great to see a movement growing up around us !!
I am legend
i AM LEGEND
LEGEND!
i am legend
LEGEND!
Where is your coffee???
Hi Paul I was the first one on Tuesday to comment but now it has disappeared do you know why?
I moderate comments so they dont show up until I approve them. This keeps spam and nonsense down. I did not delete your comment, it should be there
I understand which is good
just to let you know i Have my Smart Robot 3.0 ready and waiting and love your teaching. I have learnt a lot from you.
Thank you.
hi
do more arduino tutorialsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
First comment ⚡ Amazing
I im Legend
This would have been the time to introduce the switch statement instead of going through all these if statements. This was a boring lesson...
I use a switched case instead of if statements and it works well too. Here is my code:
#include //Make sure to install the library
int IRpin=3;
IRrecv IR(IRpin);
decode_results cmd;
int msg;
void setup()
{
Serial.begin(9600);
IR.enableIRIn();
}
void loop() {
while (IR.decode(&cmd)==0){}
msg = cmd.value;
switch (msg) {
case 26775:
Serial.println(0);
break;
case 12495:
Serial.println(1);
break;
case 6375:
Serial.println(2);
break;
case 31365:
Serial.println(3);
break;
case 4335:
Serial.println(4);
break;
case 14535:
Serial.println(5);
break;
case 23205:
Serial.println(6);
break;
case 17085:
Serial.println(7);
break;
case 19125:
Serial.println(8);
break;
case 21165:
Serial.println(9);
break;
case -23971:
Serial.println("PWR");
break;
case 25245:
Serial.println("v+");
break;
case -22441:
Serial.println("v-");
break;
case -28561:
Serial.println("up");
break;
case -8161:
Serial.println("down");
break;
case 8925:
Serial.println("");
break;
case 765:
Serial.println(">|");
break;
}
delay(500);
IR.resume();
}
I just didn't include the EQ, ST/REPT and FUNC/STOP because I didn't know what they are for
It is by no way smart to use string for anything in the code (like "pwr"...)
Just use : #define cde_pwr 0xFFA25D
Then you can compare the command received with a binary number.
Thanks for the tip, but ya gotta be a little nicer. I shouldn't have to explain why...