Lora Soil Moisture Sensor

From MakerFabsWiki
Revision as of 10:00, 27 May 2020 by Hefang (talk | contribs) (Features)

Jump to: navigation, search

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

MakePython A9G 2.JPG
①BAT: 3.7V Lipo battery connector
②CHRG: 5V power input
③Micro SD Card Holder
④Micro SIM Card Holder
⑤A9G Module
⑥GSM: GSM Antenna IPX Interface
⑦GPS: GPS Antenna IPX Interface

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.)

Related instructions

AT+GPS=1   #1:Turn the GPS on, 0:Turn the GPS off
AT+CCID	   #Query SIM, unique serial number, can be used to judge whether the card is normal
AT+CREG?   #Check the registration status of the network
AT+CSQ	   #Query signal strength, the first parameter is the signal strength value
AT+CGATT=1  #Attach to the network, if you need to access the Internet, this command is mandatory
AT+CGDCONT=1,”IP”,”CMNET”	#Set PDP parameters
AT+CGACT=1,1	  #Activate PDP, you can go online after activation
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

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.

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.
MakePython A9G 3.JPG
You can get MakePython ESP32 from here: https://www.makerfabs.com/makepython-esp32.html
Step:
1. Plug in the GPS antenna
2. Plug to MakePython ESP32, connect the USB to the PC.
MakePython A9G 4.JPG
3. Sample code, or you can get it from here: A9G_GPS.py

from machine import UART,Pin,I2C
import machine
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)

4. The screen displays GPS information.
MakePython A9G 5.JPG

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.

This example also requires MakePython ESP32.
Step:
1. Plug in the GSM antenna
2. Insert a mini SIM card(GPS does work without a SIM)
MakePython A9G 6.JPG
3. Plug to MakePython ESP32, connect the USB to the PC.
4. Sample code, or you can get it from here: A9G_GSM.py

from machine import UART,Pin,I2C
import machine
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)

4. The screen displays the phone number, time and information for sending SMS.
MakePython A9G 7.JPG

  • Mobile phone to send SMS.

MakePython A9G 8.JPG

  • Display the phone number and time of sending SMS

MakePython A9G 10.JPG

  • Show received content

FAQ

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

Resources