Electronic – arduino – How to i generate a negative potential/current and alternate the pin-input between positive and negative potential/current using an arduino uno

arduinoarduino unoelectromagneticmagneticsnegative-voltage

My goal is to make the barmagnet rotate by activating two coils and use both forces at the same time with an Arduino Uno. One coil should have a positive potential or current to attract the negative side of the magnet, the other coil should have a negative potential or current to attract the other side. I was able to make it rotate by activating only one coil at the time, but i want to make the movement a bit smoother by using the forces of two coils instead of one. Now my questions are:

  1. How can i generate a negative potential/current?

and then

  1. How can i alternate the input on the same pin between positive and negative? I am thinking about something like this:
    int delayBetweenCoilActivations = 50;   
    
    void setup() {
      pinMode(2, OUTPUT); //a pin for each coil
      pinMode(3, OUTPUT);
      pinMode(4, OUTPUT);
      pinMode(6, OUTPUT);
    
    }
    
    void loop() {
    digitalWrite(Pin1, LOW);
    digitalWrite(Pin2, (negative)HIGH);  
    digitalWrite(Pin3, LOW);
    digitalWrite(Pin4, (positive)HIGH);
    
    delay(delayBetweenCoilActivations);
    
    digitalWrite(Pin1, (positive)HIGH);
    digitalWrite(Pin2, LOW);  
    digitalWrite(Pin3, (negative)HIGH);
    digitalWrite(Pin4, LOW);
    
    delay(delayBetweenCoilActivations);
    
    digitalWrite(Pin1, LOW);
    digitalWrite(Pin2, (positive)HIGH);  
    digitalWrite(Pin3, LOW);
    digitalWrite(Pin4, (negative)HIGH);
    
    delay(delayBetweenCoilActivations);
    
    digitalWrite(Pin1, (negative)HIGH);
    digitalWrite(Pin2, LOW);  
    digitalWrite(Pin3, (positive)HIGH);
    digitalWrite(Pin4, LOW);
    
    delay(delayBetweenCoilActivations);
    }

Sketch of how i want the barmagnet to rotate

Best Answer

You can't sen a pin negative. But setting one pin high and one pin low will make current flow in one direction, and if you swap the high and low, the current will flow in the other direction.