Blynk + Arduino+ Relay+sensors

Hi,

I am working with a mini project, which requires Sensing the data from the sensor & turning on/off the relay.
I am using Ardunio serial usb to connect to blynk.

The problem I am facing is turning on the relays, i have 4 relays to turn ON/OFF, but unble to do it, it’s no responding.

But when i try it without any sensing part, it’s working fine.

Kindly help me out.

CODE:

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxx";
int LDR = 9;
int WL = 8;
int LDRState,WLState;
const int analogInPin1 = A1;
int sensorValue = 0;        // value read from the  temp
int sensorValue1 = 0;        // value read from the Hum
const int RPin1 =  2;   
const int RPin2 =  3; 
const int RPin3 =  7; 
const int RPin4 =  5;
int LEDonoff;
void setup()
{
  // Debug console
  DebugSerial.begin(9600);
  // Blynk will work through Serial
  Serial.begin(9600);
  Blynk.begin(auth, Serial);
  pinMode(LDR, INPUT);
   pinMode(WL, INPUT);
    pinMode(RPin1, OUTPUT);
  pinMode(RPin2, OUTPUT);
  pinMode(RPin3, OUTPUT);
  pinMode(RPin4, OUTPUT);
  while (Blynk.connect() == false) {
    // Wait until connected
  }
 digitalWrite(RPin1, LOW);
  digitalWrite(RPin2, LOW);
   digitalWrite(RPin3, LOW);
    digitalWrite(RPin4, LOW);
}
void loop()
{
   unsigned char value;
  unsigned int v;
  float val,hum;
   int sensorValue = analogRead(A0);
   Blynk.run();
  float volt = (sensorValue/1024.0) * 5;
  int tempC = (volt - 0.5) * 100;
  tempC= tempC+50;
  Blynk.virtualWrite(2, tempC);
    sensorValue1 = analogRead(analogInPin1);
   hum = sensorValue1;
     hum = (hum*5.0)/1024;   // voltage conversion
     hum=hum*10;
  Blynk.virtualWrite(1, hum);
  
   LDRState = digitalRead(LDR);
 LDRState = digitalRead(LDR);
 if (LDRState ==1)
 {
   Blynk.virtualWrite(0, "LOW");
 }
 else
{
   Blynk.virtualWrite(0,"HIGH");
}
   WLState = digitalRead(WL);
 if (WLState ==1)
 {
   Blynk.virtualWrite(3, "HIGH");
 }
 else
{
  Blynk.virtualWrite(3, "LOW");
}
}

I am able to read the data, but to able to send the data, i have used buttons for the same

I suggest you to search on the form, there are many examples, and made projects.

Hi aim useing this sketch for on-off from Humiditty sensor

//http://community.blynk.cc/t/blynk-wifi-humidity-level-control-with-set-point-and-hysteresis-dht22-and-relay-on-off/4341/40
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <WidgetLED.h>
#define BLYNK_PRINT Serial
char auth[] = "c7e6d0b5b6711ca56b76372ab"; 
SimpleTimer timer;
#define DHTPIN 12  //D6
#define DHTTYPE DHT22
const int relay1 =  05; //D1
int humLowTrigger;
int correctHum;
int Hys;

int state = LOW;

DHT dht(DHTPIN, DHTTYPE);
void updateHum(int param);
void updateHys(int param);
BLYNK_WRITE(V7) {
  updateHum(param.asInt());
}
BLYNK_WRITE(V8) {
  updateHys(param.asInt());
}


BLYNK_WRITE(V1)
{
  BLYNK_LOG("Got a value: %s", param.asStr());
  // You can also use:
  // int i = param.asInt() or
  // double d = param.asDouble()
  int i = param.asInt();
  if(i == 0){
    state = HIGH;
  }else if(i == 1){
    state = LOW; 
  }
  digitalWrite(relay1, state);
}


void Readdata()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(V10, h);

  Blynk.virtualWrite(V20, t);

  Blynk.virtualWrite(V25, humLowTrigger);
  if (h < 40 ) // vlhkost vyžší rele sepne
{   digitalWrite(relay1, HIGH); 
    
    } else {
  if (h > 40)  //vlhkost nižší rele vypne
   digitalWrite(relay1, LOW);
    Blynk.virtualWrite(V26, 255);
    
  }
}
void updateHum(int param) {
  humLowTrigger = param;
}
void updateHys(int param) {
  Hys = param;
}






void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "", "");
  timer.setInterval(1000, Readdata);
  dht.begin();
  pinMode(relay1, OUTPUT);
  digitalWrite(relay1, LOW);
  
}
void loop()
{   
  Blynk.run();
  timer.run();
}

were you able to assemble the code to check the lamp status with the LDR?

@Guilherme_Ferreira Please check Time/Date stamps before posting… this topic is over a year old.

If you need assistance with a project of your own, please create a new topic and supply details as instructed. Thank you