I've been working with Arduino Uno for a number months, so I'm not new, but not terribly experienced, either.
I run a small water system and have been using Arduino to provide remote monitoring capabilities for system pressure, reservoir level, time, and ambient temperature.
One Arduino is programmed to output sensor data to the serial window every two seconds. A second Arduino's sole function is to turn a small air pump on and off every ten minutes to equalize pressure in the reservoir level air line. This second unit outputs to the serial monitor the times when the air pump is cycled.
Both Arduinos are connected to the same powered USB hub, which is connected to a scrap laptop. The second Arduino has an additional 9v power supply to provide adequate power to the air pump. Everything is powered through an APC battery backup typically used for desktop computers.
The problem: About once per day, on average, the Arduino with the sensors connected will lock up. Output to the serial window stops. I can close the window without problem, but I have to use the Windows Device Manager to disable the Arduino and re-enable it before it will again output to the serial monitor. The second Arduino has never, ever had this problem.
I have replaced the original Arduino with a completely new one, but same problem. I've also replaced the USB cable, and I added the battery backup in the interest of trying to smooth out potential power issues.
The key, I think, is that failure coincides with our system's pressure pump shutting off. The last entry in the serial monitor always shows the system at its peak pressure. It will run fine for hours, up to a day or so, so it doesn't fail every time the pump shuts off. I assume this is a power problem, but I'm a little perplexed that the second unit has never had this issue.
If anyone has experienced something similar or if you have suggestions, that's what I'm here for and your help would be appreciated!
Running code below.
/*
Water System Pressure Sensor
script assembled by me on April 10, 2015
script last changed by me on July 29, 2015
assumption is that the system pressure will never go above 100 psi
0-100 PSI sensor purchased from eBay: http://www.ebay.com/itm/261260635816
Output: 0.5V – 4.5V linear voltage output. 0 psi outputs 0.5V, 50 psi outputs 2.5V, 100 psi outputs 4.5V
Pin 1 (notched) Vout, Pin 2 Ground, Pin 3 Vcc
*/
/*
This example demonstrates how to read time, date, and other information
from the DS3232 realtime clock chip.
This example is placed into the public domain.
*/
#include <SoftI2C.h>
#include <DS3232RTC.h>
SoftI2C i2c(A4, A5);
DS3232RTC rtc(i2c);
const char *days[] = {
"Mon, ", "Tue, ", "Wed, ", "Thu, ", "Fri, ", "Sat, ", "Sun, "
};
const char *months[] = {
" Jan ", " Feb ", " Mar ", " Apr ", " May ", " Jun ",
" Jul ", " Aug ", " Sep ", " Oct ", " Nov ", " Dec "
};
int sensorPin = A0; // select the input pin for the pressure sensor
int sensorValue; // integer variable to store the value coming from the sensor
float voltage; // float variable to store voltage from calculation
float psi; // float variable to store psi from calculation
float headFt; // float variable to store level of reservoir in feet from calculation
int sensorPin0 = A1; // select the input pin for the SYSTEM pressure sensor
int sensorValue0; // integer variable to store the value coming from the SYSTEM sensor
float voltage0; // float variable to store SYSTEM voltage from calculation
float psi0; // float variable to store SYSTEM psi from calculation
int minSecsBetweenEmails = 600; // 10 min
long lastSend = -minSecsBetweenEmails * 1000l;
void setup() {
Serial.begin(9600); // initialize serial
}
void loop() {
long now = millis();
RTCTime time;
RTCDate date;
rtc.readTime(&time);
rtc.readDate(&date);
Serial.print("Time: ");
printDec2(time.hour);
Serial.print(':');
printDec2(time.minute);
Serial.print(':');
printDec2(time.second);
Serial.println();
Serial.print("Date: ");
Serial.print(days[RTC::dayOfWeek(&date) - 1]);
Serial.print(date.day, DEC);
Serial.print(months[date.month - 1]);
Serial.print(date.year);
Serial.println();
Serial.print("Temp: ");
int temp = rtc.readTemperature();
if (temp != RTC::NO_TEMPERATURE) {
Serial.print((temp / 4.0) * 1.8 + 32);
Serial.println(" Fahrenheit");
} else {
Serial.println("not available");
}
Serial.println();
// read from the SYSTEM sensor and do the calculations
sensorValue0 = analogRead(sensorPin0); // read the value from the sensor
voltage0 = sensorValue0 * (.004887); // maths to determine voltage based on sensorValue: sensorValue times (5v divided by 1023 bit output range equals .004887)
psi0 = ((voltage0 - .49) * 25); // maths to determine PSI based on voltage: (sensor voltage minus minimum voltage) times (100 PSI divided by 4v range)
// output to the serial monitor SYSTEM information
Serial.println("********************************************"); // display header
Serial.print("System Pressure = "); // display label
Serial.println(psi0, 1); // display psi and CR
// read from the sensor and do the calculations
sensorValue = analogRead(sensorPin); // read the value from the sensor
voltage = sensorValue * (.0049); // maths to determine voltage based on sensorValue: sensorValue times (5v divided by 1023 bit output range equals .004887)
psi = ((voltage - .16) * 1.61); // maths to determine PSI based on voltage: (sensor voltage minus minimum voltage) times (7.25 PSI divided by 4.5v range)
headFt = psi / .43; // maths to determine head feet based on psi: one foot head equals .43 psi
// output to the serial monitor and wait a sec before starting over again
// Serial.print("Sensor Value = "); // display label
// Serial.println(sensorValue); // display sensorValue and CR
// Serial.print("Voltage= "); // display label
// Serial.println(voltage, 2); // display voltage and CR
// Serial.print("PSI= "); // display label
// Serial.println(psi, 2); // display psi and CR
Serial.print("ResLvl= "); // display label
Serial.println(headFt, 1); // display reservoir level in feet and CR
Serial.println("-------------------------------------------"); // display footer
Serial.println(""); // send extra CR
Serial.println(""); // send extra CR
if ((psi0>53) && (psi0<=57))
{
if (now > (lastSend + minSecsBetweenEmails * 1000l))
{
Serial.println("Info! Under pressure: ");
Serial.println(psi0, 1);
lastSend = now;
}
}
else if ((psi0>=45) && (psi0<=53))
{
if (now > (lastSend + minSecsBetweenEmails * 500l))
{
Serial.println("Warning! Under pressure: ");
Serial.println(psi0, 1);
lastSend = now;
}
}
else if (psi0<45)
{
if (now > (lastSend + minSecsBetweenEmails * 100l))
{
Serial.println("Critical! Under pressure: ");
Serial.println(psi0, 1);
lastSend = now;
}
}
else if (psi0>=85)
{
if (now > (lastSend + minSecsBetweenEmails * 500l))
{
Serial.println("Critical! Over pressure: ");
Serial.println(psi0, 1);
lastSend = now;
}
}
// else
// {
// Serial.println("Too soon");
// }
delay(2000); // delay for two seconds to make serial output easier to read
}
void printDec2(int value)
{
Serial.print((char)('0' + (value / 10)));
Serial.print((char)('0' + (value % 10)));
}