Hi there!
This is a cool example of how to drive DC motors with Arduino, using a MOS transistor. Let´s remember almst any DC motor has a current superior than the Arduino can take (this can be applied to voltage also) so we need a MOS transistor controlled by our digital output to make the adjustments and work with this higher loads and voltages.
See it in action on this video (a little bit long, but has all the stages):
The part list:
- 1 x DC motor (can be a toy car)
- 1 x MOS IRF520
- 1 x 10k potenciometer
- 1 x photoresistor (10k)
- 1 x 10k resistor
- 1 diode
- 1 x arduino
- 1 x 9v battery (apart from the arduino power supply)
Part 1: The basic circuit with DC motor.
The assembly is simple.
We are controlling the DC motor with the MOS transistor and the 10k Pot. We are regulating the speed of the motor with the potenciometer as shown on the diagram.
The MOS is controlled by and digital output to send the information of how much current we are giving to the DC Motor, and the MOS receives the power from the 9v battery and gives just what is told from the arduino to the DC Motor.
Check this example, and try it out!.
Part 2: Adding the Photoresistor
Now, we are adding a photoresistor to the analog 3 input (check our previous post in this link for info on how to use the photosensor) to the system and an RC car to ir (let´s have more fun).
Part 3: Adding the RC car
We had to drive directly the motor of the RC car, in order to first not modify the toy and second for simplicity of the example. We attached 2 wires directly to the motor, and 2 wires directly to the battery compartment.
Now all we have to do is to exchange the 9v battery with the 2 wires attached to the battery holder of the RC car and exchange the DC motor we installed on the breadboard with the 2 wires we installed on the RC car. Please check the polarity of the car, otherwise i´ll go forward (unless you want it to). You should use this 9v battery to power up your arduino board.
Then just secure the breadboard, the 9v battery and the arduino to the RC car, and have fun!
The Source Code:
/* DC motor driven by MOS transistor and photosensor * -------------- * * @author: Javier Lander * @hardware: Javier Lander * www.arduinoarts.com * twitter: @arduinoarts */ const int potPin = 0; // Analog in 0 connected to the potentiometer const int transistorPin = 9; // connected to the base of the transistor int potValue = 0; // value returned from the potentiometer int sens = 300; // the light amount where the DC motor starts. int photocellPin = 3; // the cell and 10K pulldown are connected to a3 int photocellReading; // the analog reading from the sensor divider void setup() { //Serial.begin(9600); if you want, you can read the photosensor data to see the breakpoint // set the transistor pin as output: pinMode(transistorPin, OUTPUT); } void loop() { photocellReading = analogRead(photocellPin); // Serial.print("BT = "); //Serial.println(photocellReading); // the raw analog reading if (photocellReading > sens){ // read the potentiometer, convert it to 0 - 255: potValue = analogRead(potPin) / 4; // use that to control the transistor: analogWrite(9, potValue); } else{ potValue = 0; // use that to control the transistor: analogWrite(9, potValue); } delay(100); }
Debe estar conectado para enviar un comentario.