The choice of transistor is dependent on the amount of current required to activate the solenoid or relay. The data sheet may specify this in milliamperes (mA) or as the resistance of the coil. To find the current needed by your solenoid or relay, divide the voltage of the coil by its resistance in ohms. For example, a 12V relay with a coil of 185 ohms draws 65 mA: 12 (volts) / 185 (ohms) = 0.065 amps, which is 65 mA. Small transistors such as the 2N2222 are sufficient for solenoids requiring up to a few hundred milliamps. Larger solenoids will require a higher power transistor, like the TIP102/TIP120 or similar. There are many suitable transistor alternatives.The purpose of the diode is to prevent reverse EMF from the coil from damaging the transistor (reverse EMF is a voltage produced when current through a coil is switched off). The polarity of the diode is important; there is a colored band indicating the cathode—this should be connected to the
Most solenoids require more power than an Arduino pin can provide, so a transistor is used to switch the current needed to activate a solenoid. Activating the solenoid is achieved by using digitalWrite to set the pin HIGH. . The solenoid will be activated for one second every hour:
int solenoidPin = 2; // Solenoid connected to transitor on pin 2
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
long interval = 1000 * 60 * 60 ; // interval = 60 minutes
digitalWrite(solenoidPin, HIGH); // activates the solenoid
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // deactivates the solenoid
delay(interval); // waits one hour
}
No comments:
Post a Comment