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:
- How can i generate a negative potential/current?
and then
- 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);
}