Issues with my slider

Alright, i can post again. The site wouldnt let me post anymore because i reached the max ammount of replies. I never deleted the code i just didnt include it in the picture, its all still there. I tried running the code on my board, it displays the temp/moisture just fine, the slider controlls the LED but it doesnt turn it on or off when it reaches a specific number, its acts like a potentiometer. Other than that the code works perfectly.
:slight_smile:

Except, where it is now it doesn’t serve the purpose that it’s defined for.

What you are doing is…

  1. take a reading from your DHT11
  2. compare this reading to your set point and turn GPIO14 on or off
  3. check where the reading from the DHT11 was valid or not

Can’t you see that this data validity check belongs immediately after the bit where you take a reading??

What do you have attached to GPIO14 ?

Pete.

Also GPIO14?? I honestly had no idea wat that was, i had to look it up. I dont think i used that…
I connected my sensor to D2 it says that one is GPIO4, ground and the 5v pin.

Oh i think i see what you mean, it says that GPIO14 is the D6 pin, yea thats my LED
, im using the built in arduino LED.

I think you’ll find that on the MKR1000, the pin labelled D6 is GPIO6

Pete.

Oh i just looked up GPIO14 not knowing what it is, my bad on the picture i saw it was pin 6 on some random board and assumed its the same for all of them.

Alright, sorry for the lack of activity, i had some issues to take care of. So, um how do i fix my virtual slider acting like a potentiometer?`

#define BLYNK_PRINT SerialUSB
 
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>
#include <DHT.h>
 

char auth[] = "";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
float humidty_setpoint,h,t;
#define DHTPIN 2

#define DHTTYPE DHT11     
DHT dht(2,11);
BlynkTimer timer;
 

void sendSensor()

  
{
 
float h = dht.readHumidity();
  float t = dht.readTemperature(); 
   
   
if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;}
   
   if (h > humidty_setpoint)
{digitalWrite(6,HIGH);} 
else 
{digitalWrite(6,LOW);}
  
  
  
  Blynk.virtualWrite(V5, t);                                                                                                                                                                                                                                                                                                                                                 
  Blynk.virtualWrite(V6, h);
}
 
void setup()
{
  pinMode(14, OUTPUT);
  // Debug console
  SerialUSB.begin(9600);
 
  
 
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
 
  dht.begin();
 
  
  timer.setInterval(1000L, sendSensor);
}

BLYNK_WRITE(V1){ 
  int humidty_setpoint = param.asInt(); 
}
 
void loop()
{
  
  
  
  Blynk.run();
  
 
  timer.run();
}

code looks like this

???

You also need to re-read post #4 where I said…

and compare this to your existing BLYNK_WRITE(V1) function.

Pete.

Yeah i changed it back to humidity, i dont know whats wrong with the pin mode. I originally changed the humidity_setpoint to temp because my LED is supposed to light up when the temp gets under the desired temperature. So i thought that it wasnt working because it said humidity,

The pin issues…

To use a pin, you declare it as an input or output pin with a pinMode function, then if it’s an output pin you write to it with a digitalWrite command.

You are doing digitalWrites to pin 6, but you have no corroborating pinMode command for pin 6.
Instead, you have a pinMode command for pin 13, which you are not using.

The variable scope issue…

You are declaring a global float variable called humidity_setpoint at the top of your sketch.

You are then re-declaring a local version of humidity_setpoint as an integer within your BLYNK_WRITE(V1) function, by placing int in front of the variable name.

That int declaration isn’t in the code snippet I posted in post #4, but you’ve added it in to your code. Please, go back and re-read post #4 as understanding variable scope is one of the most important issues in C++ coding.

Pete.