Magnetic-Levitation-Object with only …
- an ESP32Pico M5Stack „ATOM LITE“ or „ATOM MATRIX“
- a modified simple 5V-relais and
- a HALL-sensor A1302/A1308.
- The wooden carrier is made of an embroidery frame.
After I had successfully built up a „Magnetic Levitation Object“ in conventional analog design in article „Magnetic Levitation – The Easy Way“ , I now wanted to replace the technology of the 1980s with modern digital components. The object should also get a little smaller, an -as I hope – more beautiful.
In this video you can see the result: Magnetic Levitation – The Digital Way
Instead of the analog comparator, an ESP32 SoC module from M5Stack is now used. The ATOM LITE or also the ATOM MATRIX are extremely small (24mm*24mm*10mm or 15mm) and still offer all the appreciated features of the ESP32.
So especially a quite fast 12Bit-ADC is available.
The Hall sensor A1302 is now operated with 3V3 so that the level is suitable for the ESP32 ADC. This is a bit below its data sheet specification, but works very well.
Furthermore a modified 5V relay is used as electromagnet. The modification of the relay is described in detail HERE. It can be controlled directly with 3V3 from the ESP32.
The small minimalistic ARDUINO IDE program makes sure that the ADC of the ESP32 behaves like the comparator LM311 of the analog version – including the hysteresis, which stabilizes the behavior of the control very much. This is extremely simple to program, but works very well once you have experimentally determined the correct value for the TRIGGER variable. This value is very dependent on the magnets and the payload weight, as there is only a range of a few mm where the electromagnet can control the flightlevel of the magnetic object..
ATTENTION: It turned out that the quality of the 5V supply is very important. At first I had problems with the stability of the flight altitude as long as I used the 5V of my notebook via the USB port. This supply was too unstable and unclean. Only when I connected a USB hub with its own power supply in between it worked very well.
With a future extension of the program this value could be determined in the program and stored in the permanent memory of ESP32.
I tried to write the necessary code in MicroPython, but that turned out to be a bit to slow. So here you see my simple program-code for the ARDUINO IDE and an M5Stack’s ATOM LITE:
/**************************************
Magnetic Levitation object:
Lets a LEGO man, glued together with a neobodymium magnet, float under a modified 5V relay
- SoC: ESP32, very good: M5Stack's ATOM LITE or ATOM MATRIX
- Electromagnet: Modified 5V-Relais HW-482 with 3V3/5V transistor input
- Sensor: HALL-sensor A1302 or A1308
***************************************/
// int TRIGGER = 2740; // Triggerlevel is set to a level where weight of payload is equal to the force between magnet and electromagnet
int TRIGGER = 2740; // good for payload = 2 Neobdym-Magnets and a LEGO-Man
int HYST = 35; // Hysterese for trigger level
int HALL_PIN = 33; // analog Signal from HALL-sensor at GPIO33
int HALL_VAL = 0; //
int RELAIS_PIN = 23; // GPIO23 to drive the transistor input of the modified 5V-relais that is used as electromagnet
int X = 0; //
void setup(){
Serial.begin(115200);
pinMode(RELAIS_PIN, OUTPUT);
Serial.print("Magnetic Levitation: START " );
}
void loop(){
HALL_VAL =analogRead(HALL_PIN); //read HALL-Sensor with default 0-3.9V input >> 12bit
if (HALL_VAL < (TRIGGER + X) ){
digitalWrite(RELAIS_PIN, HIGH); // lift the payload
X = HYST;
}
else{
digitalWrite(RELAIS_PIN, LOW); // drop the payload
X = 0 - HYST;
}
// no delay is best
// delay (1);
}
/**************************************
Magnetic Levitation object:
Lets a LEGO man, glued together with a neobodymium magnet, float under a modified 5V relay
- SoC: ESP32, very good: M5Stack's ATOM LITE or ATOM MATRIX
- Electromagnet: Modified 5V-Relais HW-482 with 3V3/5V transistor input
- Sensor: HALL-sensor A1302 or A1308
***************************************/
// int TRIGGER = 2740; // Triggerlevel is set to a level where weight of payload is equal to the force between magnet and electromagnet
int TRIGGER = 2740; // good for payload = 2 Neobdym-Magnets and a LEGO-Man
int HYST = 35; // Hysterese for trigger level
int HALL_PIN = 33; // analog Signal from HALL-sensor at GPIO33
int HALL_VAL = 0; //
int RELAIS_PIN = 23; // GPIO23 to drive the transistor input of the modified 5V-relais that is used as electromagnet
int X = 0; //
void setup(){
Serial.begin(115200);
pinMode(RELAIS_PIN, OUTPUT);
Serial.print("Magnetic Levitation: START " );
}
void loop(){
HALL_VAL =analogRead(HALL_PIN); //read HALL-Sensor with default 0-3.9V input >> 12bit
if (HALL_VAL < (TRIGGER + X) ){
digitalWrite(RELAIS_PIN, HIGH); // lift the payload
X = HYST;
}
else{
digitalWrite(RELAIS_PIN, LOW); // drop the payload
X = 0 - HYST;
}
// no delay is best
// delay (1);
}
Comments