I already tried controlling the DC motor using a pot and worked out fine. I was thinking if I used a photoresistor to control the DC motor instead of a pot, will it still work? I'm using Arduino and trying to build a very basic robot. I have no idea right now if I will break anything on the Arduino and thus just want to be sure. I don't have any shields or H-bridges. Just building something very basic.
Short answer, yes.You’ll
Short answer, yes.
You’ll need a fixed resistor to use in combination with the photoresistor to make a voltage divider that feeds into the Arduino analog input. Take a look at this little tutorial to get you moving in the right direction.
Yes on the LDR…
NO on the motor + Arduino!
Do not plug any kind of motor directly into your Arduino.
In terms of the LDR, The TeleFox has spoken.
Are you varying motor
Are you varying motor current using PWM (pulse-width modulation)? This requires you to process the value of your potentiometer or photoresistor using an ADC (analog to digital converter) input of your Arduino. I think it will be helpful if you provide a sketch or description of your circuit you have working.
Cheers
Schematics
I’ve already implemented the DC motor and it works fine with the pot. Now instead of a pot I was thinking of using the Photoresistor for control.
Here’s the schematic of DC motor:
http://cl.ly/3y2P2H022D2Y220d0C2Y
Here’s another schematic of photoresistor:
http://cl.ly/0P3i3d2M0v0w143k2w1m
I want to somehow get rid of the pot and use the photoresistor to read the values and control the DC motor.
Be careful
The outputs on the Arduino are not made for powering motors and other high current stuff directly. You’ll fry your Arduino if you don’t put a controller or something in between, a simple transistor migh actually do.
Read the photoresistor as an analouge input and then use that input for PWM on the pin which you’ve connected to the transistor which you’ve connected to the motor.
The schematics were very
The schematics were very helpful. The voltage divider circuit with the photoresistor to the analog input is a fine approach. To determine the value of the resistance (shown as three series resistors in the circuit) that provides the greatest voltage swing multiply the minimum and maximum photoresistor values, and take the square root of that product. For example, if your maximum/minimum photoresistor values are 1Mohm and 1kohm, the calculated voltage divider resistor would be about 32kohms.
I suggest wiring the motors directly to batteries. You can look at the absolute maximum ratings for your regulator output current (google for a datasheet) and compare it with your motor stall current.
Pulse-width modulating the base of the power transistor as shown in the schematic is also a fine approach and should work!
I also suggest you put a 0.1uF non-polarized capacitor between the motor leads to attenuate noise caused by the motor brushes.