Term 2 Project - Project report (includes revisions to Arduino code and Pi script)


Term 2 Final Project - Project "Occulus Neptunus Regis 1" a miniature "research ship" to keep an eye on your aquatic life/pets






By Luis Rubim
MA Computational Arts




Abstract


The Occulus Neptunus Regis 1, is intended to be a pond/tank camera in the format of a miniature research ship, with the camera disguised as a miniature sub. It was done using frugal materials and based around both Arduino and Raspberry Pi technology, both serving different functions.
The Arduino part deals with the drop mechanism for the camera as well as illumination when light levels drop and the Pi is the imaging unit.
There are many advantages to using the Pi as an imaging unit, one being that you can remote desktop it and keep an eye in your backyard pond pets or pond life from the comfort of your home, provided you have a local network. For testing purposes, the ship, records 5 mins of video automatically as it starts.




Introduction

This project was born out of my personal interests in imaging and aquatic animal life. I also like using household and recycled objects and materials to build things and I became very interested in playing with elements for this project and became particularly interested in wet/water level detectors to trigger things. As such, I started developing this idea and it would not go away. I understood the challenges and obstacles, in terms of work/study balance, but I took the challenge.
I enjoy creating useful objects that have a fun element to them and this project appealed to my interests and there was a sense of nostalgia to it, as I as a kid would build boats out of polystyrene boxes, by wearing down the polystyrene against a wall, and watch them sail at sea.

As such, with an idea forming in my head and bearing in mind the requirement of a minimum of two inputs and two outputs, I looked around my home for materials and looked for what I was missing and started building.



Research & Development


I would recommend that this section would be taken in consideration in context of the blog for the project, which amasses all the research and development, as well as obstacles and failures, building the ship.

The imaging system

The imaging system is based on a 5MP Raspicam module connected to a Raspberry Pi Zero, housed in black electrical/electronics project boxes, as is the Arduino part.
Research was conducted in what type of motor I would use. I ordered a continuous rotation servo and I wanted the whole project to be powered onboard by a strong splashproof battery pack. I found a 10000mah splashproof power pack for mobile phones that does its job extremely well.

The other area for development and crucial decisions was, to include or exclude a splashproof display. I have decided not to include one and rather use the Pi’s or rather Linux’s remote desktop abilities, using VNC. But for failproof testing, I modified the boot script (rc.local) for the Pi’s Raspbian operating system to shoot 5mins of footage at HD as it boots and then convert from it’s native h264 video format to a more versatile MP4 file, as below underlined in red:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enauble or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

raspivid -ex auto -awb auto -br 80 -ISO 800 -vf -o /home/pi/Desktop/underwater.h264 -t 300000
sudo MP4Box -add /home/pi/Desktop/underwater.h264 /home/pi/Desktop/underwater.mp4

exit 0

########################################################################

Looking at the modified script above, the camera is shooting native HD video 1080p at 25 frames per second, albeit with automatic exposure enabled, as well as automatic white balance, brightness set to 80 (values between 0-100, as water can get very dark), maximum sensitivity available for the camera (ISO800), vertical flip as the camera had to be installed upside down and finally the last option to write the file on the desktop followed by the duration option for the video.
It then uses a codec to encode from h264 to MP4.

All these commands run in terminal so they would not stop a remote desktop user from using the Pi.

The Arduino based water sensor/winch/LDR/LED drop mechanism

This is perhaps the most interesting part of the project.
At the core of the system is an Arduino Atmega2560, to which a Water level sensor is connected, that retracts the camera if it senses no water or drops it if it senses water. This then signals the Arduino to instruct a servo to perform this operation through an H-bridge (initially installed for a DC Motor as the H-bridge was on its way to me and was late). The H-bridge I later found was not a necessity as the servo I later received seems to have a built in one, but the code was efficient enough to work with both DC and Servos, only requiring little modification (literally exchanging two values, this is explained in the blog posts). You can simply replace one motor for the other and it will work (code below after the paragraph on LDR/LED as the code was then merged).
The H-bridge allows for the reversal of the direction of the motors and does away with the requirement of a diode.
I have used a slightly modified schematic of the “Zoetrope” from the Arduino Project book for the motor to jog my memory on H-bridge pinouts and the Light Theremin from the same book was referenced to jog my memory on how to connect a LDR.
The LDR is installed right next to the camera in its makeshift underwater housing (made of plastic Kinder eggs, silicone sealant, waterproof foam filler and later, hot glue), to detect when light levels go down as the camera goes down to light up and brighten up accordingly. The full code for the project ended up as below:


