## Public projects 1

#### Magnetic Stirrer

Project showcase by jdale18

• 6,380 views
• 13 respects

## Respected projects 0

jdale18 hasn't respected any projects yet.

• ##### Magnetic Stirrerover 3 years ago

circuit seems to run fine how it is. but i am by no means an electronics guru. Just a simple circuit i picked up during my circuit classes in college. Also, I had a bunch of tip31a transistors lying around and that is what i used back in college. also after a quick compare of the 2803 you suggested i would rather use the tip31a it can handle more amperage so then i can repurpose this project to control other dc motors. but the 2803 package is pretty cool and probably strong enough to run several fans like you said.

• ##### Magnetic Stirrerover 3 years ago

I tried the use links and cut/paste code into code section of project and both ways seem to fail. i pasted code in comment section

• ##### Magnetic Stirrerover 3 years ago

/*
Magnetic Stirrer

Layman summary:
We will use a potiometer to control the speed of a DC motor.
When the potiometer is turned to full Ohms then the motor should stop.
When the potiometer is turned to 0 Ohms then the motor should be running full speed.
And if the potiometer is somewhere in the middle then the motor speed will follow.

InDepth summary;
This code will read an analog voltage of the potiometer using pin(A0).
We will take the analog to digital conversion (ADC) value and
produce a corresponding PWM signal on pin(9). The PWM signal will turn the
NPN transistor on/off very quickly to the point where the motor will spin like
it is getting less than full power.

Notes:
1. Please note the ADC on the Arduino mega is 10 bits. The PWM is 8 bits.
So we need to divide the ADC value from pin(A0) by 4 and then send that value to
the PWM on pin(9).

1. Intersting to note that if you leave out the division then
you will notice that a 1/4 turn of the potiometer will give you a 0 rpm to full speed
on your motor. This is because 8 bits will get you 255 steps for the PWM and the
ADC 10 bits will give you 1023 steps. 1023/255 = 4 (roughly)

2. I added a delay at end of loop to help stablize motor speed. I noticed
with PC fans I was using that if you rotated the potiometere quickly or back and fourth
that the load of the magnets and the drastic speed up/down would burn out the
cheap PC fan motors. So a word of caution is to turn the pot slowly to avoid motor burn out :)

Brief Function description:
analogWrite() allows us to send a 0 to 255 value to a PWM pin.
ReadAnalogVoltage() allows us to read a 0 to 5Vdc voltage and convert
voltage into a value between 0 to 1023.
Serial.Began starts serial communication to "Serial Monitor"
Serial.PrintLn writes one line to "Serial Monitor"

Credits:
Giving credit to the contributors of the example (basic) "Fade" program
and "ReadingAnalogVoltage" program since this code is really just a cut/paste of
both example programs into one working code.

leaving the original ReadAnalogVoltage notes since I found them useful as well :)
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

int motor1 = 9; // the PWM pin
int motor1speed = 0; // how fast motor1 is

// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(motor1, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {

``````  // read the input on analog pin 0:
``````

``````// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 12V):
``````

float voltage = motor1speed * (12.0 / 1023.0);

// print out the value you read:
Serial.println(motor1speed);
// print out the voltage
Serial.println(voltage);

// set the motor1speed of pin 9:
analogWrite(motor1, motor1speed/4);

// delay 30 miliseconds. this pre
delay(30);
}