---
# System prepended metadata

title: nodemcu

---

# nodemcu
## 1.閃爍燈:
[影片](https://youtube.com/shorts/HBUi1jAYlBo?feature=share)

## ArduBlock![](https://i.imgur.com/p2x386S.png)
##       程式碼![](https://i.imgur.com/EXESAMi.png)
```javascript=
void setup()
{
  pinMode( D2![](https://i.imgur.com/QuaHlxA.jpg)
![](https://i.imgur.com/giSsmF![](https://i.imgur.com/D4WadS9.jpg)
E.jpg)![](https://i.imgur.com/VL7XPKH.jpg)

![](https://i.imgur.com/m2![](https://i.imgur.com/mEaZYdP.jpg)
JIiGr.jpg)
![](https://i.imgur.com/W6jQKut.jpg)
 , OUTPUT);
}

void loop()
{
  digitalWrite(D2 , HIGH);
  delay( 300 );
  digitalWrite(D2  , LOW);
  delay( 300 );
}
```

## 2.蜂鳴器:
圖片
![](https://i.imgur.com/bcKBKd3.jpg)


## ArduBlock![](https://i.imgur.com/RDLhY9a.png)
##       程式碼![](https://i.imgur.com/mZ8X78z.png)
```javascript=![](https://i.imgur.com/EkOfzhU.jpg)
(https://)
void setup()
{
}

void loop()
{
  tone(D6, 440);
  delay( 500 );
  noTone(D6);
  delay( 500 );
}
```
## 3.超音波感測器:
圖片
![](https://i.imgur.com/j7bie65.jpg)

## ArduBlock![](https://i.imgur.com/k58vL41.png)
## 程式碼![](https://i.imgur.com/QZgscYF.png)
```javascript=
int Range = 0 ;
int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin)
{
  long duration;
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(20);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  duration = duration / 59;
  if ((duration < 2) || (duration > 300)) return false;
  return duration;
}


void setup()
{
  digitalWrite( D6 , LOW );

  Serial.begin(9600);
}

void loop()
{
  Range = ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( D6 , D5 ) ;
  Serial.print("Distance");
  Serial.print(Range);
  Serial.print(" ");
  Serial.println();
  delay( 300 );
}
```

