This Magnetic Suspension Demo System is a device that can suspend an object by magnetic force. A set of parameters to maintain an object in steady suspension state can be obtained via PID algorithm.
a.Selection of Windings
The windings for this test are sourced ready-made from www.taobao.com (the Chinese ebay), but can also be self-made with enameled wire and winding hoop. Please be noted that there’re around 800 turns in one winding, and enameled wire with iron core shall not be selected for winding making.
The floater shall be made of high-intensity neodymium iron boron (NdFeB) magnet. If possible, a layer of plastic bag shall be wrapped all over the floater during testing so as to protect it from damages caused due to collision between floater and baseplate magnet.
Since the linear Hall sensor is easy to damage during testing, it’s suggested to prepare several more for backup.
During welding, it’s deemed easy to connect main control panel to amplifying circuit, while it’s a key step to fix the windings.
1) The ends with the same number in the two windings are connected to form a pair, and the other two ends are connected in the same way; as a result, the two sets of corresponding windings are in head-to-tail series connection, leading to repelling and attracting effect.
2)The Hall sensor shall be fixed on the axle of the winding, and right over the center point as much as possible.
3) One pair of windings will be connected to OUT1 and OUT2 of L298, and the other pair to OUT3 and OUT4 of L298N.
Please ensure that the specific windings connected to OUT1/2 and OUT3/4, and the specific leads to OUT1 or OUT2 are numbered and noted clearly, so that the matching will remain the same after disconnection and re-connection. In case the connections are mixed, you would have to adjust and do it again.（Marking numbers on windings will avoid to make mistakes- picture 3)
There’re four types of IO interfaces in Android Mega, that is, analog input/output and digital input/output.
The analog input is marked as ANALOG IN, and can measure voltage at 0 – 5V; the reading range in the corresponding code is 0 – 1023; and the example code is shown below:
1. int readValue1 = analogRead(read1 Pin);
The analog output is actually the output of square waves on string, which generates
average voltage by means of duty-cycle of hi-and-low voltages; it’s marked as PWM on the circuit board; please be noted that though the output voltage is still 0 – 5V, the numeric value range is set to be 0 – 255; the example code is shown below:
1. analogWrite(power1Pin, Pid1.power);
For digital input and output, the mode of
base-pin shall be set up first; the example code is shown below:
1. pinMode(Pin1, OUTPUT); //Set to be output base-pin
2. pinMode(Pin2, INPUT); //Set to be input base-pin
3. digitalWrite(Pin1, HIGH); // Output hi-voltage
4. int v = digitalRead(Pin2); //Read the voltage of Pin2 and the returned result is either 0 or 1
All the 0 – 53 interfaces can be used for digital input/output interfaces, while only 2 – 13 are suitable for PWM analog output, and 0 – 15 for analog input, which are independent from the numbers stated above and will not mix up. It’s strongly suggested the connection numbers are noted at the beginning of the program collectively, so as to facilitate users to understand the connections straightward.
1. int adjust1Pin = ; // For regulating potentiometer on A direction
2. int adjust2Pin = 2; // For regulating potentiometer on B direction
3. int read1Pin = 4; // For connecting input A potentiometer
4. int read2Pin = 3; // For connecting input B potentiometer
5. int i1Pin = 36; // For connecting I1 interface on motor drive-plate
6. int i2Pin = 37; // For connecting I2 interface on motor drive-plate
7. int i3Pin = 39; // For connecting I3 interface on motor drive-plate
8. int i4Pin = 38; // For connecting I4 interface on motor drive-plate
9. int power1Pin = 5; // For connecting EA interface on motor drive-plate
10. int power2Pin = 6; // For connecting EB interface on motor-drive-plate
There’re four interfaces I1 to I4 in the above codes, which will be set to be digital output.
Application of L298N
L298N is directly connected to 20V power source, and supplies a 5V voltage to circuit by means of inboard power-connection. The circuit board has two current driving circuits in symmetry. Take I1, I2 and EA for an example,
1. In case of positive voltage output, when EA range is 0 – 255, the corresponding output voltage is 0 – +20V
2. I1=1;I2=0; //In case of negative voltage output, when EA range is 0 – 255, the corresponding output voltage is 0 – -20V
3. I1=0;I2=0; //Output voltage is always 0
4. I1=1;I2=1; //Output voltage is always 0
The digital outputs I1 and I2 can be used to control the voltage direction of windings, and analog output EA to control voltage. The functions of I3, I4 and EB are of the same. Moreover, please ensure that the grounding lines of Arduino, L298N and welding circuit shall be inter-connected as regulated.
A complete set of codes is hereby attached.
The PID control can be briefly understood as a regulator control by means of P(proportional)-I(integral)-D(differential).
During adjustment, the regulation of P will lead to left-right swinging of floater in increasing magnitude. Some Kd can be added at beginning; when Kd is less than normal, the floater will look like vibrating, and while Kd is greater than normal, the swinging will not be stable and the floater might slip from side.
The principle of PID is not that complicated, but it could be a time-consuming process to adjust the PID parameters during practical testing. It’s suggested to add proper weight to floater when approaching the correct parameters, so as to achieve a remarkable stable effect.
The scorching South African heat can really take a toll…
Amaze your friends with this easy to make an cool…
YouTube content creator wermy (no real name given) has produced a work…