1
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ Try an H bridge \$\endgroup\$
    – Rodo
    Mar 30, 2021 at 20:18
  • \$\begingroup\$ Tell us about the coil driver circuit. Surely you are not connecting it to the Arduino pin directly? \$\endgroup\$
    – polwel
    Mar 31, 2021 at 7:15
  • \$\begingroup\$ @Rodo: Yeah that looks interesting...i will test it and post it if it works or not \$\endgroup\$
    – Murpin
    Mar 31, 2021 at 12:01
  • \$\begingroup\$ @polwel: The coils are directly connected to the pins. \$\endgroup\$
    – Murpin
    Mar 31, 2021 at 12:02

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.