#define SensorPin A0 // the pH meter Analog output is connected with the Arduino’s Analog
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
//Blynk Pins
#define pH_Pin V2
#define temp_Pin V3
#define CO2_Pin V4
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// CO2
#include <MHZ19.h> // MHZ-19 library
#include <SoftwareSerial.h>
#define RX_PIN 3 // Tx pin of the MHZ19
#define TX_PIN 1 // Rx pin of the MHZ19
#define BAUDRATE 9600 // Device to MH-Z19 Serial baudrate (should not be changed)
SoftwareSerial mySerial(RX_PIN, TX_PIN);
MHZ19 myMHZ19;
#include <SoftwareSerial.h>
// BLYNK
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL29QyjCZ3W"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "a8lT_TobHldCKJBXA_cGFc2zAe9QZjjg"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Stopit";
char pass[] = "Stopitboy";
void setup()
{
Serial.begin(9600);
Serial.println("Ready"); //Test the serial monitor
// Start up the library
sensors.begin();
// Start Co2
mySerial.begin(BAUDRATE); // (Uno example) device to MH-Z19 serial start
myMHZ19.begin(mySerial); // *Serial(Stream) refence must be passed to library begin().
myMHZ19.autoCalibration(); // Turn auto calibration ON (OFF autoCalibration(false))
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, 8080);
}
void loop()
{
// Temp Probe
sensors.requestTemperatures(); // Send the command to get temperatures
float tempC = sensors.getTempCByIndex(0);
Serial.print("Temperature = ");Serial.println(tempC);
// pH Sensor
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Serial.print("pH = ");
Serial.println(phValue,2);
//Get CO2
int CO2;
CO2 = myMHZ19.getCO2();
Serial.print("CO2 = ");Serial.print(CO2);Serial.println(" ppm");
delay(2000);
// Send to Blynk
Blynk.virtualWrite(pH_Pin, phValue);
Blynk.virtualWrite(temp_Pin, tempC);
Blynk.virtualWrite(CO2_Pin, CO2);
Blynk.run();
}
Output:
Variables and constants in RAM (global, static), used 30936 / 80192 bytes (38%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1532 initialized variables
╠══ RODATA 2916 constants
╚══ BSS 26488 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 62811 / 65536 bytes (95%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 30043 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 261540 / 1048576 bytes (24%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 261540 code in flash
esptool.py v3.0
Serial port COM6
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 48:3f:da:03:c7:b2
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 300176 bytes to 219265...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (14 %)
Writing at 0x00008000... (21 %)
Writing at 0x0000c000... (28 %)
Writing at 0x00010000... (35 %)
Writing at 0x00014000... (42 %)
Writing at 0x00018000... (50 %)
Writing at 0x0001c000... (57 %)
Writing at 0x00020000... (64 %)
Writing at 0x00024000... (71 %)
Writing at 0x00028000... (78 %)
Writing at 0x0002c000... (85 %)
Writing at 0x00030000... (92 %)
Writing at 0x00034000... (100 %)
Wrote 300176 bytes (219265 compressed) at 0x00000000 in 19.9 seconds (effective 120.8 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
And the device is not coming online. I have switched boards, confirmed my wifi is 2.4 Ghz, and tried mobile hotspot. Still no dice. I also confirmed my baudrate matched in serial monitor, and serial monitor just feedsback random signs.
@David08755 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code and your compiler output so that they display correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
Not really, as I’m sure you can see if you take a look at your post.
The triple backticks need to be on separate line. Once you have them in the correct position you’ll see two scrollable boxes, and your descriptive text will be outside of these boxes.
The next think I’ll ask for is your serial monitor output, and that also needs triple backticks.
It doesn’t matter which baud rate you use, provided your sketch and serial monitor match.
However, most NodeMCU boards use 74880 as their default baud rate, and output their bot messages at that baud rate.
It therefore makes sense to use 74880 as the maud rate for your serial debug messages in your sketch.
Maybe you can endeavour to be clearer in future posts?
EDIT - Okay, I see what you’ve done now - you’ve created a Software Serial port on pins 1 & 3, which are the pins used by your hardware serial port.
You need to change this…
to different pins, otherwise both your hardware and software serial ports are talking across eachother.
There was a yellow line that read “Not connected. Select a board and port to connect automatically”. But the board and port are clearly chosen because it displays below
Ln 50, Col 19 NodeMCU 1.0 (ESP-12E Module) on COM6
So I changed the code to the basic blynk quickstart code to rule out hardware issues. But my device is bouncing back and forth between online and offline
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL29QyjCZ3W"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "P5QRoWVpBTsG3EmL8pr0bVzo6IKV3uj2"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Stopit";
char pass[] = "Stopitboy";
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 8080);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
Change the baud rate in your sketch to 74880 and re-upload it to your NodeMCU and set the serial monitor to the same baud rate.
When you do that, this line of serial output…
will make more sense, and will show the reason why your device is rebooting.
Can you confirm that the only thing connected to your NodeMCU is the USB serial cable?
When you compiled your code did you set the Debug Level (in the IDE > Tools > Debug level) to something other than “none” ?
The reason I ask is that some of these messages that you can now see look like debug messages from the IDE’s ESP core…