How to Connect to a Network with Grove UART Wi-Fi in NodeMCU

1) Connect the module to the D5 port.

2) Install the SimpleTimer library.

3) Run the following code:

#include <SimpleTimer.h>
#include <SoftwareSerial.h>

const int RX_PIN = 0, TX_PIN = 14;

SoftwareSerial SoftSerial(RX_PIN, TX_PIN);

SimpleTimer timer; // avoid the delay issue (http://playground.arduino.cc/Code/AvoidDelay)

void setup() {
  SoftSerial.begin(115200);

  Serial.begin(9600);

  SoftSerial.println("ATE0"); // disable echo

  timer.setTimeout(5000, [] {

    if (SoftSerial.find("OK")) {
      SoftSerial.println("AT+CWJAP_CUR=\"SampleNetwork\",\"SamplePassword\""); // connect to AP

      timer.setTimeout(5000, [] {

        if (SoftSerial.find("OK")) {
          Serial.println("Connected!");
        }

      });
    }

  });
}

void loop() {
  timer.run();
}

How to Measure Distance with a Grove Ultrasonic Ranger in NodeMCU

1) Connect the module to the D5 port.

2) Install the module library.

3) Run the following code:

#include <Ultrasonic.h>

const int PIN = 14;

Ultrasonic ultrasonic(PIN);

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(ultrasonic.MeasureInCentimeters()); // or MeasureInInches()

  delay(1000);
}

How to Get Temperature from a Grove Temperature Sensor in NodeMCU

1) Connect the module to the A0 port.

2) Run the following code:

#include <math.h>

const int B = 4275; // for v1.1 module

void setup() {
  Serial.begin(9600);
}

void loop() {
  int v = analogRead(0);

  float r = (float)(1023 - v) * 10000 / v;
  float t = 1 / (log(r / 10000) / B + 1 / 298.15) - 273.15;

  Serial.println(t);

  delay(1000);
}

How to Send/Receive with a Grove 433 Mhz Simple RF Kit in NodeMCU

Emitter

1) Connect the module to the D3 port.

2) Install the RadioHead library.

3) Run the following code:

#include <RH_ASK.h>
 
const int BIT_RATE = 2000;
 
const int RX_PIN = 14, TX_PIN = 0;
 
RH_ASK driver(BIT_RATE, RX_PIN, TX_PIN);
 
void setup() {
  driver.init();
}
 
void loop() {
  char str[] = "Simples Assim";
 
  driver.send((uint8_t *) str, strlen(str));
 
  driver.waitPacketSent();
 
  delay(1000);
}

Receiver

1) Connect the module to the D3 port.

2) Install the RadioHead library.

3) Run the following language:

#include <RH_ASK.h>

const int BIT_RATE = 2000;

const int RX_PIN = 0;

RH_ASK driver(BIT_RATE, RX_PIN);

void setup() {
  Serial.begin(9600);

  driver.init();
}

void loop() {
  uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];

  uint8_t buflen = sizeof(buf);

  if (driver.recv(buf, &buflen)) {

    for (int i = 0; i < buflen; i++)
      Serial.print((char) buf[i]);

    Serial.println("");
  }

}

How to Get GPS Data with a Grove GPS in NodeMCU

1) Connect the module to the D3 port.

2) Run the following code:

#include <SoftwareSerial.h>

const int RX_PIN = 0, TX_PIN = 14;

SoftwareSerial SoftSerial(RX_PIN, TX_PIN);

void setup() {
  SoftSerial.begin(9600);

  Serial.begin(9600);
}

void loop() {

  while (SoftSerial.available() > 0) {
    Serial.write(SoftSerial.read());
  }

}