Hi
i use a arduino mkr 1010 & kemo rain-detector m152, connecting on pin 4
i want to use the sensor to control the relay1 (pin 1)
my problem is now, that relay1 is switching on high at the start, and i dont know why
my goal is, to store the value 1/high, which should compared to pin4, to write the digitalpin1 (relay1) as high (check last point in the code)
can someone help?
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPLrNGyjAuU"
#define BLYNK_DEVICE_NAME "ITSE21a"
#define RELAY1 = (V20)
#include <SPI.h>
#include <Arduino_MKRENV.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <math.h>
#include "RTClib.h"
RTC_Millis rtc;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XPCSpLcWsELvNRCeJL-dvt43-r4deHS8";
BlynkTimer timer;// this timer is required to send data from shield to blynk app in intervals
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Fitim";
char pass[] = "123456789";
int relay_1 = 1;
int val = 1;
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1) // Switch between automatic and manual mode by changing the value of virtual pin
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
digitalWrite(1,HIGH); // Set digital pin 2 HIGH
}
else
{
// execute this code if the switch widget is now OFF
digitalWrite(1,LOW); // Set digital pin 2 LOW y
}
}
BLYNK_WRITE(V20) // Executes when the value of virtual pin 1 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON // Noch zu erfüllen Switch-Button muss nach abgelauferner Zeit wieder zurückfallen
digitalWrite(1,HIGH); // Set digital pin 2 HIGH
Blynk.virtualWrite(V20,1);
delay (9000);
digitalWrite(1,LOW);
Blynk.virtualWrite(V20,0);
}
}
void setup()
{
pinMode(1, OUTPUT); // Initialise digital pin 2 as an output pin
pinMode(4, INPUT);
digitalWrite(1, LOW);
Serial.begin(9600);
// this line is very immportant which i dont know why but it didnt work without it i got it from env arduino documentation
if (!ENV.begin())
{
Serial.println("Failed to initialize MKR ENV shield!");
while (1);
}
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensor);
// following line sets the RTC to the date & time this sketch was compiled
rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop()
{
Blynk.run();
timer.run();
}
void sendSensor()
{
float h = ENV.readHumidity();
float t = ENV.readTemperature();
float lx = ENV.readIlluminance();
// rounding all vairables to 2 decimal points
char tt[16];
dtostrf(t,1,2,tt);
char hh[16];
dtostrf(h,1,2,hh);
char lxx[16];
dtostrf(lx,1,2,lxx);
if (isnan(h) || isnan(t)) {
Serial.println("Error");
return;
}
Blynk.virtualWrite(V5, hh);
Blynk.virtualWrite(V6, tt);
Blynk.virtualWrite(V7, lxx);
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
if (val == digitalRead(4))
{
digitalWrite(1,HIGH);
}
else
{
digitalWrite(1,LOW);
}
