Tonight I wired in the Arduino to the control panel and I'm happy to say that most of it worked right away. I had miswired the HC-SR04 ultrasonic sensor, but once I finished that, I started to calibrate the system. I started with calibrating the HC-SR04 as a water level sensor. I have it mounted above my reservoir and it read exactly 40cm with no water in it. I began the painstaking task of filling it 2 liters at a time and recording the distance reading I got. Then at 20L I switched to 5L at a time, and finally at 40L I went 10L at a time to speed things up. It still took forever. I ended up with the table below.

 

040
139.97
239.4
438.54
638.1
837.8
1037.35
1236.9
1436.5
1636.2
1835.75
2035.5
2534.47
3033.48
3532.5
4031.6
5030.03
6028.3
7026.5
8024.2
9022.4


From two linear trendlines of the data in this table I created two linear equations to calculate the volume of water from the distance. The code below calculates the volume.


if(distance > 35){

  volume = (distance - 39.75) / (-.2311);

  }else{

  volume = (distance - 39.087) / (-.18378);

  }


Next I calibrated the light sensors. I found that all of the sensors would read an analog value of less than 100 if they were on and over 100 if they were off. I set the value of LightOnThresh to 100, so now I get a 1 if the light on each level is on and a 0 if it is off.


After this I tested the pump on level 2. I do not have a pump set up for the first level yet, but when I do it will be run with identical code. Here I ran into a rather dumb mistake. I had declared my pump on and pump off times as integers and used 200000 as my pump off time in milliseconds. This of course is too big for an 8 digit integer and the end result was my pump would turn on and run correctly, but would turn off for only a few seconds when it should have been off for 200 seconds. Changing these to unsigned longs solved this problem.

 

Now that I have the automation working I will work on the UART interface between the EZR32WG and the Arduino so I can use the wireless development kits as my link to the webserver that will ultimately be used for a user interface.

 

I have made a video of what I have working so far. Let me know what you guys think!

: