Hello,
I have been searching for sample codes for Arduino to output a graph (a line graph) on a serial monitor that shows the speed of dc motor through a
graph via Arduino Uno,
is it possible? and if so, is there any sample codes for that? because I have been searching for it everywhere online…
I would appreciate help,
thanks in advance.
Collect the RPM sample, and send it out the serial port. Connect the serial port (either the USB or an external level converter if you want) to a program that will read the data in and save it to a CSV file. Open the CSV file in Excel (or other spreadsheet) and plot at will. If you want a dynamic graph, you could write a GUI in something like Python or send the data to Pachube.com and let them plot it for you.
is there a sample code where I can get the arduino uno to spit out the speed of the dc motor to the serial monitor screen?
How are you getting the speed? What type of sensor?
well I wanted the speed or rather revolution per minute (RPM) of a dc motor … if there is way to code that so that I can get the RPM values on the serial monitor.
A true sign of insanity is asking the same question and expecting a different answer…
An Arduino is not a motor controller nor is it a motor sensor. It is a simple easy to use microcontroller (a non general purpose computer). To control a DC motor, you will have to turn on it power in some way. Perhaps with a relay, or a MOSFET, an H-Bridge, or a more sophisticated motor controller. Once you have solved that problem, you still do not have any idea how fast your motor is going (with some exceptions). For that you will need a sensor of some sort. It could be an optical system that looks at a stripe of the shaft, or a magnetic system that senses the teeth in a metal gear or a magnet spinning, or it could be by deduction looking at the way power is being consumed. But you will need a sensor.
Trying to provide you with code without knowing what type of motor, what type of controller, and what type of RPM sensor system is a waste of everyone’s time. We have narrowed it down to a DC motor. Are we talking a tiny pager motor or a huge Prius drive motor?
The dc motor that I"m using looks something like this http://www.3rivers.net/~cmac/motors/ast-3142-01.jpg
I’m using 10 K ohms potentiometer to control the speed of the dc motor. And I’m also using arduino uno.
Could I be able to use tachometer or speed sensor to place it near the dc motor if I can’t get the speed (RPM) of the dc motor just by arduino uno code?
I mean I guess that’s the only way I can think of it right now.
I’m doing this as a project. My professor has been bugging me as to why I’m not getting the speed of the dc motor via code.
Sorry if my question sounded redundant but I appreciate your help and your replies.
There is no way to get the speed of the motor with just “code”. You need a sensor of sorts. The best solution is very much dependent on the application. An encoder might be perfect in some circumstances and horrible in others. If you want advise, you are going to have to supply more details. Pictures, words, datasheets, … would all help.
But here is one possibility… Add a white paper disc to the motor shaft with a thick black line drawn on it. Use a reflective IR sensor to see the line as it spins by. Connect the output on the sensor to a interrupt pin on the Arduino. Inside the ISR, add one to a count. Program the timer interrupt to get the count every second or so and compute the RPM. The mail loop can then send the RPM out the serial port. A possible sensor might be this one: http://www.sparkfun.com/products/9454 or this: http://www.sparkfun.com/products/9208
If adding anything to your system is not possible, than a “Back EMF” solution might be the way to go. But this is a much more difficult problem and one that requires both analog and digital electronics knowledge.
fll-freak:
There is no way to get the speed of the motor with just “code”. You need a sensor of sorts. The best solution is very much dependent on the application. An encoder might be perfect in some circumstances and horrible in others. If you want advise, you are going to have to supply more details. Pictures, words, datasheets, … would all help.
But here is one possibility… Add a white paper disc to the motor shaft with a thick black line drawn on it. Use a reflective IR sensor to see the line as it spins by. Connect the output on the sensor to a interrupt pin on the Arduino. Inside the ISR, add one to a count. Program the timer interrupt to get the count every second or so and compute the RPM. The mail loop can then send the RPM out the serial port. A possible sensor might be this one: http://www.sparkfun.com/products/9454 or this: http://www.sparkfun.com/products/9208
If adding anything to your system is not possible, than a “Back EMF” solution might be the way to go. But this is a much more difficult problem and one that requires both analog and digital electronics knowledge.
Does it matter if I use analog version of this instead? http://www.sparkfun.com/products/9453
Or does it have to be digital? http://www.sparkfun.com/products/9454
What do you mean by “inside the ISR, add one to a count” ? u mean on the code that I write?
Because I’m told by a professor that if I put my finger on the spinning DC motor, and the value of rpm changes then I should have the microcontroller (Arduino Uno) to apply PID to readjust the rpm back to its normal regular speed…
For example…
Like let’s say the rpm of a motor goes to 12000 rpm and then I add my finger to the dc motor and it reads 8000 rpm and so my professor told me to have PID applied so that even if I put my finger into the dc motor, the PID will take care and have the dc motor go back to original 12000 rpm.
how would I make this to be? I been searching everywhere and I can’t get the PID from the arduino Uno.
Having your sensor be analog would not be a good idea. What you will want is the output of the sensor to go directly to the interrupt pin of the processor. Inside the Interrupt Service Routine (the code that gets called each time the interrupt occurs) you can increment a counter by one. How many counts go up in a time unit (second, millisecond, …) gives you an indication of speed.
You could use an analog sensor if you had a very fast processor that could perform ADC conversions at the rate the wheel is turning. You can also condition the analog output with a voltage comparator chip to turn the digital into analog. Much simpler just to go analog if you can get the parts.
PID is the name of a software algorithm that allows a micro to adjust some parameter (in your case the PWM of the motor) to make drive something else to a desired value (in your case motor RPM to some value). There are thousands of websites on various types of PID loops and how to write and adjust them. No reason going into that here.
Despite the obvious language barrier, I get the sense that the OP doesn’t grasp the basics of the control loop he’s trying to create. What course is this for ? What background in control theory is deemed to be a prerequisite ? Does the acronym PID have any meaning to you (the OP) ?