<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — ESP8266-Ultrasonic sensors-motor relay]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1717&amp;type=atom" />
	<updated>2023-11-14T06:16:34Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=1717</id>
		<entry>
			<title type="html"><![CDATA[ESP8266-Ultrasonic sensors-motor relay]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=5251#p5251" />
			<content type="html"><![CDATA[<p>NEED HELP - Trying to get a sketch that will drive an esp8266 fed by two sensors to measure water volume and percentage in two seperate but identical tanks and turn a pump on when tank 1 gets to 10% and off at 50% and have that info displayed on my ipad running remotexy.</p><p>Copied the scrip generated by remotexy that defines the GUI and had ChatGPT write code for the reast and then tried to combine the two.</p><p>This is the code :-</p><p>#define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD<br />#include &lt;ESP8266WiFi.h&gt;<br />#include &lt;RemoteXY.h&gt;</p><p>// RemoteXY connection settings <br />#define REMOTEXY_WIFI_SSID &quot;ORBI58&quot;<br />#define REMOTEXY_WIFI_PASSWORD &quot;freshbug844&quot;<br />#define REMOTEXY_CLOUD_SERVER &quot;cloud.remotexy.com&quot;<br />#define REMOTEXY_CLOUD_PORT 6376<br />#define REMOTEXY_CLOUD_TOKEN &quot;a14581acb38dab3e7980fa05c36281a5&quot;</p><br /><br /><p>// RemoteXY configurate&nbsp; <br />#pragma pack(push, 1)<br />uint8_t RemoteXY_CONF[] =&nbsp; &nbsp;// 69 bytes<br />&nbsp; { 255,0,0,24,0,62,0,16,160,0,66,1,17,6,32,49,4,26,66,1,<br />&nbsp; 50,6,32,49,94,26,67,5,22,55,22,6,16,26,11,67,5,53,55,26,<br />&nbsp; 6,16,26,11,129,0,57,1,17,5,16,72,79,85,83,69,0,129,0,26,<br />&nbsp; 1,13,5,16,66,79,82,69,0 };<br />&nbsp; <br />// this structure defines all the variables and events of your control interface <br />struct {</p><p>&nbsp; &nbsp; // output variables<br />&nbsp; int8_t volumeTank1; // =0..100 level position <br />&nbsp; int8_t volumeTank2; // =0..100 level position <br />&nbsp; char percentTank1[11];&nbsp; // string UTF8 end zero <br />&nbsp; char percentTank2[11];&nbsp; // string UTF8 end zero </p><p>&nbsp; &nbsp; // other variable<br /> // uint8_t connect_flag;&nbsp; // =1 if wire connected, else =0 </p><p>} RemoteXY;<br />#pragma pack(pop)<br />#define PIN_RELAY D1<br />#define TANK_HEIGHT 2.75 // in meters<br />#define TANK_RADIUS 1.89 // in meters (diameter 3.78m / 2)<br />#define SENSOR_HEIGHT 0.5 // in meters<br />#define TANK_VOLUME (PI * pow(TANK_RADIUS, 2) * (TANK_HEIGHT -SENSOR_HEIGHT)) // in cubic meters<br />#define TRIG_PIN_TANK1 D2<br />#define ECHO_PIN_TANK1 D3<br />#define TRIG_PIN_TANK2 D4<br />#define ECHO_PIN_TANK2 D5</p><br /><p>void setup() {<br />&nbsp; RemoteXY_Init (); </p><p>&nbsp; pinMode(PIN_RELAY, OUTPUT);<br />&nbsp; pinMode(TRIG_PIN_TANK1, OUTPUT);<br />&nbsp; pinMode(ECHO_PIN_TANK1, INPUT);<br />&nbsp; pinMode(TRIG_PIN_TANK2, OUTPUT);<br />&nbsp; pinMode(ECHO_PIN_TANK2, INPUT);<br />}</p><p>void loop() {<br />&nbsp; &nbsp;RemoteXY_Handler ();</p><p>&nbsp; float measureLevel1(int TRIG_PIN_TANK1, int ECHO_PIN_TANK1);<br />&nbsp; digitalWrite(TRIG_PIN_TANK1, LOW);<br />&nbsp; delayMicroseconds(2);<br />&nbsp; digitalWrite(TRIG_PIN_TANK1, HIGH);<br />&nbsp; delayMicroseconds(10);<br />&nbsp; digitalWrite(TRIG_PIN_TANK1, LOW);</p><p>&nbsp; float duration1 = pulseIn(ECHO_PIN_TANK1, HIGH);<br />&nbsp; float distance1 = (duration1 * 0.0343) / 2; // calculate distance based on speed of sound in air<br />&nbsp; float level = SENSOR_HEIGHT - distance1; // calculate level of water in the tank<br />&nbsp; return measureLevel1;</p><p>float measureLevel2(int TRIG_PIN_TANK2, int ECHO_PIN_TANK2);<br />&nbsp; digitalWrite(TRIG_PIN_TANK2, LOW);<br />&nbsp; delayMicroseconds(2);<br />&nbsp; digitalWrite(TRIG_PIN_TANK2, HIGH);<br />&nbsp; delayMicroseconds(10);<br />&nbsp; digitalWrite(TRIG_PIN_TANK2, LOW);</p><p>&nbsp; float duration2 = pulseIn(ECHO_PIN_TANK2, HIGH);<br />&nbsp; float distance2 = (duration2 * 0.0343) / 2; // calculate distance based on speed of sound in air<br />&nbsp; float level = SENSOR_HEIGHT - distance2; // calculate level of water in the tank<br />&nbsp; return measureLevel2;</p><p>&nbsp; float levelTank1 = measureLevel1(TRIG_PIN_TANK1, ECHO_PIN_TANK1);<br />&nbsp; float levelTank2 = measureLevel2(TRIG_PIN_TANK2, ECHO_PIN_TANK2);</p><p>&nbsp; float percentTank1 = (levelTank1 / TANK_HEIGHT) * 100;<br />&nbsp; float percentTank2 = (levelTank2 / TANK_HEIGHT) * 100;</p><p>&nbsp; float volumeTank1 = (levelTank1 / TANK_HEIGHT) * TANK_VOLUME * 1000; // in liters<br />&nbsp; float volumeTank2 = (levelTank2 / TANK_HEIGHT) * TANK_VOLUME * 1000; // in liters</p><p>&nbsp; if (percentTank1 &lt; 10) {<br />&nbsp; &nbsp; digitalWrite(PIN_RELAY, HIGH); // turn on pump<br />&nbsp; } else if (percentTank1 &gt; 50) {<br />&nbsp; &nbsp; digitalWrite(PIN_RELAY, LOW); // turn off pump<br />&nbsp; }</p><p>&nbsp; // Send data to RemoteXY<br />&nbsp; RemoteXY.levelTank1 = percentTank1;<br />&nbsp; RemoteXY.levelTank2 = percentTank2;<br />&nbsp; RemoteXY.volumeTank1 = volumeTank1;<br />&nbsp; RemoteXY.volumeTank2 = volumeTank2;<br />}</p><br /><p>But it will not compile and gives these errors:-</p><p>C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino: In function &#039;void loop()&#039;:<br />C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino:70:10: error: return-statement with a value, in function returning &#039;void&#039; [-fpermissive]<br />&nbsp; &nbsp;70 |&nbsp; &nbsp;return measureLevel1;<br />&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~~~~~~~~~~<br />C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino:81:9: error: redeclaration of &#039;float level&#039;<br />&nbsp; &nbsp;81 |&nbsp; &nbsp;float level = SENSOR_HEIGHT - distance2; // calculate level of water in the tank<br />&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~<br />C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino:69:9: note: &#039;float level&#039; previously declared here<br />&nbsp; &nbsp;69 |&nbsp; &nbsp;float level = SENSOR_HEIGHT - distance1; // calculate level of water in the tank<br />&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~<br />C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino:82:10: error: return-statement with a value, in function returning &#039;void&#039; [-fpermissive]<br />&nbsp; &nbsp;82 |&nbsp; &nbsp;return measureLevel2;<br />&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~~~~~~~~~~<br />C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino:100:12: error: &#039;struct&lt;unnamed&gt;&#039; has no member named &#039;levelTank1&#039;<br />&nbsp; 100 |&nbsp; &nbsp;RemoteXY.levelTank1 = percentTank1;<br />&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~~~~~~~<br />C:\Users\User\OneDrive\Documents\Arduino\update\sketches\WAVdemo\adc_i2v56\adc_i2v56.ino:101:12: error: &#039;struct&lt;unnamed&gt;&#039; has no member named &#039;levelTank2&#039;<br />&nbsp; 101 |&nbsp; &nbsp;RemoteXY.levelTank2 = percentTank2;<br />&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~~~~~~~</p><p>Using library ESP8266WiFi at version 1.0 in folder: C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.1\libraries\ESP8266WiFi <br />Using library RemoteXY at version 3.1.11 in folder: C:\Users\User\OneDrive\Documents\Arduino\libraries\RemoteXY <br />exit status 1</p><p>Compilation error: return-statement with a value, in function returning &#039;void&#039; [-fpermissive]</p>]]></content>
			<author>
				<name><![CDATA[waynerob11]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2585</uri>
			</author>
			<updated>2023-11-14T06:16:34Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=5251#p5251</id>
		</entry>
</feed>
