This is my drawing project where I use a DC motor to paint circles.
I created a drawing machine designed to make circles; I used paint for this instance. I did this to see what other things I can make with the Arduino. Plus, I did this to understand how the DC motor works and how to program it. This was also the first time I was able to use Legos to create the frame for my model. The Legos were used for its versatility and accommodations for certain areas. The model works by being supplied from a 9 volt battery mounted on top of the model, but plugged into the Arduino. The wires that connect the Arduino to the bread board is how the energy is transferred, finally using that energy to the DC motor.
This is the video on how it works. For convenience, I added captions to the video. And for some reason, the video has a very low resolution. I’m not sure why. As I was editing it, it was fine.
This is the result from the drawing project. The drawing on the right came out to be better.
With Legos, I was able to make accommodations for the interfaces.
Here is another example of versatility: the ability to make a gap for the power and ground wires.
And the last example of versatility: a gap was made for the yellow wire.
The 9 volt battery is located on top and inside the model.
The inside of the model. The Arduino circuit board, wires, breadboard, and the DC motor.
The schematics of my Arduino:
And of course, the code to my model:
int motorPin = 9; // define the pin the motor is connected to
// (if you use pin 9,10,11 or 3you can also control speed)
/*
* setup() – this function runs once when you turn your Arduino on
* We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
* rather than an input (checking whether a pin is high or low)
*/
void setup()
{
pinMode(motorPin, OUTPUT);
}
/*
* loop() – this function will start after setup finishes and then repeat
* we call a function called motorOnThenOff()
*/
void loop() // run over and over again
{
digitalWrite(motorPin, HIGH);
//motorOnThenOff();
//motorOnThenOffWithSpeed();
//motorAcceleration();
}
/*
* motorOnThenOff() – turns motor on then off
* (notice this code is identical to the code we used for
* the blinking LED)
*/
int onTime;
int offTime;
int onSpeed;
int offSpeed;
void motorOnThenOff(){
int onTime = 2500; //the number of milliseconds for the motor to turn on for
int offTime = 1000; //the number of milliseconds for the motor to turn off for
digitalWrite(motorPin, HIGH); // turns the motor On
delay(onTime); // waits for onTime milliseconds
digitalWrite(motorPin, LOW); // turns the motor Off
delay(offTime); // waits for offTime milliseconds
}
/*
* motorOnThenOffWithSpeed() – turns motor on then off but uses speed values as well
* (notice this code is identical to the code we used for
* the blinking LED)
*/
void motorOnThenOffWithSpeed(){
onSpeed = 50; // a number between 0 (stopped) and 255 (full speed)
onTime = 2500; //the number of milliseconds for the motor to turn on for
offSpeed = 0; // a number between 0 (stopped) and 255 (full speed)
offTime = 0; //the number of milliseconds for the motor to turn off for
analogWrite(motorPin, onSpeed); // turns the motor On
delay(onTime); // waits for onTime milliseconds
analogWrite(motorPin, offSpeed); // turns the motor Off
delay(offTime); // waits for offTime milliseconds
}
/*
* motorAcceleration() – accelerates the motor to full speed then
* back down to zero
*/
void motorAcceleration(){
int delayTime = 50; //milliseconds between each speed step
//Accelerates the motor
for(int i = offSpeed; i <= onSpeed; i++){ //goes through each speed from 0 to 255
analogWrite(motorPin, i); //sets the new speed
delay(delayTime); // waits for delayTime milliseconds
}
//Decelerates the motor
for(int i = onSpeed; i >= offSpeed; i–){ //goes through each speed from 255 to 0
analogWrite(motorPin, i); //sets the new speed
delay(delayTime); // waits for delayTime milliseconds
}
}