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.
| 0 | 40 |
| 1 | 39.97 |
| 2 | 39.4 |
| 4 | 38.54 |
| 6 | 38.1 |
| 8 | 37.8 |
| 10 | 37.35 |
| 12 | 36.9 |
| 14 | 36.5 |
| 16 | 36.2 |
| 18 | 35.75 |
| 20 | 35.5 |
| 25 | 34.47 |
| 30 | 33.48 |
| 35 | 32.5 |
| 40 | 31.6 |
| 50 | 30.03 |
| 60 | 28.3 |
| 70 | 26.5 |
| 80 | 24.2 |
| 90 | 22.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!
:
Top Comments