Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ARDUINO CODE
- // include the library code:
- #include <SoftwareSerial.h>
- SoftwareSerial s(5,6);
- //Temperature sensor library
- #include <OneWire.h>
- #include <DallasTemperature.h>
- int ONE_WIRE_BUS=4;
- OneWire oneWire (ONE_WIRE_BUS);
- DallasTemperature sensors (&oneWire);
- #include <LiquidCrystal.h>
- // initialize the library by associating any needed LCD interface pin
- // with the arduino pin number it is connected to
- const int rs = 9, en = 8, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- //Moisture sensor declaration
- int moisturePin = A0; // moisture sensor
- int thresholdValue = 800;
- int relaysignal = 7; //Relay pin
- String str; //String declaration
- void setup() {
- // put your setup code here, to run once:
- s.begin(115200);
- pinMode(moisturePin,INPUT); // mositure sensor
- pinMode(relaysignal,OUTPUT); // Relay module control
- Serial.begin(115200);
- sensors.begin();
- delay(2000);
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- //lcd.print("pH:"); //PH setup disabled
- lcd.print("VL:");
- lcd.setCursor(6,0);
- lcd.print("TEMP:");
- lcd.setCursor(0,1);
- lcd.print("MOIST:");
- }
- void loop() {
- // put your main code here, to run repeatedly:
- // soil moisture sensor
- int sensorValue = analogRead(moisturePin);
- int moistureconversion = (100 -(sensorValue * 0.09766));
- Serial.println ("MOISTURE READING");
- Serial.print (sensorValue);
- Serial.println (moistureconversion);
- Serial.print("%");
- //Readings float conversion
- float C = sensors.getTempCByIndex(0);
- float F = sensors.getTempFByIndex(0);
- float M = moistureconversion;
- //Temperature readings Serial printing
- sensors.requestTemperatures ();
- Serial.println("TEMPERATURE READING");
- Serial.print("Celsius temperature: ");
- Serial.print(sensors.getTempCByIndex(0));
- Serial.print(" - Fahrenheit temperature: ");
- Serial.println (sensors.getTempFByIndex(0));
- Serial.println (" ");
- //Moisture sensor and relay statement
- if (sensorValue < thresholdValue){
- Serial.println("- Doesn't need watering");
- digitalWrite (relaysignal,LOW);
- lcd.setCursor(3,0); //Status of valve OFF
- lcd.print("OFF");
- }
- else{
- Serial.println("- Time to water your plant");
- digitalWrite (relaysignal,HIGH);
- lcd.setCursor(3,0); //Status of valve ON
- lcd.print("~ON");
- }Serial.println (" ");
- //LCD display
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(11, 0);
- lcd.print(sensors.getTempCByIndex(0));
- lcd.setCursor(6,1);
- lcd.print(moistureconversion);
- //lcd.setCursor(3,0); //position for PH readings
- //lcd.print("---");
- lcd.setCursor(9,1);
- lcd.print("%");
- str =String("coming from Ogom: ")+String("MOISTURE LEVEL: ")+String(M)+String("%")+String(" ")+String("TEMPERATURE; in Centigrade: ")+String(C)+String(" ")+String("Farenheit: ")+String(F);
- s.println(str);
- delay(1000);
- }
- NODEMCU CODE
- /*
- * EMailSender library for Arduino, esp8266 and esp32
- * Simple esp8266 Gmail with Email From name send example
- *
- * https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
- *
- */
- #include "Arduino.h"
- #include <EMailSender.h>
- #include <ESP8266WiFi.h>
- const char* ssid = "******";
- const char* password = "*******";
- uint8_t connection_state = 0;
- uint16_t reconnect_interval = 10000;
- EMailSender emailSend("sending smtp enabled mail", "smtp password", "emailfrom@gmail.com", "Soil monitoring system");
- uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
- {
- static uint16_t attempt = 0;
- Serial.print("Connecting to ");
- if(nSSID) {
- WiFi.begin(nSSID, nPassword);
- Serial.println(nSSID);
- }
- uint8_t i = 0;
- while(WiFi.status()!= WL_CONNECTED && i++ < 50)
- {
- delay(200);
- Serial.print(".");
- }
- ++attempt;
- Serial.println("");
- if(i == 51) {
- Serial.print("Connection: TIMEOUT on attempt: ");
- Serial.println(attempt);
- if(attempt % 2 == 0)
- Serial.println("Check if access point available or SSID and Password\r\n");
- return false;
- }
- Serial.println("Connection: ESTABLISHED");
- Serial.print("Got IP address: ");
- Serial.println(WiFi.localIP());
- return true;
- }
- void Awaits()
- {
- uint32_t ts = millis();
- while(!connection_state)
- {
- delay(50);
- if(millis() > (ts + reconnect_interval) && !connection_state){
- connection_state = WiFiConnect();
- ts = millis();
- }
- }
- }
- void setup()
- {
- Serial.begin(115200);
- while (!Serial) {
- }
- connection_state = WiFiConnect(ssid, password);
- if(!connection_state) // if not connected to WIFI
- Awaits(); // constantly trying to connect
- }
- void loop()
- {
- if (Serial.available()){
- // Serial.write(Serial.read());
- int s=Serial.read();
- Serial.write(s);
- }
- int s = Serial.read();
- EMailSender::EMailMessage message;
- message.subject = "Soil monitor update";
- message.message = s;
- //"Ciao come stai<br>io bene.<br>www.mischianti.org";
- EMailSender::Response resp = emailSend.send("recieving mail", message);
- Serial.println("Sending status: ");
- Serial.println(resp.status);
- Serial.println(resp.code);
- Serial.println(resp.desc);
- delay (5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement