Dana Mah
Created July 22, 2017 © GPL3+

Buoy

This is a buoy to take reading and display them back to a user.

IntermediateFull instructions provided2 hours142
Buoy

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
GPS receiver (generic)
×1
JSN-SR04T Waterproof
×1
Temperature Sensor
Temperature Sensor
×1
Photo resistor
Photo resistor
×1
3.6V 0.5W Zener Diode
3.6V 0.5W Zener Diode
×1
Resistor 1k ohm
Resistor 1k ohm
×1
SparkFun Serial Enabled LCD Kit
SparkFun Serial Enabled LCD Kit
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Fritzing Diagram

Schematic

Here is a basic schematic. The part numbers are not correct because I used what was available in fritzing.org

Code

Arduino Sensor Code

Arduino
This code will initialise the sensors.

In the loop function, it will poll each of the connected sensors and display the data to the LCD.
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <ParallaxLCD.h>
#include <TinyGPS++.h>

ParallaxLCD lcd(9,2,16);

//Temperature variables
int sensePin = A1;  //This is the Arduino Pin that will control Relay #1
int sensorInput;    //The variable we will use to store the sensor input
double temp;        //The variable we will use to store temperature in degrees. 

//Ultrasonic
#define trigPin 8
#define echoPin 7

//GPS
#define GPSRxPin 6
#define GPSTxPin 5
static const uint32_t GPSBaud = 9600;                   // gps baud rate, the module I have use 9600
SoftwareSerial SerialGPS(GPSRxPin, GPSTxPin);         // The serial connection to the GPS device
TinyGPSPlus gps;

const int chipSelect = 10; 

struct DATA {
  String date;
  String time;
  String lat;
  String lng;
  int light;
  float temperature;
  int distance;  
};
DATA sData;

void setup() {
  lcd.setup();
  delay(1000);
  lcd.on();
  lcd.backLightOn();
  lcd.at(0,0,"Initialize");
  delay(2000);
  SerialGPS.begin(GPSBaud);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  if (!SD.begin(chipSelect)) {
    // don't do anything more:
    return;
  }
}

void loop() {
  updateLocation();
  sData.date=String(gps.date.year()) + F("/") + String(gps.date.month()) + F("/") + String(gps.date.day());
  sData.time=String(gps.time.hour()) + F(":") + String(gps.time.minute()) + F(":") + String(gps.time.second());
  sData.lat=String(gps.location.lat(),6);
  sData.lng=String(gps.location.lng(),6);
  lcd.empty();
  lcd.at(0,0,"DATE: " );
  lcd.at(0,6,String(gps.date.year()) + F("/") + String(gps.date.month()) + F("/") + String(gps.date.day()));
  lcd.at(1,0,"TIME: " );
  lcd.at(1,6,String(gps.time.hour()) + F(":") + String(gps.time.minute()) + F(":") + String(gps.time.second()));
  delay(2000); 
  lcd.empty();
  lcd.at(0,0,"LAT: ");
  lcd.at(0,6,String(gps.location.lat(),6));
  lcd.at(1,0,"LNG: ");
  lcd.at(1,6,String(gps.location.lng(),6));
  delay(2000);

  //Light
  int photocellReading = analogRead(0); 
  sData.light= photocellReading;
  lcd.empty();
  lcd.at(0,0,"Light: ");
  lcd.at(0,7,photocellReading);
  delay(2000);

  //Temperature
  sensorInput = analogRead(A1);        //read the analog sensor and store it = 
  sData.temperature = (float)sensorInput/10;
  lcd.empty();
  lcd.at(0,0,"Temp: ");
  lcd.at(0,6,String((float)sensorInput/10));
  delay(2000);

  //Distance
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  sData.distance = distance;
  lcd.empty();
  lcd.at(0,0,"Distance: ");
  lcd.at(0,10,distance);
  delay(2000);

  saveData();  
}

void updateLocation(){
  while(!gps.location.isUpdated()||!gps.time.isUpdated()){ 
    while (SerialGPS.available() > 0) {
        char c = SerialGPS.read();
        gps.encode(c);
    }
  }  
}

void saveData(){
  File dataFile = SD.open("data.txt", FILE_WRITE);
  // if the file is available, write to it:
  if (dataFile) { 
    dataFile.print(sData.date);
    dataFile.print(",");
    dataFile.print(sData.time + "GMT");
    dataFile.print(",");
    dataFile.print(sData.lat);
    dataFile.print(",");
    dataFile.print(sData.lng);
    dataFile.print(",");
    dataFile.print(sData.light);
    dataFile.print(",");
    dataFile.print(sData.temperature);
    dataFile.print(",");
    dataFile.print(sData.distance);
    dataFile.println("");
  }       
  dataFile.close();
}

Credits

Dana Mah

Dana Mah

12 projects • 27 followers
I'm a hobbyist interested in microcontroller solutions to simple problems.

Comments