Project tutorial
Buoy

Buoy © GPL3+

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

  • 106 views
  • 0 comments
  • 0 respects

Components and supplies

About this project

My idea was for a buoy that would take reading periodically and transmit them using a lora module. Well, things didn't work out like I planned. My lora modules were defective and some of the sensors I wanted to use requires 5v, which the Edison doesn't have. So I've modified my idea by using a Arduino 101. and removed the lora sensor. Because of this change, I've added a couple of other sensors.

The buoy now consist of an Arduino 101, serial LCD, SD card, GPS, ulrasonic sensor (for depth), temperature sensor, photo sensor.

One issues I've had to overcome was the ulrasonic sensor outputs 5v Even though the arduino 101 can handle 5v on the inputs I really wanted to keep it to 3.3v, I ended up using a 3.3v zener diode and a 1k resistor to make sure I didnt overload the input.

Another issue I had was the backlight on the lcd would shut off randomly. After some head scratching, I realized that with all the sensors, powering the circuit with the USB wasn't going to cut it. I tested hooking up a battery to the power jack and voila, the backlight stays on.

Now that the circuit stays on, I was able to get some data and store it on the sd card. Here is a sample of the data.

2017/7/26,1:33:21GMT,45.260399,-66.077724,98,22.00,20 
2017/7/26,1:33:32GMT,45.260469,-66.077772,98,21.70,20 
2017/7/26,1:33:43GMT,45.260558,-66.077821,99,21.90,20 
2017/7/26,1:33:54GMT,45.260647,-66.077909,98,21.90,20 
2017/7/26,1:34:5GMT,45.260713,-66.077951,99,22.00,20 

Future Enhancements:

  • proper formatting on the data.
  • wake up timer, to conserve power
  • add a working lora module.
  • add lithium battery
  • add a better ultrasonic sensor. even though the one I have is suppose to be waterproof, after researching it, its not supposed to be submerged in water

Code

Arduino Sensor CodeArduino
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();
}

Schematics

Fritzing Diagram
Buoy wfwvegowdz
Schematic
Here is a basic schematic. The part numbers are not correct because I used what was available in fritzing.org
Buoy schematic v3risrzpai

Comments

Add projectSign up / Login