Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define REMOTEXY_MODE__WIFI_CLOUD
- #include <WiFi.h>
- #include <OneWire.h>
- #include <RemoteXY.h>
- #include <DallasTemperature.h>
- // RemoteXY connection settings
- #define REMOTEXY_WIFI_SSID "BS Home1"
- #define REMOTEXY_WIFI_PASSWORD "0554418546"
- #define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
- #define REMOTEXY_CLOUD_PORT 6376
- #define REMOTEXY_CLOUD_TOKEN "f41550dd4fa9c627fb644675dd7e94c7"
- #define REMOTEXY_ACCESS_PASSWORD "1234"
- #define Temprature_Sensor_PIN 4
- #define Level_Sensor_LOW__PIN 34
- #define Level_Sensor_MED__PIN 35
- #define Level_Sensor_HIGH_PIN 36
- int LOW__Level_Status = 1;// 1 = no liquid detected
- int MED__Level_Status = 1;// 1 = no liquid detected
- int HIGH_Level_Status = 1;// 1 = no liquid detected
- // GPIO where the DS18B20 is connected to
- const int oneWireBus = Temprature_Sensor_PIN;
- // Setup a oneWire instance to communicate with any OneWire devices
- OneWire oneWire(oneWireBus);
- // Pass our oneWire reference to Dallas Temperature sensor
- DallasTemperature sensors(&oneWire);
- // RemoteXY GUI configuration
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] = // 181 bytes
- { 255, 0, 0, 9, 0, 174, 0, 19, 0, 0, 0, 67, 97, 114, 32, 79, 105, 108, 32, 77,
- 111, 110, 105, 116, 111, 114, 0, 31, 1, 106, 200, 1, 1, 6, 0, 72, 35, 39, 38, 38,
- 44, 166, 140, 134, 26, 0, 0, 0, 0, 0, 0, 16, 66, 0, 0, 0, 0, 1, 0, 0,
- 200, 65, 0, 0, 16, 66, 73, 45, 108, 19, 50, 100, 128, 2, 1, 26, 0, 0, 0, 0,
- 0, 0, 200, 66, 0, 0, 0, 0, 1, 0, 0, 72, 66, 0, 0, 140, 66, 135, 0, 0,
- 140, 66, 0, 0, 180, 66, 1, 0, 0, 180, 66, 0, 0, 190, 66, 69, 246, 0, 20, 20,
- 1, 129, 23, 28, 62, 6, 64, 8, 69, 110, 103, 105, 110, 101, 32, 79, 105, 108, 32, 84,
- 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 0, 129, 34, 95, 42, 6, 64, 8, 69, 110,
- 103, 105, 110, 101, 32, 79, 105, 108, 32, 76, 101, 118, 101, 108, 0, 69, 246, 22, 20, 20,
- 1
- };
- // this structure defines all the variables and events of your control interface
- struct {
- // output variables
- int8_t circularBar_01; // from 0 to 36 // TEMP
- float linearbar_01; // from 0 to 100 // LEVEL
- int16_t sound_01; // =0 no sound, else ID of sound, =1001 for example, look sound list in app
- int16_t sound_02; // =0 no sound, else ID of sound, =1001 for example, look sound list in app
- //RemoteXY.sound_01 = 1001; //Alert ON
- //RemoteXY.sound_01 = 0; //Alert OFF
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- #pragma pack(pop)
- /////////////////////////////////////////////
- // END RemoteXY include //
- /////////////////////////////////////////////
- void setup()
- {
- //Serial.begin(9600);
- RemoteXY_Init ();
- pinMode(Level_Sensor_LOW__PIN, INPUT);
- pinMode(Level_Sensor_MED__PIN, INPUT);
- pinMode(Level_Sensor_HIGH_PIN, INPUT);
- sensors.begin();
- // TODO you setup code
- }
- void loop() {
- RemoteXY_Handler ();
- // TODO you loop code
- // use the RemoteXY structure for data transfer
- // do not call delay(), use instead RemoteXY_delay()
- // Take 50 readings and calculate average for each sensor
- long lowSum = 0;
- long medSum = 0;
- long highSum = 0;
- int numReadings = 50;
- sensors.requestTemperatures();
- float temperatureC = sensors.getTempCByIndex(0);
- RemoteXY.circularBar_01 = (int)(temperatureC);
- if ((int)temperatureC > 25) {
- RemoteXY.sound_02 = 2004; //Alert ON
- }
- else if ((int)temperatureC <= 25) {
- RemoteXY.sound_02 = 0; //Alert OFF
- }
- //Serial.print(temperatureC);
- //Serial.println("ΒΊC");
- for (int i = 0; i < numReadings; i++) {
- lowSum += analogRead(Level_Sensor_LOW__PIN);
- medSum += analogRead(Level_Sensor_MED__PIN);
- highSum += analogRead(Level_Sensor_HIGH_PIN);
- //delay(10); // Small delay between readings
- }
- // Calculate averages
- LOW__Level_Status = lowSum / numReadings;
- MED__Level_Status = medSum / numReadings;
- HIGH_Level_Status = highSum / numReadings;
- /*
- // Print the averaged values
- Serial.print(LOW__Level_Status);
- Serial.print(" | ");
- Serial.print(MED__Level_Status);
- Serial.print(" | ");
- Serial.print(HIGH_Level_Status);
- Serial.println(" | ");
- */
- if (LOW__Level_Status == 0 && MED__Level_Status == 0 && HIGH_Level_Status == 0) {
- // Serial.println("Oil Level is HIGH ---> OK");
- RemoteXY.linearbar_01 = (int)(100);
- RemoteXY.sound_01 = 0; //Alert OFF
- }
- else if (LOW__Level_Status == 0 && MED__Level_Status == 0 && HIGH_Level_Status > 10) {
- // Serial.println("Oil Level is Medium ---> Please Fill the Oil and Check For Leaks!!!");
- RemoteXY.linearbar_01 = (int)(66.66);
- RemoteXY.sound_01 = 2018; //Alert ON
- }
- else if (LOW__Level_Status == 0 && MED__Level_Status > 10 && HIGH_Level_Status > 10) {
- // Serial.println("Oil Level is LOW ---> DANGER !!! Please Fill the Oil and Check For Leaks!!!");
- RemoteXY.linearbar_01 = (int)(33.33);
- RemoteXY.sound_01 = 2019; //Alert ON
- }
- else {
- // Serial.println("Oil Level is Empty ---> DANGER !!! STOP THE CAR NOW!!!");
- RemoteXY.linearbar_01 = (int)(0);
- RemoteXY.sound_01 = 2020; //Alert ON
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment