The value of a pin controlling a relay that in turn controls a pump is set in code after some simple if/then statements. the system works and closes the relay when the pump is under the water and the photo electric sensor is submerged otherwise the pump is off. The problem is that in IOT cloud it only shows off. If I switch the logic so it is on when the pump is out of the water, it shows changes to on in the cloud but of course that is NOT what I want. I have the pump set on a 30 second delay. Could that be the problem?? Thanks
How would we know? Code?
I actually don't know who to write to. I'm happy to send along my code. I'm sooooo lost. Conrad
@constanley you can post your code here
Hello and thank you for offering help. My wife and I collect rainwater and contain it in a 350 ga tote, which is near the house. If it were to overflow it would flood the sunroom so when the water is too high, the pump run and fills a fish pond 30 feet away. An ultrasonic sensor determines height of water and a photo-electric sensor detects being submerged. If the water is near overflowing and the pump is submerged a relay is closed and the pump empties for about 30 seconds. I have been trying to make this IOT based but am struggling. As an aside, I plastic printed a diverter so if the tank's full and I expect heavy rain I can discharge it onto the lawn. I'll happily send you pics or plans if you want. It's all powered by a solar charged 12 VDC car battery. Again, thanks for any help. I just turned 67 so if I do dumb stuff that's the reason. Conrad
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/dc0997c4-b415-463f-a21c-dce594218d06
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudElectricPotential volt_my;
float newLevel;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <Wire.h> //volt_onboardl_onboardage sensor
#include <Arduino.h> //std library
#include <Simple_HCSR04.h> //ultrasonic
//int volt_onboardINT = A0; !!A0 and A2 fail on Nano33 iot
//float volt_onboard;
//Variable convention type_My means cloud vs onboard is physical pin maybe number if several exist
// example LED_MY_3 OR LED_ONBOARD_3
// math section for delay used to keep pump running
unsigned long secondsMy = 1000L; //convert millisec to long to seconds
unsigned long minutesMy = secondsMy * 60; //convert secondsMy to minutes
float multiplierMy = .5; // multiplier for partial minutes
float pumpRun = minutesMy * multiplierMy; //how long pump will run about 30 sec
//assign variables
int Liquid_level = 0; //initial photoelecric value*
int offset = 2;// set the correction offset value volt_onboardl_onboardage sensor
const int ECHO_PIN = 8; /// the pin at which the sensor echo listen is connected
const int TRIG_PIN = 7; /// the pin at which the sensor trig broadcast is connected
Simple_HCSR04 *sensor;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1000);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(6, OUTPUT); //relay off or on volt_onboard CHANGE ME
pinMode(7, OUTPUT); // ultrasonic trigger pulse
pinMode(8, INPUT); //ultrasonic echo either 0 or 1
pinMode(4, INPUT); //set photoeleectric pin 5pwm as read return 0 or 1
// pinMode(A0, INPUT);
// create sensor object
sensor = new Simple_HCSR04(ECHO_PIN, TRIG_PIN); //ultra to gauge height of water in tote
// ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, onIoTSync); // on setup sync see below
}
void loop() {
ArduinoCloud.update();
// Your code here measure level ultrasonic
unsigned long distance = sensor->measure()->cm(); //ultra cal measure funct output in cm
int newLevel_onboard; //updated val to check against
Serial.print("distance: ");
Serial.print(distance);//new add
Serial.print('\n');
//volt section
//sensorValue = analogRead(analogInPin);
int volt_onboardINT = analogRead(A6);// read the input DONT USE A0 OR A2
//double voltage = map(volt,0, 4096, 0, 1650) + voltage_offset; //from https:forum.arduino.cc
float volt_onboard = map(volt_onboardINT, 0, 1023, 0, 1650) + offset; //for 3.3 nano change to 1650 is 5*3.3
// float volt_onboard = map (volt_onboardINT, 0, 1023, 0, 2500) + offset; // map 0-1023 to 0-2500 and add correction offset mega
Serial.print("volt_onboardINT: ");
//lcd.clear(); //clear display
Serial.print(volt_onboardINT);
volt_onboard /= 100; // divide by 100 to get the decimal values REM =
Serial.print('\n');
Serial.print("volt_onboard: ");
//lcd.print("volt_onboard: "); used on Mega 2560 old
Serial.print(volt_onboard);//print the volt_onboardl_onboardge
Serial.print('\n'); //newline added now
//Serial.print(volt_onboard * 2);
//lcd.print(volt_onboard);
// Serial.println("V");
delay(1000); //check volt_onboard seconds
Serial.print('\n'); //newline added now
//Serial.print("photoLiquid_level: "); //prints sensor value
//Serial.print(Liquid_level, DEC);
Serial.print('\n');
volt_my = volt_onboard; //update cloud variable works well
//newline
//end volt_onboard
Liquid_level = digitalRead(4); //photo 0 or 1 contact sensor
newLevel = distance;
if (distance <= 30 && distance != newLevel_onboard && Liquid_level == 0) //safe level and not overfull
{
// lcd.setCursor (0, 1); // go to start of 2nd line
// lcd.print("SafeDepth cm ");
// lcd.print(distance);
Serial.print('\n'); //newline
Serial.print("safe cm: ");
Serial.print(distance);
Serial.print('\n'); //newline
digitalWrite(6, LOW); //swap high and low
newLevel_onboard = distance;
Serial.print('\n'); //newline
Serial.print('\n'); //newline
Serial.print(" status: ");
// Serial.print(pump_status_onboard);
Serial.print(" status_my: ");//declare cloud pump status off
Serial.print('\n'); //newline
}
else if (distance <= 30 && distance != newLevel_onboard && Liquid_level == 1) //dump close relay and run pump
{
Serial.print('\n'); //newline
Serial.print(" dump: ");
Serial.print('\n'); //newline
Serial.print(distance);
Serial.print('\n'); //newline
digitalWrite(6, HIGH); //swap high and low
Serial.print('\n'); //newline
Serial.print("status"); //
//Serial.print(pump_status_onboard);
Serial.print('\n'); //newline
Serial.print("status_my: ");
Serial.print('\n'); //newline
//declare cloud pump status off
// lcd.setCursor (0, 1); // go to start of 2nd line
// lcd.print("Dumping cm ");
// lcd.print(distance);
delay(pumpRun); //pumping time in milli moved to seperae call below
//long unsigned int millis(40000);
newLevel_onboard = distance;
// this works pumping for 30 seconds BUT phone doesn't show the change. You can't tell
// if pump is running. If I get this going I'll make a push button with the same idea so
// my wife can water her garden using her phone
}
else if (distance > 30) //disable pump if it's alllllllllmost out of the water
{
Serial.print(" cm disabled");
Serial.print('\n'); //newline new added
digitalWrite(6, LOW); //swap high and low
// lcd.setCursor (0, 1); // go to start of 2nd line
// lcd.print("Disabled Cm: "); // from old mega 2560 routine
/// lcd.print(distance);
newLevel_onboard = distance;
}
}
I posted my code, even formatted it correctly
Please note: message attached
Return-Path: incoming+verp-7eacc4a532890c7822725e55d9eae377@arduino.discoursemail.com
Received: from mx03.vgs.untd.com (mx03.vgs.untd.com [10.181.44.33])
by maildeliver04.dca.untd.com with SMTP id AABUH7YYYATEYVAA
for constanley@juno.com (sender incoming+verp-7eacc4a532890c7822725e55d9eae377@arduino.discoursemail.com);
Tue, 6 Jun 2023 00:05:58 -0700 (PDT)
Authentication-Results: mx03.vgs.untd.com; DKIM=PASS
Received-SPF: Pass
Received: from mx-out-01a.dub1.discourse.cloud (mx-out-01a.dub1.discourse.cloud [184.104.178.57])
by mx03.vgs.untd.com with SMTP id AABUH7YYXASGLLYJ
for constanley@juno.com (sender incoming+verp-7eacc4a532890c7822725e55d9eae377@arduino.discoursemail.com);
Tue, 6 Jun 2023 00:05:57 -0700 (PDT)
Received: from localhost.localdomain (unknown [IPv6:2602:fd3f:1:102:0:242:ac11:10])
by mx-out-01a.dub1.discourse.cloud (Postfix) with ESMTP id D9D8520612
for constanley@juno.com; Tue, 6 Jun 2023 07:05:51 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=discoursemail.com;
s=dub1; t=1686035151;
bh=CtgKvW+dLaRCQZeOUyabYRud/2fHVZh4h+U9Q79z29Y=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:
List-Unsubscribe:List-ID:List-Archive;
b=tAMSvQ1sCpT9dCtPgatvUJIur5MRNC/0oiKg/gqRGRseRIUjgZUv4DgLleAJcBfZB
TAoo6xpnQohaf0pLPTsdc/O34yNxBb3PV0hQzDwB/4k1JQLly0+a6D/6dsR5Ge/6fg
nIXSLx2qUeFe+JJoRTuep7PIkntVUi3yT1K19QEGjeGNAcLcUI0+l+lj59vumnKmjH
WwKQb/HWgl/zRsQou5bLR06v2HCEKLp5E/SQAG26qzOlZGpI7Uq0VcovVhGCNLBMeC
CM+QsVI5QUdtXW6W11OKf4sLs+A+GSlBVMWFTPvwpb5n8t4mz8lFtH0agWlnA1Dboh
D+qLSlo/x4xhA==
Hi @constanley from the code is not clear to me which is the pin and cloud variable controlling the pump.
It is not recommended to use delay() in your loop. delay() is a blocking function and completely stops the execution of your sketch. I suggest you to substitute your blocking delay function with something like this:
Hello pennam
Thank you for writing. The pump variable is not controlled from the cloud but internal sensors and if/then statements tell it to pump. I can see the water height and voltage in the cloud but I cannot see the status of the pump, i.e. - is it pumping or off. Maybe there isn't a way to see it's status but it would be nice. Thanks so much!!
If I can figure out a timer function using that library I'll do that and am working on learning it on a different Nano 33 IOT. On the Mega it worked perfectly pausing while letting the pump run and maybe that's why I cannot see it. Again, thanks so much.
Conrad
Hello pennam
Thank you for writing. The pump variable is not controlled from the cloud but internal sensors and if/then statements tell it to pump. I can see the water height and voltage in the cloud but I cannot see the status of the pump, i.e. - is it pumping or off. Maybe there isn't a way to see it's status but it would be nice. Thanks so much!!
If I can figure out a timer function using that library I'll do that and am working on learning it on a different Nano 33 IOT. On the Mega it worked perfectly pausing while letting the pump run and maybe that's why I cannot see it. Again, thanks so much.
Conrad
Please note: message attached
Return-Path: incoming+verp-355598836208ced66998ee0556952097@arduino.discoursemail.com
Received: from mx04.vgs.untd.com (mx04.vgs.untd.com [10.181.44.34])
by maildeliver10.dca.untd.com with SMTP id AABUJC8ZPANLMRH2
for constanley@juno.com (sender incoming+verp-355598836208ced66998ee0556952097@arduino.discoursemail.com);
Wed, 7 Jun 2023 23:53:33 -0700 (PDT)
Authentication-Results: mx04.vgs.untd.com; DKIM=PASS
Received-SPF: Pass
Received: from mx-out-01b.dub1.discourse.cloud (mx-out-01b.dub1.discourse.cloud [184.104.202.122])
by mx04.vgs.untd.com with SMTP id AABUJC8ZNAWYFA4S
for constanley@juno.com (sender incoming+verp-355598836208ced66998ee0556952097@arduino.discoursemail.com);
Wed, 7 Jun 2023 23:53:32 -0700 (PDT)
Received: from localhost.localdomain (unknown [IPv6:2602:fd3f:1:102:0:242:ac11:10])
by mx-out-01b.dub1.discourse.cloud (Postfix) with ESMTP id 7710C813B3
for constanley@juno.com; Thu, 8 Jun 2023 06:53:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=discoursemail.com;
s=dub1; t=1686207207;
bh=Mk7XaF8+Lj0bbHoUl3XkxRXsev4Y6xaxKcdCemoXJqA=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:
List-Unsubscribe:List-ID:List-Archive;
b=KCsDjB+I1cBvJGN7C6NN28laLaGZOa6IHr9PbEvzQOVpajhWDp9WiweY6QfF8rdZZ
sp1WYrNf6TzgH4P/la/CUlFBFtqlTV9QjN1x8XUMHLgcjZEeCfR0Rx9+dWzO8haDS0
udaLX17t3EBVXLVa/kymzyB4/5lkxEymIDZ9+qpQMDtrmqm6nbEcx3Dv1eZoPv5vJ7
XGtLgBQRSFGGJNgEC1JOLAGZ8WA6VSXRTF3cm6wJJlgrrUM36xZ0RZgZVygVeS6Rxd
/7JcoDezJIICXvyCsm1sP5AJwhT/cFy5BPi0YjP6BFmcykuntD/PIC0X12pNFIk1aH
Bv3/wvb6UciWg==
Hi, you need to assign new cloud bool variable to represent the state of the pump. For example, if pin 6 is HIGH, pumpIsOn = true and if pin 6 is LOW, pumpIsOn = false;
Thanks but I already did that several times trying both read only and R/W no luck. It works as false correctly but never sees true. I called separate functions and tried replacing delay with timer but I am struggling to learn that library now. If I change the 3rd if to something I don't really want to happen such as pump is out of water so set pump_status to true, then that works but that's not a solution. I am baffled. You have no idea how nice it is to have some help so THANK YOU a lot!!
Hello And I replied thru Arduino site
Please note: message attached
Return-Path: incoming+verp-c77197f202fe169467a9ce245548744e@arduino.discoursemail.com
Received: from mx06.vgs.untd.com (mx06.vgs.untd.com [10.181.44.36])
by maildeliver08.dca.untd.com with SMTP id AABUJD2XMAREDPU2
for constanley@juno.com (sender incoming+verp-c77197f202fe169467a9ce245548744e@arduino.discoursemail.com);
Thu, 8 Jun 2023 07:16:11 -0700 (PDT)
Authentication-Results: mx06.vgs.untd.com; DKIM=PASS
Received-SPF: Pass
Received: from mx-out-01a.dub1.discourse.cloud (mx-out-01a.dub1.discourse.cloud [184.104.202.121])
by mx06.vgs.untd.com with SMTP id AABUJD2XLA4V62ZJ
for constanley@juno.com (sender incoming+verp-c77197f202fe169467a9ce245548744e@arduino.discoursemail.com);
Thu, 8 Jun 2023 07:16:10 -0700 (PDT)
Received: from localhost.localdomain (unknown [IPv6:2602:fd3f:1:109:0:242:ac11:f])
by mx-out-01a.dub1.discourse.cloud (Postfix) with ESMTP id 950F7211CD
for constanley@juno.com; Thu, 8 Jun 2023 14:16:05 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=discoursemail.com;
s=dub1; t=1686233765;
bh=wgCMQEia9bJtUfQImbIx7XcuIpp499v428Keui7ow9c=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:
List-Unsubscribe:List-ID:List-Archive;
b=5Amg8xu2rfF8UREX/sAMCVMEIHIvJMIADFl7l9d2YJguQa729aLo5Et9LtBPkMZUV
ctMKeybGCQaW+TY+Vir5+gE79+yvsXsq67LFAtdMKongvJVYFmV8470uDD3deqSNSB
KyUX2Mw5l1UcmL4Fg4YOH/3vtCCyL9BVw439OmiIDXW+z0+7IGqYb5ezR/9oKhtFWu
m0Sqh8u0vVoS1AmdSG+sYIzAODaBmIvAIQruJuOnaPWzB06Afs+bdXG1Wi1gEwEto8
CTQ0/kWeHu5XLhfNaRQiGUKncsQxhpmQOmNGM2uFor1EokIvtTct1JO/gL/HOGbiez
jGWYhElConlaQ==
Well, then something is wrong with your code and if you want someone to jump in and help you, you have to post the code, thingPropeties.h included.
Btw, I don`t understand what is that massage you attached and how it could be helpful?
Cloud bool variable should be read only.
If the Arduino Iot Cloud library is properly generating the thingProperties.h
It should not be a problem.
You can’t edit that file.
Huh? Perhaps IR detector? Water only degrades visible light with higher frequencies penetrating most. If you make a float that lies flat on ground but stands up afloat, can a wire with a weighted end inside be used as a switch? Which way is up?
I'm not sure what that gobltyGook is, all I wrote was I replied thru Arduino. It kind of works always telling me false, the pump is off. It just never tells me it is running. Confused and thanks
Everything works except it won't tell me when the pump is running just when it's not. So confused. It correctly displays voltage and water depth using these:
HiLetgo 5pcs Voltage Detection Module DC 0~25V Voltage Sensor for Arduino
2Pcs JSN-SR04T Integrated Ultrasonic Distance Measuring Sensor Transducer Module Waterproof
CQRobot Ocean: Contact Water/Liquid Level Sensor Compatible with Raspberry Pi/Arduino.
and after having two false positives I installed a float switch
Float Switch for Sump Pump - 10-Foot Water Level Sensor with Honeywell Microswitch and Adjustable Tether Length for Ground Water Bilge Pump and Water Tank
I've moved the variable to the beginning of the if submerged and if water deep enough then code statement but doesn't work. I'll try again but it is baffling. Thanks for helping
Conrad
If all you do is test the sensor(s), do they reliably say if there is water depth or not?
It is very important to eliminate hardware problems before digging into the code for bugs because if the error is in hardware then trying to fix that only results in writing bugs to fix what isn't broke. Been there, got paid after the computer (theirs) HD turned out to have an error that only occurred after a nice warm up. But until then, I was the bad guy.
Just in case all those sensors you bought don't work (to me. 0.1% chance);
A number of people use sound reflected from above.
If you keep the bare ends clean, plain water will conduct current between them.
If you hand a tube with a string and upright sensor if will sense upright until water reaches it and it floats flat.
The sensors work properly telling me depth and if water has contacted the photoelectric contact sensor. It dumps, using delay that I can vary, for a specified length of time. It all works and protects our home from flooding while also storing water for the garden. The only thing wrong is that I cannot tell when the pump is running. I plan to try again to add an variable in cloud as read only and checked periodically but it is baffling. Thanks for the help.