1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Lab view programming to drive motor

  1. Dec 8, 2011 #1

    I will get straight on to the problem. I want my RC servo motor to run when there is no light from 0-180 degrees and when there is light the motor should stop. I have made a program which reads the voltage from sensor and a program to generate PWM signal witha a timer sepraretly as a basic approach for my task. I would appreciate if any one could give me a good explanation on how to make it (please note im still a beginner)

    Thanks !

    Attached Files:

    Last edited: Dec 8, 2011
  2. jcsd
  3. Dec 9, 2011 #2
    I guess I'm a bit confused on what you want help with. You have written code to read the voltage from the sensor and you have written code to make the servo run, correct? You just want to know how to write a conditional statement to make the servo only run when the voltage is zero (i.e. when there is no light)?

    Have you used 'case structures' before? It sounds like that might be what you want. You would feed in the voltage from the sensor. The structure would then let you say "if the V=0, move the motor" and "if V=!0, stop the motor". Your signal will likely not be precisely zero so you may want to do something like "in range and coerce" before hand. Set the limits from 0 to what ever the max voltage is when you still consider the light to be off. Then feed the boolean from that to the case structure.

    Attached Files:

  4. Dec 10, 2011 #3

    Yes you got it right. Now here where I get stuck. What do you mean by programming code for motor. I have done something what I believe is the programming code for motor. I am a beginner so please help me. Thanks !

    Attached Files:

  5. Dec 12, 2011 #4
    Have you been successful in making the servo motor move at all? How is it connected to the computer?

    I don't recognize the LabVIEW functions in your code. The only way I've used servo motors has been with an NI Motion Control card.
  6. Dec 12, 2011 #5

    I used it using DAQ card-USB-6211. The motor worked fine.
  7. Dec 12, 2011 #6
    But thats not all I want. If I have two different sensors as input separated by a divider, I want the motor to move in the direction of light. For example if right photo sensor had light and left didnt, I want sensor to move in the direction towards left and vice versa.

    (Also a small problem is that it move from 0-150 degrees. after 150 degrees it stops , it doesnt move beyond 150 degrees. It just hangs in there. I am not sure if its exact 150, when I say 150 degrees, all i mean is to complete 180 degrees it is few steps away from it where it hangs)
  8. Dec 13, 2011 #7
    Ok, I'm still lost on what exactly the problem is. It sounds like you can move the motor with the program but when you have all the stuff in there with the light sensor, nothing is happening. This is how I would propose to troubleshoot the whole thing. Go through these steps and tell me where you get stuck.

    1. Write code that moves the motor 180 degrees and execute it. Make sure the motor turns. Make sure you can run the code a second time and the motor turns again. Also make sure you can make the motor turn in the other direction.

    2. Write code to read the light sensor and execute it (this would be a separate VI from the above). Make it display the voltage. See that the voltage goes low when the light is off and high when the light is on. Record the voltage when the light is off and when the light is on.

    3. Write a very simple conditional statement that just takes a front panel control (a true/false control). If you push "go" then it will make the motor turn. Make sure all of this works.

    4. Instead of having the "go" button on the front panel, replace that code with the light sensor code. Just get one sensor working at first. See that the motor turns.

    Let me know what number step you get stuck on and I can go into more detail. But I'm worried about the servo only moving 150 degrees. Are you using a servo driver - has it been tuned properly? There are frequently programmable stops too. Make sure none of those are activated.
  9. Dec 13, 2011 #8

    Thanks a lot for taking your time for me. No you got it wrong, i don't have any trouble shooting with it. The program works like charm !

    I have done point 1, 2 and 3 exactly you have described. I am not using any motor driver. I am using DAQ card(USB-6211). I have attached a picture to show that. I don't think it is a big problem if servo motor is not moving beyond 150 Degrees. I will sort it out. I have achieved what I had desired for by your help. Thanks

    My second step is to have two input sensors and try to manipulate the rc servo motor. For example Sensor 1 has light and Sensor 2 does not, I want the motor to move in the direction of Sensor 2. Could you help me in how to achieve this please. Thanks :smile:

    Attached Files:

  10. Dec 20, 2011 #9

    I have made a program which the motor will track the light actively. I have made two different programs. 1st program uses DAQ card to drive motor. 2nd Program drives the motor using a motor driver which has a USB attached to computer and it identifies the COM port and runs it.

    My next approach is to make Servo motor actively track the light using 2 input sensors. I want the motor to actively track by moving clockwise and anti clockwise direction to track the light. Suppose the left sensor receives low voltage compared to right sensor I want the motor to move towards the direction of left sensor and vice versa. I have attached the file of both program which I have done. Please help !!!

    Attached Files:

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook