Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Luc Paquin
Published © CC BY-ND

Project #15: Environment – GPS – Mk27

Project #15: Environment – GPS – Mk27

BeginnerFull instructions provided1 hour42
Project #15: Environment – GPS – Mk27

Things used in this project

Hardware components

Elecrow Crowduino Uno - SD
×1
Elecrow Crowtail - Base Shield
×1
Elecrow Crowtail - GPS
×1
Elecrow Crowtail - RTC 2.0
×1
Elecrow Crowtail - Temperature and Humidity Sensor 2.0
×1
Elecrow Crowtail - Rotary Angle Sensor 2.0
×1
Elecrow Crowtail - Moisture Sensor 2.0
×1
Elecrow Crowtail - I2C LCD
×1
Elecrow Crowtail - LED(Green)
×1
Elecrow Crowtail - LED(Yellow)
×1
USB Battery Pack
×1
SparkFun USB Mini-B Cable - 6 Foot
SparkFun USB Mini-B Cable - 6 Foot
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Code

DL2502Mk04p.ino

Arduino
/****** Don Luc Electronics © ******
Software Version Information
Project #15: Environment – GPS – Mk27
DL2502Mk04p.ino
DL2502Mk04
1 x Crowduino Uno - SD
1 x Crowtail - Base Shield
1 x Crowtail - GPS
1 x Crowtail - RTC 2.0
1 x Crowtail - Temperature and Humidity Sensor 2.0
1 x Crowtail - Rotary Angle Sensor 2.0
1 x Crowtail - Moisture Sensor 2.0
1 x Crowtail - I2C LCD
1 x Crowtail - LED(Green)
1 x Crowtail - LED(Yellow)
1 x USB Battery Pack
1 x USB Mini-B Cable
*/

// Include the Library Code
// EEPROM library to read and write EEPROM with unique ID for unit
#include <EEPROM.h>
// Wire
#include <Wire.h>
// Liquid Crystal
#include "LiquidCrystal.h"
// Temperature and Humidity Sensor
#include "DHT.h"
// RTC (Real-Time Clock)
#include "RTClib.h"
// GPS Receiver
#include <TinyGPS++.h>
// Software Serial
#include <SoftwareSerial.h>

// GPS Receiver
static const int RXPin = 2;
// This one is unused and doesnt have a conection
static const int TXPin = 3;
// GPS Baud
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// Latitude
float TargetLat;
// Longitude
float TargetLon;
// GPS Status
String GPSSt = "";

// RTC (Real-Time Clock)
RTC_DS1307 RTC;
String dateRTC = "";
String timeRTC = "";

// Temperature and Humidity Sensor
#define DHTPIN 5
// DHT 11
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// Temperature and Humidity Sensor
float h = 0;
float t = 0;

// Potentiometer
int iPotentiometer = A1;
// Change Your Threshold Here
int Threshold = 0;
int zz = 0;

// Liquid Crystal
// Connect via i2c
LiquidCrystal lcd(0);

// Crowtail Moisture Sensor
int iSoilMoisture = A0;
int iSoilMoistureVal = 0;

// LED Yellow
int iLEDYellow = 7;

// LED Green
int iLEDGreen = 6;

// EEPROM Unique ID Information
String uid = "";

// Software Version Information
String sver = "15-27";

void loop() {

  // Crowtail Moisture Sensor
  isSoilMoisture();

  // Temperature and Humidity Sensor
  isTH();

  // RTC (Real-Time Clock)
  isRTC();

  // isGPS
  isGPS();

  // Delay 2 Second
  delay( 2000 );

  // Display Temperature and Humidity
  isDisplayTH();

  // Delay 2 Second
  delay( 2000 );

  // Display EEPROM
  isDisplayEEPROM();

  // Delay 2 Second
  delay( 2000 );

  // Display RTC
  isDisplayRTC();

  // Delay 2 Second
  delay( 2000 );

  // GPS Vector Pointer Target
  isDisplayInfo();

  // Delay 2 Second
  delay( 2000 );

}

getDisplay.ino

Arduino
// getDisplay
// Crowbits - OLED 128X64 UID
void isDisplayUID(){

  // Set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  // Cursor
  lcd.setCursor(0, 0);
  lcd.print("Don Luc Electron");
  // Cursor
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print( sver );

}
// isDisplay Green
void isDisplayG(){

  // Print a message to the LCD
  // Clear
  lcd.clear();
  // Cursor
  lcd.setCursor(0, 0);
  lcd.print("Humid Soil");
  // Cursor
  lcd.setCursor(0, 1);
  // Print a message to the LCD
  lcd.print( iSoilMoistureVal );
  
}
// isDisplay Yellow
void isDisplayY(){

  // Print a message to the LCD
  // Clear
  lcd.clear();
  // Cursor
  lcd.setCursor(0, 0);
  lcd.print("Dry Soil");
  // Cursor
  lcd.setCursor(0, 1);
  // Print a message to the LCD
  lcd.print( iSoilMoistureVal );
  
}
// Display Temperature and Humidity
void isDisplayTH(){

  // Clear
  lcd.clear();
  // Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print("H: "); 
  lcd.print(h);
  lcd.print(" %");
  // Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print("T: "); 
  lcd.print(t);
  lcd.print(" *C");
  
}
// Display EEPROM
void isDisplayEEPROM(){

  // Clear
  lcd.clear();
  // Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print("EEPROM"); 
  // Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print( uid ); 

}
// Display RTC
void isDisplayRTC(){

  // Clear
  lcd.clear();
  // Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print( dateRTC );
  // Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print( timeRTC );
  
}
// GPS Vector Pointer Target
void isDisplayInfo(){

  // Clear
  lcd.clear();
  // Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print( "Lat: " );
  lcd.print( TargetLat );
  // Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print( "Lon: " );
  lcd.print( TargetLon );
  
}

