I m basically taking values from mq6 sensor in nodemcu but i want to send those values to arduino too so that i can glow led and buzzer.. Problem : i m not able to send values and i tried some ways but its taking values but cannot store that value at arduino end.
store in String named "d" the result of the operation to SEND the RAM-adress of object "Serial1"
This doesn't make any sense
You wrote
This means your arduino code has to receive the data
modeMCU ----->----->-------"value of d"----->----->---Arduino
as d is an integer-value easiest way would be to
code for the arduino
void setup() {
//Serial Begin at 9600 Baud
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
int d = Serial1.parseInt();
Serial.println(d);
// a value of 100 means
// freeze microcontroller for 100 milliseconds
delay(100);
}
both codes are very rudimentary
How about improving your code to show a senseful value instead of just the raw ADC-reading?
have a look at nodemcu-details-specifications which states UART Pins NodeMCU/ESP8266 has 2 UART interfaces (UART0 and UART1) which provide asynchronous communication (RS232 and RS485), and can communicate at up to 4.5 Mbps. UART0 (TXD0, RXD0, RST0 & CTS0 pins) can be used for communication. However, UART1 (TXD1 pin) features only data transmit signal so, it is usually used for printing log.
you can therefore use hardware Serial port 1 pin TXD1 17 if just transmitting from the NodeMCU to an Arduino
if you require two way communication have a look at EspSoftwareSerial
the ESP8266 uses 3.3V logic - if connecting to a 5V logic Arduino use a potential divider on the Arduuino Tx to ESP8266 Rx line
the above communication was only medium effective.
You should post some more detail information:
1.) what exact type of arduino board are you using?
2.) what is the purpose of the arduino-board?
receiving some data is not a self-purpose I. assume that you want to do something with the received data in the arduino. So what is the final purpose of having the data inside the Arduino?
displaying the data on a display connected to the arduino?
using the arduino-IDE-serial-monitor to check the data?
i need only one way communication i.e from nodemcu to arduino uno and i need to store the data which is being transmitted at arduino side so that i can use it for buzzer via using if conditions.
I am using Arduino Uno R3 board and in simple words i want to transfer my readings from nodemcu to my arduino so that i can use it for buzzer (alarm warning).
here is example code using a NodeMCU ESP8266 hardware serial1 pin D4 TXD1 17
// ESP8266 example using HardwareSerial library to transmit using Serial port 1 pins TXD1 17 (no RXD1)
#define SERIAL_BAUD 38400
HardwareSerial* refSer;
void setup() {
//Initialize serial port 0
Serial.begin(115200);
delay(2000);
Serial.println("\nESP8266 HardwareSerial transmit test port 1 pin TXD1 17");
//Initialize serial port 1
refSer = new HardwareSerial(1);
refSer->begin(SERIAL_BAUD, SERIAL_8N1);
}
void loop() {
while (refSer->available() > 0) {
uint8_t byteFromSerial = refSer->read();
Serial.write(byteFromSerial);
}
while (Serial.available() > 0) {
uint8_t byteFromSerial1 = Serial.read();
Serial.write(byteFromSerial1);
refSer->write(byteFromSerial1);
}
}
just tested the above code connected to a UNO running SoftwareSerial RX is pin 2 worked OK transmitting from NodeMCU to UNO
/* Software serial multple serial test
on the UNO circuit is:
* RX is digital pin 2 (connect to TX of other device)
* TX is digital pin 3 (connect to RX of other device)
// Note: UNO uses 5V logic
// - if connecting the 3.3V logic use a voltage divider 2.2K to ground 1K to UNO Tx
Note uses interrupts on pin:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo and Micro support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
*/
#include <SoftwareSerial.h>
const byte rxPin = 2;
const byte txPin = 3;
// Set up a new SoftwareSerial object
SoftwareSerial mySerial (rxPin, txPin);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println();
Serial.println("SoftwareSerial test");
// set the data rate for the SoftwareSerial port
mySerial.begin(38400);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}