Shi Hui LeeAlex Lowkxrinxx Quxk
Created October 6, 2019 © GPL3+

Falling Tree Monitor (Final Submission)

Sigfox Universities 2019 competition. To propose a Sigfox solution to prevent tree falling with IoT sensors.

IntermediateFull instructions provided14 days133
Falling Tree Monitor (Final Submission)

Things used in this project

Hardware components

5 mm LED: Red
5 mm LED: Red
×1
Arduino UNO
Arduino UNO
×1
SiPy
Pycom SiPy
×1
Solar Panel 5V 0.8A with USB Connector
×1
Xbee S1 RF Module
×1
IP65 Casing
×1
Inertial Measurement Unit (IMU) (6 deg of freedom)
Inertial Measurement Unit (IMU) (6 deg of freedom)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API
Pymakr Plugin
Pycom Pymakr Plugin
Processing
The Processing Foundation Processing
Visual Studio 2015
Microsoft Visual Studio 2015

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter
Multitool, Screwdriver
Multitool, Screwdriver
Bench Power Supply
Desoldering Tip, Tenma 21-8220 Desoldering Pump
Desoldering Tip, Tenma 21-8220 Desoldering Pump
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Custom parts and enclosures

Final BOM for Project

Schematics

Complete Circuit For Moisture Sensor Node

Complete Circuit For Moisture Sensor Node

Complete Circuit For Tree Tilting Sensor Node

Complete Circuit For Tree Tilting Sensor Node

Code

Moisture Sensor

C/C++
Moisture Sensor Arduino Code
#include "SoftwareSerial.h"


SoftwareSerial Serial1(6,7); // RX, TX

int soilMoistureValue = 0;
byte mapSoilMoistureValue=0;

#define LED1 4
void setup() {
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
  Serial1.begin(9600);
  pinMode(LED1, OUTPUT);
  blinkLED(5);
  Serial.println("Moisture Sensor Node v1.0");
  
}

void blinkLED(byte cnt)
{
  for(int i=0; i<cnt; i++)
  {
    digitalWrite(LED1,HIGH);
    delay(50);
    digitalWrite(LED1,LOW);
    delay(50);
  }
}
void loop() {
  soilMoistureValue = analogRead(A0);  //put Sensor insert into soil
  mapSoilMoistureValue=map(soilMoistureValue,0,1024,0,255);
  //Send to nodes through Xbee
  Serial1.write(0x66);
  Serial1.write(mapSoilMoistureValue);

  //Local Printout for debug
  Serial.print("Sent: ");
  Serial.println(mapSoilMoistureValue);
  blinkLED(5);
  delay(5000);
}

Tree Tilting Sensor

C/C++
Tree Tilting Sensor Arduino Code
#include "SoftwareSerial.h"


SoftwareSerial Serial1(6,7); // RX, TX


int mapSoilMoistureValue=0;
char buff[10];

#define LED1 4
void setup() {
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
  Serial1.begin(9600);
  pinMode(LED1, OUTPUT);
  blinkLED(5);
  Serial.println("Tilting Sensor Node v1.0");
}

void blinkLED(byte cnt)
{
  for(int i=0; i<cnt; i++)
  {
    digitalWrite(LED1,HIGH);
    delay(50);
    digitalWrite(LED1,LOW);
    delay(50);
  }
}
void loop() {

  while(Serial1.available()>=2)
  {
    buff[0]=Serial1.read();
    buff[1]=Serial1.read();
    if(buff[0]==0x66)
    {
      mapSoilMoistureValue=buff[1];
      Serial.print("Rec: ");
      Serial.println(mapSoilMoistureValue);
    }
  }
  
}

Thingspeak Matlab Script

C/C++
Thingspeak Matlab Script
% Read and generate alerts for Tree Falling Project


% Channel ID to read data from 
readChannelID = 000; %replace with your channel id
% Temperature Field ID 
temperatureUpperFieldID = 1; 
temperatureLowerFieldID = 2; 
X_FieldID=3;
Y_FieldID=4;
Z_FieldID=5;
Moisture_FieldID=6;


% Channel Read Private API Key 
readAPIKey = 'xxxx'; %replace with your key