getEEPROM.ino

Arduino
// EEPROM
// isUID EEPROM Unique ID
void isUID() {
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGPS.ino

Arduino
// GPS Receiver
// isGPS
void isGPS(){

  // Receives NEMA data from GPS receiver
  // This sketch displays information every time a 
  //new sentence is correctly encoded
  while ( ss.available() > 0) {
    
    // Read
    if ( gps.encode( ss.read() ))
    {
     
       // GPS Vector Pointer Target
       displayInfo();
       
    }
    
  }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
   
     while(true);
    
  }

}
// GPS Vector Pointer Target
void displayInfo(){

  // Location
  if (gps.location.isValid())
  {
    
     // Latitude
     TargetLat = gps.location.lat();
     // Longitude
     TargetLon = gps.location.lng();
     // GPS Status 2
     GPSSt = "Yes";
    
  }
  else
  {

     // GPS Status 0
     GPSSt = "No";
    
  }

}

getRTC.ino

Arduino
// RTC (Real-Time Clock)
// Setup RTC
void isSetupRTC(){

  // RTC (Real-Time Clock)
  RTC.begin();

  // RTC Running
  if (! RTC.isrunning()) {
    
    // following line sets the RTC to the date & time
    //this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // RTC.adjust(DateTime(2014, 1, 21, 3, 0, 0))
    
  }
  
}
// RTC (Real-Time Clock)
void isRTC(){

  // RTC (Real-Time Clock)
  DateTime now = RTC.now();
  
  // Date
  dateRTC = now.year(), DEC; 
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.month(), DEC;
  dateRTC = dateRTC + "/";
  dateRTC = dateRTC + now.day(), DEC;
  
  // Time
  timeRTC = now.hour(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.minute(), DEC;
  timeRTC = timeRTC + ":";
  timeRTC = timeRTC + now.second(), DEC;

}

getSoilMoisture.ino

Arduino
// Crowtail Moisture Sensor
// Soil Moisture
void isSoilMoisture(){

  // Connect Soil Moisture Sensor to Analog 0
  // iSoilMoistureVal => 0~700 Soil Moisture
  iSoilMoistureVal = analogRead( iSoilMoisture );

  // Threshold => 200~500
  zz = analogRead( iPotentiometer );
  Threshold = map( zz, 0, 1024, 200, 500);

  // Threshold
  if (iSoilMoistureVal > Threshold) {

    // 300~700 - Humid Soil
    // LED Yellow
    digitalWrite(iLEDYellow, LOW);
    // Display Green
    isDisplayG();
    // LED Green
    digitalWrite(iLEDGreen, HIGH);
    
  }
  else {
    
    // 0-300 Dry Soil
    // LED Green
    digitalWrite(iLEDGreen, LOW);
    // Display Yellow
    isDisplayY();
    digitalWrite(iLEDYellow, HIGH);
    
  }

}

getTH.ino

Arduino
// Temperature and Humidity Sensor
void isTH(){

  // Temperature
  t = dht.readTemperature();
  // Humidity
  h = dht.readHumidity();
  
}

setup.ino

Arduino
// Setup
void setup()
{
 
  // Delay
  delay(100);
  
  // isUID EEPROM Unique ID
  isUID();
  
  // Delay
  delay(100);

  // Initialize the LED iLED Yellow
  pinMode(iLEDYellow, OUTPUT);

  // Initialize the LED LED Green
  pinMode(iLEDGreen, OUTPUT);

  // Temperature and Humidity Sensor
  dht.begin();

  // Delay
  delay(100);
  
  // Setup RTC
  isSetupRTC();
  
  // Delay
  delay(100);

  // GPS Receiver
  // Setup GPS
  ss.begin(GPSBaud);
  
  // Delay
  delay(100);

  // Display UID
  isDisplayUID();
  
  // Delay 5 Second
  delay( 5000 );

}

Credits

Luc Paquin
22 projects • 3 followers
Teacher, Instructor, E-Mentor, R&D and Consulting -Programming Language -Microcontrollers -IoT -Robotics -Machine Learning -AI -Sensors
Contact

Comments

Please log in or sign up to comment.