Arduino + Small DC motor

This little engine has the ability to buzz.
You can manage the level with command like

analogWrite(motorPin, speed);

where speed is 0 to 255 means level.

I am using details from Starter Kit
Mosfet transistors [IRF520], (to manage voltage for motor)
1N4007 diod (for protection)
TFK-280SA-22125 MOTOR (6V DC)

See the circuit below (click to enlarge)































//Arduino code (google examples for more details)

const int motorPin =  9; // the number of the motor pin

int switchState = 0;  // variable for reading the switch's status

void setup() {
  // initialize the motor pin as an output:
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");
}


void loop()
{
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
}



Connect arduino usb to computer, open terminal emulator (ubuntu) and allow this device to run:
sudo chmod a+rw /dev/ttyACM0

Upload the sketch (see the code above) and open Tools>Serial Monitor
Type any value from 0 to 255 into command line














At 255 it is running at full speed and buzzes very fine. 100 is slower. 50 is very slow. At 30 it stuck.

Unfortunately I don't have propeller now, and can't make this test more interesting. You may google for lessons, where it is combined with temperature sensor for PID control.
 https://youtu.be/CP_ZifhiC-U









No comments:

Post a Comment