Difference between revisions of "Lora Soil Moisture Sensor"

From MakerFabsWiki
Jump to: navigation, search
(Features)
Line 15: Line 15:
  
 
== Interface Function ==
 
== Interface Function ==
[[File:MakePython_A9G_2.JPG|700px]]<br>
+
[[File:Lora_Soil_2.jpg|500px]]<br>
①BAT: 3.7V Lipo battery connector<br>
+
①ANT: Lora Antenna.<br>
②CHRG: 5V power input<br>
+
②RFM95T/RFM96T/RFM5W.<br>
③Micro SD Card Holder<br>
+
③SWD: Serial Wire Debug.<br>
④Micro SIM Card Holder<br>
+
④ATMega328P.<br>
⑤A9G Module<br>
+
⑤AHT10.<br>
⑥GSM: GSM Antenna IPX Interface<br>
+
⑥J1: serial port interface.<br>
⑦GPS: GPS Antenna IPX Interface<br>
 
  
 
==Usage==
 
==Usage==
Warning: Don't operate when in power supply on (That is, don’t plug or unplug the Antenna ,SIM Cars, SD Card , in case of short-circuit that may burn the IC down.)<br>
+
This routine will use Lora Soil Moisture sensor and Lora gateway to make an Internet project that collects air temperature and soil humidity data and uploads it to the server, allowing you to learn the usage of Lora Soil and the basic use of Lora in depth.<br>
 
