The magnetic field cannot be seen and felt, but all of us know what the picture created by a magnet and iron sawdust looks like.
If you make very small sawdust and mix it with a viscous base, you can get a 3D picture of the magnetic field.
The solution is called "ferromagnetic liquid" and it is freely sold in special stores. With it, you can create not only a tutorial, but also a fun toy, if you pour a little into a transparent vessel with a transparent liquid in which it can swim freely. If you bring a magnet to a vessel, move it along the walls, you can observe a rather interesting effect of a “living blot”, the ferromagnetic fluid moves behind the magnet, changing shape and size, like a jellyfish. It looks amazing and unusual.
We decided to replace the usual permanent magnet with an electric magnet, which will be controlled by a microcontroller. We connect the magnet power pulses with musical rhythms and get a “dancing blot”. Let's try!
Components and assemblyLet's find the liquid first. You can find and order it in special stores. There are variants based on kerosene and silicone. The second option is more expensive, but both options are normal. Take a 30 ml bottle, that's enough.
Prepare a container for a future dancing blot. You need to find a flat transparent bottle, the volume of which is 10 times larger than the ferromagnetic liquid. There shouldn't be too much space, but enough. We recommend using a 250 ml bottle (by Vodka), but you can use a similar container, for example, a large perfume bottle or an aquarium for small fish.
Fill the bottle strictly in this order:
Pour clean water (preferably distilled) about halfway or a little more.
- Pour clean water (preferably distilled) about halfway or a little more.
Shake well to thoroughly wet all sides of the vessel, including the neck. It is very important!
- Shake well to thoroughly wet all sides of the vessel, including the neck. It is very important!
Being careful, open a bottle with ferromagnetic liquid and slowly, but confidently pour it into a bottle.
- Being careful, open a bottle with ferromagnetic liquid and slowly, but confidently pour it into a bottle.
Bring the water to the edges, tightly twist the cover.
- Bring the water to the edges, tightly twist the cover.
What for? Kerosene-based liquid adheres strongly to any surface, including glass. If you first pour the blot into the bottle, then black spots will remain on the walls. Also, try not to get liquid on your hands, clothes or furniture. It's very hard to wash off.
Now there are two immiscible liquids in the bottle - ferromagnetic and ordinary water. Transparent and black. Black is denser, and therefore lies at the bottom of the container.
Now we need an electromagnet. There are many types of them. You need to choose the right size. Take the magnet a little less than the width of the bottle - about 70 mm.
Experiments have proven that one magnet is not enough. You need to add two more small magnets from below. Now they can work independently of each other and create different combinations of the magnetic field. The dance of the blot will become more varied and spectacular.
Print the case on a 3D printer. First, you should draw the model in the editor program.
The lower part of the body holds the bottle, the upper one closes the neck. The space for the three magnets is behind. There is a space for LED tape on the side.
Printing.
The main part of the device is assembled and tested.
Music time! To do this, we will need two speakers and a bluetooth sound card. Both are sold in a wide range. For convenience, you need to assemble everything on one plate, which is also printed on a 3D printer.
Assembly. Magnets are connected to 12 V power supply, 3A, through MOSFETs. The audio signal is applied to the analog input of the controller. The pins are connected as follows:
Pin to connect
2 small magnet 1 MOSFET
3 small magnet 2 MOSFET
4 large magnet MOSFET
A0 audio output
A little bit of physicsThe characteristics of the transparent liquid (in which the blot floats) are very important. Especially density and viscosity. The density should be slightly less than that of a ferromagnetic liquid, so we get the maximum effect of "weightlessness". In clean water, the blot is quite heavy, it sinks quickly, so its density should be increased. You can do this in many ways, for example, using salt or sugar. We used glycerin, it increased not only the density, but also the viscosity, the blot began to move more smoothly. It was experimentally found that 20 ml of glycerol should be added to 250 ml of water, this is enough. If you overdo it, the blot will pop up and will not dance.
The "soul" of the device, writing the codeOur code may be imperfect, it can be modified as you like, for different speeds and amplitudes. But it is enough to demonstrate the operation of the device.
How does the algorithm work? The program monitors the state of the audio input at some frequency, looking for power surges. When the first level is reached, lower magnets are switched on; when the second level is reached, upper magnet is turned on. The faster the music, the faster the blot moves, the louder the wider the movement.
#define M1 2 // bottom magnet 1
#define M2 4 // bottom magnet 2
#define M3 3 // top magnet
#define A A0 // audio input
byte sound;
void setup() {
pinMode(A, INPUT);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(M3, OUTPUT);
randomSeed(analogRead(A0));
digitalWrite(M2, HIGH);
digitalWrite(M1, HIGH);
delay(200);
digitalWrite(M3, HIGH);
delay(500);
}
void loop() {
load(); // reading audio
drig(); // jerking of magnets
}
void load() { // reading audio
static int a[3];
static unsigned long timer;
if (timer > millis()) return; // once every 50 seconds (optional)
a[0] = a[1];
a[1] = a[2];
a[2] = analogRead(A); // read and compare with previous readings, capturing the difference
if (a[2] > a[1] + 35) { // big splash
sound = 2;
} else if (a[2] > a[1] + 10) {// small splash
sound = 1;
} else {
sound = 0;
}
timer = millis() + 50; // polling frequency
}
void drig() { // jerking of magnets
static unsigned long timer;
static byte timerOut;
if (timer > millis()) return; // reaction frequency (set at the end of the function)
if (sound == 1) { // small splash, accidentally jerking with bottom magnets
digitalWrite(M1, random(2));
digitalWrite(M2, random(2));
timerOut = 0;
} else if (sound == 2) { // big splash, accidentally jerking with both magnets
int a = random(0, 30);
if (a == 7) kl1(); // sometimes (with a frequency of 1/30 (optional) we go to the script (you can do a lot of them)
digitalWrite(M1, random(2));
digitalWrite(M2, random(2));
digitalWrite(M3, random(10) > 6);
timerOut = 0;
} else {
timerOut++;
if (timerOut > 10) { // turn off the magnets if there is no music for a long time
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
digitalWrite(M3, LOW);
}
}
timer = millis() + random(50, 200); // random frequency from 50 to 200 ms (can be changed depending music)
}
void kl1() { // example of script
Serial.println("kl1");
digitalWrite(M2, LOW);
digitalWrite(M1, LOW);
delay(500);
digitalWrite(M2, HIGH);
digitalWrite(M1, HIGH);
delay(300);
digitalWrite(M2, LOW);
digitalWrite(M1, LOW);
for (byte i = 0; i < random(3, 6); i++) {
digitalWrite(M3, HIGH);
delay(400);
digitalWrite(M3, LOW);
delay(400);
}
}
Sometimes ready-made scripts can be included in movements. We used one script for example. He throws a blot from the bottom and pulsates it several times in space. You can create many additional scripts, this will make the dance more varied and interesting.
Article prepared with the assistance of PCBWay, industrial-grade prototyping available to everyone.
Comments