'when uploading the nodemcu everything works except for the pump, it uploads and stops
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h> //for i2c
LiquidCrystal_I2C lcd(0x27, 16, 2);
/*
librarries for esp-8266 wifi and thing-speak
channel ID
thing-speak Write Api Key.
*/
#include <ESP8266WiFi.h>
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
int pump = 3;
int tempMax = 25;
unsigned long myChannelNumber = 1699712;
const char * myWriteAPIKey = "4NBIAWTER4EDTKNY";
const char* ssid = "PLDT_Home_83956"; // your network SSID (name)
const char* password = "Pldthome1"; // your network password
//float Tavg;
WiFiClient client;
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float T1, T2, T3, F1, F2, F3, Tavg;
void setup(void)
{
pinMode(pump, OUTPUT);
Serial.begin(115200);
Wire.begin(12,14);
lcd.backlight();
lcd.begin(20, 4);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
sensors.begin(); // Start up the library
deviceCount = sensors.getDeviceCount();
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop(void)
{
if( Tavg >= tempMax) {
digitalWrite(pump, LOW);
} else {
digitalWrite(pump, HIGH);
}
// Send command to all the sensors for temperature conversion //
sensors.requestTemperatures();
lcd.setCursor (0,0);
Serial.print("Avg Temp:");
Serial.print(Tavg);
Serial.print("*C ");
lcd.print("Avg Temp: ");
lcd.print (Tavg);
/*
debug only
int T1 = random(0, 50);
int T2 = random(0, 75);
int T3 = random(20, 100);
int Tavg = random(50, 100);
*/
float T1 = sensors.getTempCByIndex(0);
Serial.print("T1: ");
Serial.print(T1);
Serial.print("*C ");
lcd.setCursor(0,1);
lcd.print("T1: ");
lcd.print(T1);
lcd.write(223);
lcd.print ("C");
float T2 = sensors.getTempCByIndex(1);
Serial.print("T2: ");
Serial.print(T2);
Serial.print("*C ");
lcd.setCursor(0,2);
lcd.print("T2: ");
lcd.print(T2);
lcd.write(223);
lcd.print ("C");
float T3 = sensors.getTempCByIndex(2);
Serial.print("T3: ");
Serial.print(T3);
Serial.print("*C ");
lcd.setCursor(0,3);
lcd.print("T3: ");
lcd.print(T3);
lcd.write(223);
lcd.print ("C");
Tavg = ((T1 + T2 + T3) / 3);
Serial.print("Temp avg: ");
Serial.print(Tavg);
Serial.print("*C ");
/*
here we set fields for our channels
*/
ThingSpeak.setField(1, T1);
ThingSpeak.setField(2, T2);
ThingSpeak.setField(3, T3);
ThingSpeak.setField(4, Tavg);
/*
here we will write data to each field
delay of 20Sec in each writeField is necessary due to write limition of thing-speak free account
*/
ThingSpeak.writeFields(1, myWriteAPIKey);
delay(20000);
ThingSpeak.writeFields(2, myWriteAPIKey);
delay(20000);
ThingSpeak.writeFields(3, myWriteAPIKey);
delay(20000);
ThingSpeak.writeFields(4, myWriteAPIKey);
delay(2000);
}
there is no error reflected in the serial monitor. temp sensor works fine, the lcd displays the temp, only pump issues. when you upload the code the pump relay turns on and if it is already uploaded in nodemcu relay stops ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