+
<br>
===Related instructions===
+
Step:<br>
<pre>
+
1.The Lora Soil node sends data to the gateway.<br>
AT+GPS=1   #1:Turn the GPS on, 0:Turn the GPS off
+
*Here we need to use Arduino for programming.<br>
AT+CCID   #Query SIM, unique serial number, can be used to judge whether the card is normal
+
*Connect CP2102 USB toTTL module to Lora soil moisture sensor.<br>
AT+CREG?  #Check the registration status of the network
+
*Open Arduino IDE, Board choose Arduino Pro or Pro Mini, Processor choose ATmega328p (3.3V, 8MHz), select the corresponding port.<br>
AT+CSQ   #Query signal strength, the first parameter is the signal strength value
+
[[File:Lora_Soil_3.jpg|500px]]<br>
AT+CGATT=1  #Attach to the network, if you need to access the Internet, this command is mandatory
+
*Download the program from here: [https://github.com/Makerfabs/MakePython-Lora/tree/master/Lora%20Soil%20Moisture%20Sensor/Arduino_Lora_Soil TransmitterAHT10].<br>
AT+CGDCONT=1,”IP”,”CMNET” #Set PDP parameters
+
*Open the program and click upload (you need to press the reset button during the upload process). After success, you can see the following output from the serial monitor:<br>
AT+CGACT=1,1   #Activate PDP, you can go online after activation
+
[[File:Lora_Soil_4.jpg|500px]]<br>
AT+GPSRD=N   #N is a number indicating that a NEMA message is read every N seconds
 
AT+GPSRD=0   #Stop reporting
 
AT+LOCATION=2  #Get the address information of GPS, as long as the GPS can see the satellite before returning, otherwise it will return GPS NOT FIX NOW
 
AT+CPMS="SM","SM","SM"  #Set up SMS storage unit
 
AT+CMGF=0/1 #Set the SMS format, 1 for text format reading, 0 for pud format reading
 
AT+CMGR=x #Read SMS content, x is the number of SMS
 
AT+CMGL=4/"ALL"   #View the SMS list. The reading parameter in PUD format is 4, and the reading parameter in txt format is "ALL"
 
AT+CMGD=1 #Delete the text message. If you use AT + CMGD = 1,4 then delete all SMS
 
</pre>
 
 
 
===Project_1: Shows the GPS location on OLED display===
 
Attention: To get GPS location, please ensure you are outdoor, and plug the GPS Antenna. Indoor may get the incorrect location or no location information.<br>
 
 
<br>
 
<br>
This MakePython A9G can do nothing. It needs a microcontroller like ESP32 to drive it. The following two routines are implemented by A9G with MakePython ESP32, they can be directly combined to achieve various functions.<br>
+
2. LoRa Gateway
[[File:MakePython_A9G_3.JPG|700px]]<br>
+
Here uses Micropython programming to receive and process data.<br>
You can get MakePython ESP32 from here:
+
You need to use Makepython Lora module and MakePython ESP32 module, you can get them from the link below.<br>
 
https://www.makerfabs.com/makepython-esp32.html<br>
 
https://www.makerfabs.com/makepython-esp32.html<br>
Step:<br>
+
Makepython ESP32:<br>
1. Plug in the GPS antenna<br>
+
[[File:Lora_Soil_5.jpg|500px]]<br>
2. Plug to MakePython ESP32, connect the USB to the PC.<br>
+
Makepython Lora:<br>
[[File:MakePython_A9G_4.JPG|700px]]<br>
+
[[File:Lora_Soil_6.jpg|500px]]<br>
3. Sample code, or you can get it from here: [https://github.com/Makerfabs/MakePython-A9G A9G_GPS.py]<br>
+
Assemble MakePython Lora and ESP32 to make a gateway that can receive remote data and upload it to the Internet.<br>
 +
[[File:Lora_Soil_7.jpg|500px]]<br>
 +
<br>
 +
3.Receive the data transmitted by Lora Soil Moisture sensor.<br>
 +
You download the [https://github.com/Makerfabs/MakePython-Lora/tree/master/Lora%20Soil%20Moisture%20Sensor/Micropython_Lora_Soil code] from here: code, then upload all xxx.py in the Micropython_Lora_Soil file to ESP32.<br>
 +
Open the LoRaDuplexCallback.py file, You need to make some adjustments so that your ESP32 can connect to the network and upload data to the server.<br>
 +
*Modify the API_KEY you obtained in ThingSpeak. (I will introduce how to obtain it later)<br>
 
<pre>
 
<pre>
from machine import UART,Pin,I2C
+
#https://thingspeak.com/channels/1035244
import machine
+
API_KEY='SO3W20EMSKIEJN4E'
import ssd1306
 
import utime
 
 
 
uart = UART(2, baudrate=115200, rx=16, tx=22,timeout=10)
 
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)      #Init i2c
 
lcd=ssd1306.SSD1306_I2C(128,64,i2c)         
 
 
 
A9G_RESET_PIN = Pin(33, Pin.OUT)
 
A9G_RESET_PIN.value(0)            #set pin to low
 
 
 
utime.sleep_ms(2000)
 
A9G_PWR_KEY = Pin(21, Pin.OUT)
 
A9G_PWR_KEY.value(0)
 
utime.sleep_ms(2000)
 
A9G_PWR_KEY.value(1)
 
utime.sleep_ms(20000)
 
 
 
#Display line wrap
 
p=0
 
def text(string,c=0,r=0):  
 
    global p
 
    if p>80:
 
        p=0
 
        lcd.fill(0)
 
    colum=int(len(string)/15)+2
 
    i=0
 
    for a in range(0,colum):
 
        lcd.text(string[i:i+15],c,a*8)
 
        i=i+15
 
    lcd.show()
 
 
 
if True:
 
  lcd.fill(0)
 
  uart.write('AT+GPS=1\r\n')#1: turn on GPS  0:Turn off GPS
 
  utime.sleep_ms(1000)
 
  uart.write('AT+GPSRD=10\r\n')
 
  utime.sleep_ms(1000)
 
  uart.write('AT+LOCATION=2\r\n')
 
  utime.sleep_ms(1000)
 
  while True:     
 
    if uart.any():
 
      uart.write('AT+LOCATION=2\r\n') #Get GPS address
 
      bin_data = uart.readline()
 
      print(bin_data)
 
      lcd.fill(0)
 
      text(bin_data,0,0) 
 
      lcd.show()
 
    utime.sleep_ms(2000)
 
 
</pre>
 
</pre>
4. The screen displays GPS information.<br>
+
*Modify SSID and PSW to connect WiFi.<br>
[[File:MakePython_A9G_5.JPG|700px]]<br>
 
 
 
===Project_2: Display SMS message on OLED display===
 
Please note that each text message may require some fees depending on your local GSM operator, make sure the SIM card is active, and leave enough money for this application.<br>
 
<br>
 
This example also requires MakePython ESP32.<br>
 
Step:<br>
 
1. Plug in the GSM antenna<br>
 
2. Insert a mini SIM card(GPS does work without a SIM)<br>
 
[[File:MakePython_A9G_6.JPG|700px]]<br>
 
3. Plug to MakePython ESP32, connect the USB to the PC.<br>
 
4. Sample code, or you can get it from here: [https://github.com/Makerfabs/MakePython-A9G A9G_GSM.py]<br>
 
 
<pre>
 
<pre>
from machine import UART,Pin,I2C
+
ssid = "Makerfabs"
import machine
+
pswd = "20160704"
import ssd1306
 
import utime
 
uart = UART(2, baudrate=115200, rx=16, tx=22,timeout=10)
 
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)      #Init i2c
 
lcd=ssd1306.SSD1306_I2C(128,64,i2c)         
 
A9G_RESET_PIN = Pin(33, Pin.OUT)
 
A9G_RESET_PIN.value(0)           
 
utime.sleep_ms(2000)
 
A9G_PWR_KEY = Pin(21, Pin.OUT)
 
A9G_PWR_KEY.value(0)
 
utime.sleep_ms(2000)
 
A9G_PWR_KEY.value(1)
 
utime.sleep_ms(20000)
 
p=0
 
def text(string,c=0,r=0):
 
    global p
 
    if p>80:
 
        p=0
 
        lcd.fill(0)
 
    colum=int(len(string)/15)+2
 
    i=0
 
    for a in range(0,colum):
 
        lcd.text(string[i:i+15],c,a*8)
 
        i=i+15
 
    lcd.show()
 
if True:
 
    uart.write('AT+GPS=0\r\n')#1: turn on GPS  0:Turn off GPS
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CCID\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CREG?\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CGATT=1\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CGACT=1,1\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CGDCONT=1,\"IP\",\"CMNET\"\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CSQ\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CPMS="SM","SM","SM"\r\n')
 
    utime.sleep_ms(1000)
 
    uart.write('AT+CMGF=1\r\n')
 
    utime.sleep_ms(1000)
 
    #uart.write('AT+CMGL="ALL"\r\n')
 
    #utime.sleep_ms(1000)
 
    while True:     
 
      if uart.any():
 
        lcd.fill(0)
 
        uart.write('AT+CMGR=1\r\n')
 
        utime.sleep_ms(1000)
 
        bin_data = uart.readline()
 
        print(bin_data)
 
        text(bin_data,0,0)
 
        lcd.show()
 
      utime.sleep_ms(2000)
 
 
</pre>
 
</pre>
4. The screen displays the phone number, time and information for sending SMS.<br>
+
*Open the connectWiFi.py file, here also need to modify the ssid and pswd.<br>
[[File:MakePython_A9G_7.JPG|500px]]<br>
+
[[File:Lora_Soil_8.jpg|500px]]<br>
*Mobile phone to send SMS.<br>
+
<br>
[[File:MakePython_A9G_8.JPG|700px]]<br>
+
4.Use ThingSpeak IoT<br>
*Display the phone number and time of sending SMS<br>
+
*Sign up an account in https://thingspeak.com/. If you already have one, sign in directly.<br>
[[File:MakePython_A9G_10.JPG|700px]]<br>
+
*Click New Channel to create a new ThingSpeak channel.<br>
*Show received content
+
*Input name, Description, Select Field 1 to 5. Then save channel on the bottom.<br>
 +
[[File:Lora_Soil_9.jpg|500px]]<br>
 +
*Click the API Keys option, copy the API Key, we will use it in the program.<br>
 +
[[File:Lora_Soil_10.jpg|500px]]<br>
 +
5. Result<br>
 +
Press the reset button of Makeoython ESP32, after the connection to the network is successful, the screen can display the data sent by the Lora Soil Moisture sensor module.<br>
 +
[[File:Lora_Soil_11.jpg|500px]]<br>
 +
After logging into ThingSpeak, you can see the data uploaded by ESP32 Gateway.<br>
 +
[[File:Lora_Soil_12.jpg|500px]]<br>
 +
 
  
 
== FAQ  ==
 
== FAQ  ==
Line 195: Line 81:
  
 
== Resources ==
 
== Resources ==
*[https://www.makerfabs.com/wiki/images/a/a0/Gprs_series_module_at_instruction_set_v1.0%28A9_A9G%29.pdf AT Command Set]
 

Revision as of 10:19, 27 May 2020

Introduction

The Lora soil moisture sensor is an Internet of Things (IoT) solution based on Atmel's Atmega328P MCU, Lora module and AHT10. It is a Lora terminal node that can collect air temperature and humidity, and soil humidity data and transmit it to the Lora gateway. The soil moisture sensor, the user can use the Arduino IDE for programming, is very easy, especially suitable for non-programmers.

Lora Soil 1.jpg

Features

• Classic ATMEL AVR 8-bit Atmega328P.
• RAM: 2KBytes.
• EEPROM: 1Kbytes.
• Clock Speed: 8 MHz.
• Interface: UART.
• Working Temperature: -20 ~ +85℃.
• Default baud rate: 115200bps.

Interface Function

Lora Soil 2.jpg
①ANT: Lora Antenna.
②RFM95T/RFM96T/RFM5W.
③SWD: Serial Wire Debug.
④ATMega328P.
⑤AHT10.
⑥J1: serial port interface.

Usage

This routine will use Lora Soil Moisture sensor and Lora gateway to make an Internet project that collects air temperature and soil humidity data and uploads it to the server, allowing you to learn the usage of Lora Soil and the basic use of Lora in depth.

Step:
1.The Lora Soil node sends data to the gateway.

  • Here we need to use Arduino for programming.
  • Connect CP2102 USB toTTL module to Lora soil moisture sensor.
  • Open Arduino IDE, Board choose Arduino Pro or Pro Mini, Processor choose ATmega328p (3.3V, 8MHz), select the corresponding port.

Lora Soil 3.jpg

  • Download the program from here: TransmitterAHT10.
  • Open the program and click upload (you need to press the reset button during the upload process). After success, you can see the following output from the serial monitor:

Lora Soil 4.jpg

2. LoRa Gateway Here uses Micropython programming to receive and process data.
You need to use Makepython Lora module and MakePython ESP32 module, you can get them from the link below.
https://www.makerfabs.com/makepython-esp32.html
Makepython ESP32:
Lora Soil 5.jpg
Makepython Lora:
Lora Soil 6.jpg
Assemble MakePython Lora and ESP32 to make a gateway that can receive remote data and upload it to the Internet.
Lora Soil 7.jpg

3.Receive the data transmitted by Lora Soil Moisture sensor.
You download the code from here: code, then upload all xxx.py in the Micropython_Lora_Soil file to ESP32.
Open the LoRaDuplexCallback.py file, You need to make some adjustments so that your ESP32 can connect to the network and upload data to the server.

  • Modify the API_KEY you obtained in ThingSpeak. (I will introduce how to obtain it later)
#https://thingspeak.com/channels/1035244
API_KEY='SO3W20EMSKIEJN4E'
  • Modify SSID and PSW to connect WiFi.
ssid = "Makerfabs"
pswd = "20160704"
  • Open the connectWiFi.py file, here also need to modify the ssid and pswd.

Lora Soil 8.jpg

4.Use ThingSpeak IoT

  • Sign up an account in https://thingspeak.com/. If you already have one, sign in directly.
  • Click New Channel to create a new ThingSpeak channel.
  • Input name, Description, Select Field 1 to 5. Then save channel on the bottom.

Lora Soil 9.jpg

  • Click the API Keys option, copy the API Key, we will use it in the program.

Lora Soil 10.jpg
5. Result
Press the reset button of Makeoython ESP32, after the connection to the network is successful, the screen can display the data sent by the Lora Soil Moisture sensor module.
Lora Soil 11.jpg
After logging into ThingSpeak, you can see the data uploaded by ESP32 Gateway.
Lora Soil 12.jpg


FAQ

You can list your questions here or contact with support@makerfabs.com for technology support.

Resources