Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Peter Neufeld
Published

Magnetic Levitation – The Digital Way

Magnetic-Levitation-Object with only an ESP32Pico M5Stack „ATOM LITE/MATRIX," a modified simple 5V-relais and a Hall-sensor.

IntermediateShowcase (no instructions)10 hours5,742
Magnetic Levitation – The Digital Way

Story

Read more

Schematics

Schematic

Code

ARDUINO code

Arduino
/**************************************
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);     
}

Credits

Peter Neufeld
4 projects • 11 followers

Comments