How to use a LM393 IR Speed sensor with an Arduino - Tutorial
Vložit
- čas přidán 25. 06. 2024
- Let's see how to connect and use a LM393 Speed Sensor to calculate the speed of a DC motor.
Check out our tutorials page at : brainy-bits.com/tutorials/ to get the schematic and more information on this tutorial. - Věda a technologie
+Neil Kolban Thanks for watching and your comment! And I will work on my pronunciation of "potentiometer" in my next videos! :)
your tutorials are always detailed, informative. thank you for making me better.
Thanks for watching Mike!
+Max Tubbs Also make sure that you closed and restarted the Arduino IDE software after you extracted the files.
Your video’s and web site is very nicely done, you have me hooked.
Ron Henderson Thanks for watching and your comment! Always great to hear that the videos are interesting, and it encourage us to make new ones!
Amazing tutorial, very informative.
+Max Tubbs Hi, make sure that the folder that has the TimerOne files in your Arduino Libraries folder is named: TimerOne and not TimerOne-r11. Not sure if that's the problem but it's worth a try. Let me know if that doesn't fix it, then we'll try something else :)
this is a nice high level explanation.
I'd be careful in the way you handle the math --> as your rotation variable is an integer and integer math are trunking results - what you get when you divide by 20 is highly approximative( but it makes nice for display). In practice with your code, if counter is 20 or 39 you'll show 1 Revolution per second which is correct for 20 but almost way off when counter is 39.
Also, while by defaults lower level interrupts do not stop the execution of an interrupt callback, it might be good practice to call noInterrupts(); and interrupts(); at the beginning and end of your timerIsr function.
Also because it's not a great idea to have long running interrupts (where you do all the printing - that skews timing functions and your main code might need accurate millis() for example) best would be to limit what you do in the timerIsr function. For example you could have a global volatile variable lastMeasuredRPM which you would calculate in timers and do the printing in your main loop function (checking millis() - startmillis) and print every second for example)
Hello, I'm making a line following robot and I want to know I can connect 04 motors DC (3-6v) in brigde l298n? And how to control the rotation and speed of the motors(02 motors by connecting in series) ?
Thank you.
Great tutorial, really useful.
+Edgaras Art Thanks for the comment and for watching of course :)
very nice, thank you very much
I was working on a project with your code as the base where the rpm is displayed on an LCD screen, however, these weird characters are also getting displayed along with motor speed .
I have basically replicated your project here but using a hobby airplane electric motor. The difference for me is I'm dealing with much faster RPMs. Using your code above with the interrupts, I can only sense a maximum of 240 "counts" per second. Anything faster begins to drastically corrupt the reading. Is that a limitation of the interrupt itself or of this sensor (LM393)? I have it plugged into the interrupt 21 (2) pin of my Arduino Mega. What would you suggest if I wanted to increase the counts per second? Thanks in advance.
While this code is simple so it does not really matter much, to be accurate and safe, your counter variable should be declared as volatile ( volatile keyword should be used in the definition of a variable when there's a chance that the variable's value could change outside the normal flow of execution of the program - which is the case here as you use it in an interrupt).
Well explained!
Thanks for watching Ryan!
is it possible to use this system with a 220v pwm speed controller? I want to make a speed controller for a 220v router motor on a cnc machine for mach3, im just worried about the higher voltage frying the rest of the circuit. maybe there is buffer circuit or something i need to put between the dc and ac parts?
Would it work if your encoder plate has say 4 holes? You would just divide the counter by 4?
Has it been uploaded? Can't find this tutorial on your site.
Here it is: www.brainy-bits.com/speed-sensor-with-arduino/ Thanks for watching!
could i use that lm393 to make my own wind sensor? doesnt have to be very precise, just want to pull down a solar tracking panel if the wind is too strong.
Hello! Can i print the disc with a 3D printer? Do i have to have the exact number of slots you had on your disk?
Hello, can we set the timer to a higher value like 15 mints? and how? thank you.
hi...what is the maximum allowable cable distance between sensor and the UNO??
hi I m basically in making of project by using adruino to test the rpm and output voltage from the 24v dc generator of wind turbine can you help me with the coding?
pls kindly share the link to the forum, I would like to join. Thanks for the tutorial
sketch_nov05a.ino: In function 'void timerIsr()':
sketch_nov05a:14: error: 'Timer1' was not declared in this scope
sketch_nov05a.ino: In function 'void setup()':
sketch_nov05a:30: error: 'Timer1' was not declared in this scope
I get the above error message.
I have extracted the TimerOne-r11.zip file into libraries file where all my other libraries work fine for other sketches.
So WHY won't it recognise this, or am I mistaken?
Many thanks
Hello there, great tutorial!. It should work with any ir sensor right?. Thanks
+kevteg05 The module used is basically an IR emitter and IR receptor. If you have an IR sensor then all you need is an IR Led to make sort of like the same thing. Of course it is easier to use the module, but it's possible :) Thanks for watching!
How can I use that sensor to set speed on 230 volts motor with brushes? Can arduino rule the triac driver? Please answer )
Sorry for my english )
Nice video. Is encoder disk included when you buy LM393? Where could I find any?
+Dunc Poly The ones we sell in our store at: brainy-bits.com/shop/modules/speed-sensor-module/ come with the encoder disc. Unfortunately we don't sell them separately. Thanks for watching!
inside interrupt mode rising - lose a slight mm from one hole to another..maybe you must change the mode rising to change and replace 20 to 40
perfect for beginners! exactly what i was looking for. thanks! which language is the code in .. C ?
Arduino uses a C++ type of language structure. They are some restrictions of course because of the little available RAM on the Arduino hardware, but it's very similar. Thanks for your comment and watching btw :)
Do exactly the same, and it works well, thank you very much, but only works correctly up to 10 Volts, after that, the speed decreases. Please help.
Awesome!
Cool! Thanks for watching!
Yay, I'm the first to like this video.
hello, can i get the program? just need it for the thesis thank you!
can u tell me how i can show rps in lcd.
i used stepper motor with tb6600 driver and i also use your encoder coding. but when i combine your coding with my motor stepper coding, the serial monitor shows value 3000 but i didn't let anyting through sensor... how come it could happend:( please help:(
i cant found the library. please give me the link :(
Thanks
which sensor is used to measure the speed of the vehicle
Very useful video 👍🏻, automatically susbcribing the channel.
how to change output pin from speed sensor (pin 2) to another pin ?. Currently im using arduino mega.
can you show me exmple sketch to change the digital pin.?
how..can you show me..because i cannot define pin at my coding
I've been using pin 21 (interrupt 2) on my Mega and it works.
can u tall me how can use to count the pules to rotate the motor to a particular position. like a stepper motor. plz hlp
+md nouman You can count the pulses and stop the motor at a specific one, but it will never be precise since there is no encoder on these motor to keep track of their position. For accuracy you want to use a stepper motor.
You can control a DC motor as if it was a stepper motor, except you also get feedback with these...
guys, how do i wanna measure the speed underwater? it is for my final project, can u help me, what sensor should i use, help me plis....
what is the maximum rpm that can be measured using this module ?
i would love to know that too.
like how many holes per second are the limit for the arduino and sensor?
It depends on the processing speed of the Arduino
I have been using this same setup on a Mega and can achieve a max of 240 "counts" per second (see code in video) before the reading starts to degrade. With a 20 hole disk, that means a max RPM sensing of 720. You can increase the rpm reading capability by reducing the number of holes, at the cost of sample time.
why 680 value? i dont understand why maping this value
Shouldn't the Ground of the motor driver be connected to the arduino's Ground in order to have signals travel to the motor driver?
+Flo wey You are correct. You should always have ground referenced to the Microcontroller. In this instance it still worked fine, but as good mesure you should do it! Thanks for the observation and for watching!
+Brainy-Bits thanks for clearing that up, had my mind boggled. :P
***** You are welcome :)
i had a problem with this sensors. how the speed sensors will get the rpm data ? all i know.. we put the rotation thing between the two little cube things that allready in the sensor modules. im a correct ? because i didnt see how you put the rotation things in this video.
sorry for my bad english btw :)
+darren alex You are right, you put the sensor wheel that's on the gearbox motor between the two cubes thats on the speed sensor. There are holes in the sensor wheel that will let the infrared led on the speed sensor shine through and that's how it detects rotation. Hope that helps. Thanks for watching!
+Brainy-Bits thanks! its very difficult to find this kind of sensors in my place... so i dont have any idea to use it :)
50/5000
can it be used on a motorcycle vehicle?
Will it work with stepper motor ? and not connected to PC ?
+Wojciech PVB To use a stepper motor you would need a motor controller like the EasyDriver board. I did some videos using the EasyDriver, you can check this one here: czcams.com/video/dQuTgngoFPQ/video.html Hope that helps! Thanks for watching!
can u send u circuit.....
can you give me coods for ardueno
and map
danke sehr hilfreich!
a new precisely and fine resolution speedsensor 0-70m/s ; Company AFCCe.U.
Very useful, Thank you. Liked. :o)
Always nice to hear that the videos are helping others. Thanks for watching and the Like :)