<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
		<id>http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Lesson_37--Microduino_Controls_Relay</id>
		<title>Lesson 37--Microduino Controls Relay - 版本历史</title>
		<link rel="self" type="application/atom+xml" href="http:///https//wiki.microduino.cn/index.php?action=history&amp;feed=atom&amp;title=Lesson_37--Microduino_Controls_Relay"/>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Lesson_37--Microduino_Controls_Relay&amp;action=history"/>
		<updated>2026-04-20T23:37:15Z</updated>
		<subtitle>本wiki的该页面的版本历史</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https//wiki.microduino.cn/index.php?title=Lesson_37--Microduino_Controls_Relay&amp;diff=4103&amp;oldid=prev</id>
		<title>Pkj：Created page with &quot;{{Language|第三十七课--Microduino 控制继电器开关}} {| style=&quot;width: 800px;&quot; |- | ==Objective== This tutorial will teach you how to use the relay to control a relat...&quot;</title>
		<link rel="alternate" type="text/html" href="https//wiki.microduino.cn/index.php?title=Lesson_37--Microduino_Controls_Relay&amp;diff=4103&amp;oldid=prev"/>
				<updated>2014-09-10T03:13:54Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Language|第三十七课--Microduino 控制继电器开关}} {| style=&amp;quot;width: 800px;&amp;quot; |- | ==Objective== This tutorial will teach you how to use the relay to control a relat...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Language|第三十七课--Microduino 控制继电器开关}}&lt;br /&gt;
{| style=&amp;quot;width: 800px;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
==Objective==&lt;br /&gt;
This 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)&lt;br /&gt;
&lt;br /&gt;
==Equipment==&lt;br /&gt;
*'''[[Microduino-Core]]'''&lt;br /&gt;
*'''[[Microduino-FT232R]]'''&lt;br /&gt;
*Other equipment&lt;br /&gt;
**Breadboard Jumper            one box   &lt;br /&gt;
**Breadboard  	               one piece  &lt;br /&gt;
**DC electrical appliance      one &lt;br /&gt;
**Button                       one&lt;br /&gt;
**NPN transistor              one&lt;br /&gt;
**10k registor                 one&lt;br /&gt;
**1k  registor                 one&lt;br /&gt;
**Diode                        one&lt;br /&gt;
**Battery box                  one&lt;br /&gt;
**USB cable                    one&lt;br /&gt;
&lt;br /&gt;
'''Relay Introduction：'''&lt;br /&gt;
     Relay is an electronic control device, it has a control system (also called input circuit) and controled system (also called the output circuit), usually used in automatic control circuit. It is actually a kind of &amp;quot;automatic switch&amp;quot; which uses the less current to control large current. In the circuit, it plays an automatic adjustment, safety protection, conversion circuit function.&lt;br /&gt;
　　 The principle of relay is taht 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.&lt;br /&gt;
　　 &lt;br /&gt;
[[File:第三十七课-继电器.jpg|600px|center|thumb]]&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
As shown above in the middle of the yellow diagram, put the bottom pin of relay toward you.&lt;br /&gt;
&lt;br /&gt;
NC: Normal Closed&lt;br /&gt;
&lt;br /&gt;
NO: Normal Open&lt;br /&gt;
&lt;br /&gt;
COM: Common&lt;br /&gt;
&lt;br /&gt;
==Schematic==&lt;br /&gt;
[[File:第三十七课-Microduino控制继电器开关原理图.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
*Relay coil connects to +5V, on the other side of the coil (blue line) connects to the collector of the NPN transistor&lt;br /&gt;
&lt;br /&gt;
*The rectifier diode connected in parallel to the coil, pay attention to the rectifier diode's directivity, marking end toward to the power (in this case, if there is no rectifier diode, instead of a light emitting diode (led))&lt;br /&gt;
&lt;br /&gt;
*NPN transistor Emitter connects to GND, then the Base series of a 1k resistor connects to Microduino pin 13&lt;br /&gt;
&lt;br /&gt;
*Motor anode (red line) connects to relay's NO pin, and the cathode (black line) connects to GND&lt;br /&gt;
&lt;br /&gt;
*Use a relatively large power, the anode connects to the COM of relay (this tutorial uses two 18650 battery series in which the output voltage is 7.4 V)&lt;br /&gt;
&lt;br /&gt;
*Finally, the pin of button connects to  +5 v, another pin connects to pin2 and pick up a 10k resistor to GND, that is done.&lt;br /&gt;
&lt;br /&gt;
==Program==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Use relay to contorl motor&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
const int buttonPin = 2;                 // pushbutton&lt;br /&gt;
const int relayPin = 13;                 // Relay&lt;br /&gt;
int relayState = 0;                      // relay state&lt;br /&gt;
 &lt;br /&gt;
void setup()&lt;br /&gt;
{&lt;br /&gt;
  Serial.begin(9600);                     // Enable Serial port, set baud rate 9600 bps&lt;br /&gt;
   &lt;br /&gt;
  pinMode(buttonPin, INPUT);             // Set buttonPin to INPUT&lt;br /&gt;
  pinMode(relayPin, OUTPUT);             // Set relayPin to OUTPUT    &lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void switchRelay()&lt;br /&gt;
{&lt;br /&gt;
  if (relayState == 0)                        &lt;br /&gt;
    relayState = 1;                      // Set relay state to ON&lt;br /&gt;
  else&lt;br /&gt;
    relayState = 0;                      // Set relay state to OFF     &lt;br /&gt;
       &lt;br /&gt;
  digitalWrite(relayPin, relayState);    // Switch the button&lt;br /&gt;
 &lt;br /&gt;
  Serial.print(&amp;quot;Relay status: &amp;quot;);        // Serial output relay state&lt;br /&gt;
  Serial.println(relayState);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void loop()&lt;br /&gt;
{&lt;br /&gt;
  int buttonState;&lt;br /&gt;
   &lt;br /&gt;
  // Read the button state&lt;br /&gt;
  buttonState = digitalRead(buttonPin);&lt;br /&gt;
 &lt;br /&gt;
  // Check if the button was pressed&lt;br /&gt;
  // If yes, buttonState is HIGH&lt;br /&gt;
  if (buttonState == HIGH) {      &lt;br /&gt;
     switchRelay();                      // Switch relay &lt;br /&gt;
     delay(500);                         // Delay 0.5s&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Debug==&lt;br /&gt;
Step 1：Copy the code to IDE and compile it&lt;br /&gt;
&lt;br /&gt;
Step 2：Set up circuit, as follows: &lt;br /&gt;
[[File:第三十七课-Microduino控制继电器开关连接图.jpg|600px|center|thumb]]&lt;br /&gt;
&lt;br /&gt;
Step 3: Run program&lt;br /&gt;
&lt;br /&gt;
Step 4: Press button, check if the motor can rotate. &lt;br /&gt;
&lt;br /&gt;
==Result==&lt;br /&gt;
Press 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.&lt;br /&gt;
==Video==&lt;br /&gt;
http://v.youku.com/v_show/id_XNjc5OTAyNDky.html&lt;/div&gt;</summary>
		<author><name>Pkj</name></author>	</entry>

	</feed>