#include <Servo.h>
#define _relay 8
#define _motor 9
const int controlPin1 = 2;
const int controlPin2 = 3;
int previousState;
int motorDirection;

int ledPin1 = 11;
int ledPin2 = 12;
int LDRin = 0;


int timex = millis(); //----optional if controlling other things that require it
int timer = 0;        //----optional if controlling other things that require it

Servo _servo;


void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  previousState = 1;
  motorDirection = 1;


  _servo.attach(5);
  pinMode(_relay, INPUT);
  pinMode(_motor, OUTPUT);
  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:


  //--------------------light level sensor lights up LEDs in camera------------------------

  LDRin = (analogRead(0) / -4); // divides 1023 values by 4, to translate it to close to 255 values for LED
  analogWrite(ledPin1, LDRin);
  analogWrite(ledPin2, LDRin);

  //--------------------Camera drop in contact with water & retracts when not -------------

  if (digitalRead(_relay) == HIGH && previousState == !1) {


    Serial.print("  ON - Submerging Camera ");

    digitalWrite(controlPin1, HIGH);//--- interchange these (HIGH/LOW) if your motor does
    digitalWrite(controlPin2, LOW);//--- not have a built in H-Bridge

    _servo.attach(5);

    delay(10000);

    digitalWrite(_motor, HIGH);
    _servo.write(360);//--- line of code only relevant if you are using a servo
    delay(4500);
    digitalWrite(_motor, LOW);

    previousState = 1;



    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin2, LOW);

  }


  if (digitalRead(_relay) == LOW && previousState == 1) {

    motorDirection != 1;

    _servo.attach(5);

    Serial.print("  OFF  - Retracting Camera");
    digitalWrite(controlPin1, HIGH);
    digitalWrite(controlPin2, LOW);

    delay(10000);
    digitalWrite(_motor, HIGH);
    _servo.write(-360); //--- line of code only relevant if you are using a servo
    delay(4500);
    digitalWrite(_motor, LOW);

    //_servo.detach();

    previousState = !1;

    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin2, LOW);

  }


}

The winch mechanism was controlled by timings which required some testing and declaring motor states. There is a delay in the beginning of 10 seconds to allow for the user to drop the ship in the water, as such it is imperative that the camera is not retracted or that the winch cable is slack, when the system is switched on to prevent any damage to the system. Tehe system works well and is perhaps the part of the system that works the best, accomplishing the two input, two outputs required for the project.


Challenges

The most challenging part, even through the end of the project was the underwater housing and camera, which despite my best efforts in sealing it, it kept sustaining water ingress. But first let me point out that I was very impressed with the durability of the Raspicam module (see blog). The module sustained repeated water ingress, being fully flooded, yet it still worked even while submerged. After the first episode, I thought the module was damaged and dead but it was not, requiring simple drying and more silicone grease. It also took the housing a few times back to the drawing board, until I finally managed to get some footage out of it, although not perfect. Yet, a small gap in one of the LED holes caused further ingress and another redesign. I am, as I am writing this looking at further sealing and redesign of the housing.



Conclusion

In conclusion, it was a project which I thoroughly enjoyed making and also the most challenging as there were more factors to consider than I previously thought, from balancing elements, to the underwater elements.
In the future, I am considering adding Radio Control electronics to the project as well as an aeration device for the camera to allow for condensation and moisture to escape the housing, to increase the lifespan of the device.
It also brought me back to documenting my progress in my project via a blog allowing me to reflect back on it.
On a last note, I intend to continue to develop all my projects further and create something more challenging and more arts oriented for my final project, with my newly acquired skillset.



References

Arduino Project book


My Links for this project:


All aggregated at:

http://luiscomputes.blogspot.co.uk/




PS: More video and schematic to come

Until next project,

Luis


Comments

Popular Posts