% Read the latest data from channel. 
data=thingSpeakRead(readChannelID,'ReadKey',readAPIKey); 
tempH = data(1:1);
tempL = data(2:2);
X_Val =data(3:3);
Y_Val =data(4:4);
Z_Val = data(5:5);
moisture_Val = data(6:6);

% Convert to Celsius 
tempC = tempH +tempL /100; 

% Display Data 
display(tempC,'Temperature in Celsius'); 
display(X_Val,'X Value'); 
display(Y_Val,'Y Value'); 
display(Z_Val,'Z Value'); 
display(moisture_Val,'Moisture'); 

% Condition Checking. Need to modify according to existing angles.
X_Axis_default = 92 ;%degree
Y_Axis_default = 123;% degree
Z_Axis_default = 90.5; % degree

alertStatus=0;
if X_Val>X_Axis_default+20 || X_Val<X_Axis_default-20 
    alertStatus=alertStatus + 1;
end
if Y_Val>Y_Axis_default+20 || Y_Val<Y_Axis_default-20 
    alertStatus=alertStatus + 2;
end
if Z_Val>Z_Axis_default+20 || Z_Val<X_Axis_default-20
    alertStatus=alertStatus + 4;
end
if moisture_Val<50 
    alertStatus=alertStatus + 8;
end


display(alertStatus,'Alert Value'); 
% Replace the [] with channel ID to write data to: 
writeChannelID =000; %replace with your channel id
% Enter the Write API Key between the '' below: 
writeAPIKey = 'xx'; %replace with your key
temperatureWriteFieldID=1;
alertFieldID = 2; 
thingSpeakWrite(writeChannelID,'Fields',[1,2],'Values',{tempC,alertStatus} ,'WriteKey',writeAPIKey); 

Pycom SiPy Source Code

Python
Serial Slave Source Code for Pycom
from machine import UART # Tx and Rx (``P3`` and ``P4``)
from network import Sigfox
import binascii
import socket
import time
import pycom
import sys
pycom.heartbeat(False)

#init Sigfox for RCZ4 (Asia)
sigfox = Sigfox(mode=Sigfox.SIGFOX,rcz=Sigfox.RCZ4)

uart1 = UART(1, baudrate=9600)
uart1.init(9600,bits=8,parity=None, stop=1, pins = ('P3', 'P4'), timeout_chars=20)


#uart1.write('1,34,56') #serial write to uno 
while True:
    try:
        recv=uart1.readline() #
        print("Recv : %s" %(recv))
        if recv != None:
            print("Enter if.")
  
            #print Sigfox DeviceID
            print(binascii.hexlify(sigfox.id()))

            # print Sigfox PAC number 
            print(binascii.hexlify(sigfox.pac()))

            #create Sigfox socket
            sk1 = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)

            #make thesocket blocking
            sk1.setblocking(False)

            #configure as uplink only
            sk1.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)


            dataList = recv.decode("utf-8")
            if(len(dataList) > 10):
                
                print("dataList : %s" %(dataList))
                split_val = dataList.split(",")
                temp_H = int(split_val[0])
                temp_L = int(split_val[1])
                x_Val =int(split_val[2])
                y_Val =int(split_val[3])
                z_Val =int(split_val[4])
                moist_Val = int(split_val[5])
                print("temp_H : %d temp_L : %d x_Val : %d y_Val : %d z_Val : %d moist_Val : %d" % (temp_H, temp_L,x_Val,y_Val,z_Val,moist_Val)) 
                bData = [temp_H,temp_L,x_Val,y_Val,z_Val,moist_Val]
                print(bData)

                meas_temp = temp_H + (temp_L*0.01)
                print("measure temperature : %.2f" %(meas_temp))
                
              
                
                sk1.send(bytes(bData))
                uart1.write("OK")
                sk1.close()
                time.sleep(5)
               
            
            else:
                uart1.write("Error")
    except KeyboardInterrupt:
        sys.exit()  

Credits

Shi Hui Lee

Shi Hui Lee

1 project • 0 followers
Alex Low

Alex Low

1 project • 0 followers
kxrinxx Quxk

kxrinxx Quxk

1 project • 0 followers

Comments