sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.61k stars 621 forks source link

LoRa starting failed! #594

Closed abinstanislaus closed 1 year ago

abinstanislaus commented 1 year ago

image code:

#include <Wire.h>
#include <SPI.h>
#include <LoRa.h>
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define DHTPIN 5          //pin where the dht22 is connected
DHT dht(DHTPIN, DHT22);
#define relay 7
#define ss 10
#define rst 9
#define dio0 2
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

String LoRaMessage = "";
int counter = 0;

const int AirValue = 590;   //you need to replace this value with Value_1
const int WaterValue = 300;  //you need to replace this value with Value_2
const int SensorPin = A0;
int soilMoistureValue = 0;
int soilmoisturepercent = 0;

void setup() 
{
  Serial.begin(115200);
  dht.begin();
  sensors.begin(); // Dallas temperature
  pinMode(relay, OUTPUT);

  while (!Serial);
  Serial.println("LoRa Sender");
  LoRa.setPins(ss, rst, dio0);
    if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    delay(100);
    while (1);
  }
}

void loop() 
{
  soilMoistureValue = analogRead(SensorPin);  //put Sensor insert into soil
  soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);

  if (isnan(h) || isnan(t)) 
  {
  Serial.println("Failed to read from DHT sensor!");
  return;
  }
  Serial.print("Soil Moisture Value: ");
  Serial.println(soilMoistureValue);

  Serial.print("Soil Moisture: ");
  Serial.print(soilmoisturepercent);
  Serial.println("%");

  Serial.print("Soil Temperature: ");
  Serial.print(temp);
  Serial.println("°C");

  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println("°C");

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println("%");
  Serial.println("");

  Serial.print("Sending packet: ");
  Serial.println(counter);

    if (soilmoisturepercent >= 0 && soilmoisturepercent <= 40)
  {
    Serial.println("Plants need water..., notification sent");
    digitalWrite(relay, LOW);
    Serial.println("Motor is ON");
    //WidgetLED PumpLed(V5);
    //PumpLed.on();
     }
  else if (soilmoisturepercent > 30 && soilmoisturepercent <= 100)
  {
    Serial.println("Soil Moisture level looks good...");
    digitalWrite(relay, HIGH);
    Serial.println("Motor is OFF");
    //WidgetLED PumpLed(V5);
    //PumpLed.off();
  }

  LoRaMessage = String(counter) +"/" + String(soilMoistureValue) + "&" + String(soilmoisturepercent)
                + "#" + String(temp) + "@" + String(t) + "$" + String(h);

   // send packet
  LoRa.beginPacket();
  LoRa.print(LoRaMessage);
  LoRa.endPacket();

  counter++;

  delay(1500);
}
abinstanislaus commented 1 year ago

serial monitor always says "starting lora failed". I cross checked every pins and circuits. But the error is same. What should I do?

Kongduino commented 1 year ago

Your code is unreadable. Please surround it with three backticks ``` each.

morganrallen commented 1 year ago

You haven't set up your SPI pins completely. You clock/SCK pin isn't hooked up at all and it looks like you have DIO5 (not used by this library at all) hooked to D13, the default SPI clock pin for the Nano.

Kongduino commented 1 year ago

Yeah, why is D13 connected to DIO5 and SCK not connected?

abinstanislaus commented 1 year ago

Yeah, why is D13 connected to DIO5 and SCK not connected?

So, What are the necessary changes, that I should make?

abinstanislaus commented 1 year ago

"" #include

include

include

include

include

include

define DHTPIN 5 //pin where the dht22 is connected

DHT dht(DHTPIN, DHT22);

define relay 7

define ss 10

define rst 9

define dio0 2

define ONE_WIRE_BUS 6

OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire);

String LoRaMessage = ""; int counter = 0;

const int AirValue = 590; //you need to replace this value with Value_1 const int WaterValue = 300; //you need to replace this value with Value_2 const int SensorPin = A0; int soilMoistureValue = 0; int soilmoisturepercent = 0;

void setup() { Serial.begin(115200); dht.begin(); sensors.begin(); // Dallas temperature pinMode(relay, OUTPUT);

while (!Serial); Serial.println("LoRa Sender"); LoRa.setPins(ss, rst, dio0); if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); delay(100); while (1); } }

void loop() { soilMoistureValue = analogRead(SensorPin); //put Sensor insert into soil soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100); float h = dht.readHumidity(); float t = dht.readTemperature(); sensors.requestTemperatures(); float temp = sensors.getTempCByIndex(0);

if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.print("Soil Moisture Value: "); Serial.println(soilMoistureValue);

Serial.print("Soil Moisture: "); Serial.print(soilmoisturepercent); Serial.println("%");

Serial.print("Soil Temperature: "); Serial.print(temp); Serial.println("°C");

Serial.print("Temperature: "); Serial.print(t); Serial.println("°C");

Serial.print("Humidity: "); Serial.print(h); Serial.println("%"); Serial.println("");

Serial.print("Sending packet: "); Serial.println(counter);

if (soilmoisturepercent >= 0 && soilmoisturepercent <= 40)

{ Serial.println("Plants need water..., notification sent"); digitalWrite(relay, LOW); Serial.println("Motor is ON"); //WidgetLED PumpLed(V5); //PumpLed.on(); } else if (soilmoisturepercent > 30 && soilmoisturepercent <= 100) { Serial.println("Soil Moisture level looks good..."); digitalWrite(relay, HIGH); Serial.println("Motor is OFF"); //WidgetLED PumpLed(V5); //PumpLed.off(); }

LoRaMessage = String(counter) +"/" + String(soilMoistureValue) + "&" + String(soilmoisturepercent)

  • "#" + String(temp) + "@" + String(t) + "$" + String(h);

    // send packet LoRa.beginPacket(); LoRa.print(LoRaMessage); LoRa.endPacket();

    counter++;

    delay(1500); }"""

abinstanislaus commented 1 year ago

Oh Ya! That was the problem! Thanks a lot!

abinstanislaus commented 1 year ago

Yeah, why is D13 connected to DIO5 and SCK not connected?

D13 should connect to sck and not to D105. Thanks a lot!