Difference between revisions of "Lesson 37--Microduino Controls Relay"
(Created page with "{{Language|第三十七课--Microduino 控制继电器开关}} {| style="width: 800px;" |- | ==Objective== This tutorial will teach you how to use the relay to control a relat...") |
|||
Line 15: | Line 15: | ||
**Button one | **Button one | ||
**NPN transistor one | **NPN transistor one | ||
− | **10k | + | **10k resistor one |
− | **1k | + | **1k resistor one |
**Diode one | **Diode one | ||
**Battery box one | **Battery box one | ||
Line 22: | Line 22: | ||
'''Relay Introduction:''' | '''Relay Introduction:''' | ||
− | Relay is an electronic control device, it has a control system (also called input circuit) and | + | Relay is an electronic control device, it has a control system (also called input circuit) and controlled system (also called the output circuit), usually used in automatic control circuit. It is actually a kind of "automatic switch" which uses the less current to control large current. In the circuit, it plays an automatic adjustment, safety protection, conversion circuit function. |
− | The principle of relay is | + | The principle of relay is that when the input (such as voltage, current, temperature, etc.) achieve specified value, the controlled circuit will be conducted or broken. It can be divided into electric parameters (such as current, voltage, frequency, power, etc.) relay and non-electric parameters (such as temperature, pressure, speed, etc.) relay. It has characters that fast, work stability, long service life, small volume, etc. Widely used in power protection, automation, motor, remote control, measurement and communication device etc. |
[[File:第三十七课-继电器.jpg|600px|center|thumb]] | [[File:第三十七课-继电器.jpg|600px|center|thumb]] | ||
Line 57: | Line 57: | ||
/* | /* | ||
− | * Use relay to | + | * Use relay to control motor |
*/ | */ | ||
Line 104: | Line 104: | ||
==Debug== | ==Debug== | ||
− | Step | + | Step 1: Copy the code to IDE and compile it |
− | Step | + | Step 2: Set up circuit, as follows: |
[[File:第三十七课-Microduino控制继电器开关连接图.jpg|600px|center|thumb]] | [[File:第三十七课-Microduino控制继电器开关连接图.jpg|600px|center|thumb]] | ||
Latest revision as of 08:52, 12 September 2016
Language: | English • 中文 |
---|
ObjectiveThis tutorial will teach you how to use the relay to control a relatively large current electrical appliances (this experiment will use a driver motor unloaded from the old VCD) Equipment
Relay Introduction: Relay is an electronic control device, it has a control system (also called input circuit) and controlled system (also called the output circuit), usually used in automatic control circuit. It is actually a kind of "automatic switch" which uses the less current to control large current. In the circuit, it plays an automatic adjustment, safety protection, conversion circuit function. The principle of relay is that when the input (such as voltage, current, temperature, etc.) achieve specified value, the controlled circuit will be conducted or broken. It can be divided into electric parameters (such as current, voltage, frequency, power, etc.) relay and non-electric parameters (such as temperature, pressure, speed, etc.) relay. It has characters that fast, work stability, long service life, small volume, etc. Widely used in power protection, automation, motor, remote control, measurement and communication device etc. Most of the relay as shown above, there are five pins or 6 pins. This tutorial use the type that has five pins. The difference between them lies in the 6 pins relay has two com pins, you can use any of them freely, and the relay with 5 pins only has on com pin. The following is the relay pin introduction: As shown above in the middle of the yellow diagram, put the bottom pin of relay toward you. NC: Normal Closed NO: Normal Open COM: Common SchematicNote:
Program/*
* Use relay to control motor
*/
const int buttonPin = 2; // pushbutton
const int relayPin = 13; // Relay
int relayState = 0; // relay state
void setup()
{
Serial.begin(9600); // Enable Serial port, set baud rate 9600 bps
pinMode(buttonPin, INPUT); // Set buttonPin to INPUT
pinMode(relayPin, OUTPUT); // Set relayPin to OUTPUT
}
void switchRelay()
{
if (relayState == 0)
relayState = 1; // Set relay state to ON
else
relayState = 0; // Set relay state to OFF
digitalWrite(relayPin, relayState); // Switch the button
Serial.print("Relay status: "); // Serial output relay state
Serial.println(relayState);
}
void loop()
{
int buttonState;
// Read the button state
buttonState = digitalRead(buttonPin);
// Check if the button was pressed
// If yes, buttonState is HIGH
if (buttonState == HIGH) {
switchRelay(); // Switch relay
delay(500); // Delay 0.5s
}
} DebugStep 1: Copy the code to IDE and compile it Step 2: Set up circuit, as follows: Step 3: Run program Step 4: Press button, check if the motor can rotate. ResultPress the button, relay is in Normal Open(NO) state, the motor rotates, then press button again, relay switch to Normal Closed(NC) state, then motor stops. Video |