For a project I'm working on, I need to turn an electromagnet on and off relatively fast. I need my arduino uno to turn the power on and off at a rate ranging around 10 times per second or 100 times per second at the fastest. I figured since the adruino uno is capable of doing things in milliseconds, that I could safely get my arduino to cut and re-supply power to my electromagnet at 100 times per second.
I was going to solder a circuit together(as I have a dislike for breadboards) specifically to connect the signal wire to the positive and negative wires of the electromagnet via a transistor, as demonstrated here
http://bildr.org/2011/03/high-power-control-with-arduino-and-tip120/
What I don't understand is how to tell my arduino uno what it's connecting to, and what pin to use.
for example in void setup, I can't say something simple like "servo_0.attach(0); " which identifies what it's connecting to (in that case, a servo). Also, when I was looking at someone else's question in a forum (2nd link above) where they were trying to get their arduino to turn a circuit off within a time period, he mentions the use pf "digitalWrite(pinNum, HIGH);" , implying that he used this in combination with the code provided from the first site I listed.
The code from the first site I listed was this
//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code to output a PWM sine wave signal on pin 9
//////////////////////////////////////////////////////////////////
#define fadePin 9
void setup(){
pinMode(fadePin, OUTPUT);
}
void loop(){
for(int i = 0; i<360; i++){
//convert 0-360 angle to radian (needed for sin function)
float rad = DEG_TO_RAD * i;
//calculate sin of angle as number between 0 and 255
int sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
analogWrite(fadePin, sinOut);
delay(15);
}
}