Arduino Forum

Using Arduino => General Electronics => Topic started by: Bjerknez on Mar 29, 2020, 08:55 pm

Title: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 29, 2020, 08:55 pm
I'm going to order some photo resistors like this:

https://www.aliexpress.com/item/32760631393.html?spm=a2g0o.productlist.0.0.5b29785bvc4rVd&algo_pvid=6049f749-268c-484a-8a73-f81981e8ce73&algo_expid=6049f749-268c-484a-8a73-f81981e8ce73-0&btsid=0be3746c15855077261581456e4ab8&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

But when to choose?
5528, 5537... etc.?

My goal is to meassure light in my basement from light to dark where i need to read 4-5 states of reading between light and dark for triggering other things.

I've got an ldr module with pot meter, but this shows either on or off. (For the most) when i make it darker the value jumps from 4095 to around 100.

I use an ESP32 and Wemos Mini, but i also want it to work with 5v.

Can somebody help me to choose the right one?
Title: Re: LDR Photoresistor and resistance
Post by: jremington on Mar 29, 2020, 09:14 pm
Just about any LDR will work, with a suitable resistor load.

Quote
I've got an ldr module with pot meter, but this shows either on or off.
That may be an issue with your wiring, or your program and if so could be much improved. Post a link to the module.

Or just remove the LDR from the module and use it with a suitable resistor.

Please read "How to use this forum", post the code (using code tags) and a wiring diagram with the part values. Forum members will be happy to help you make it work properly.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 29, 2020, 09:59 pm
If any Of the LDR in tje page i linked to works... why sell different kinds?

This is the module i have:
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 29, 2020, 09:59 pm
If any Of the LDR in tje page i linked to works... why sell different kinds?

This is the module i have:
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 29, 2020, 10:01 pm
posting from ipad is pain in the ass. Cant upload picture. Upload it to morrow.
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Mar 30, 2020, 12:17 am
If you scroll down the page you linked to you will see the differences spelled out. The main difference is the "Bright Resistance" and "Dark Resistance" their sensitivity to light wavelength is the same for all of them. We are looking at photo cells which sell by the pile in bulk so really don't expect much as to a data sheet.

Quality parts include a data sheet which is detailed. When I can buy 20 of these things for about Twenty-Five cents each (USD) don't expect much. Anyway to answer your question it is the link, just scroll down the page to Product Information, Parameters. Like any part you choose based on intended application. Your guess is as good as mine as to defining "Bright Light".  :)

Ron
 

Title: Re: LDR Photoresistor and resistance
Post by: jremington on Mar 30, 2020, 12:21 am
You might as well ask why there so many kinds of screws and bolts, given that just about any of them will hold two pieces of wood together.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 09:40 am
This is the LDR sensor i use.
Title: Re: LDR Photoresistor and resistance
Post by: Grumpy_Mike on Mar 30, 2020, 10:38 am
All very well but how are you using it? What pins do you connect?
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 11:14 am
All very well but how are you using it? What pins do you connect?
Ground from LDR to Ground on ESP32. VCC from LDR to 3.3v on ESP32, and DO (Digital Output) from LDR to D34 on ESP32.

I tried an another sensor module LDR and that one worked perfect and was not "on/off". I plugged that sensor on the same output. I just changed it on breadboard without doing anything else.

But i do not know why...
Title: Re: LDR Photoresistor and resistance
Post by: Grumpy_Mike on Mar 30, 2020, 12:54 pm
Quote
DO (Digital Output) from LDR to D34 on ESP32.
So if you use a digital output you will only get a digital output, either high or low. The threshold level will be determined by the setting of the pot on board.
For an analogue output use the AO pin.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 01:00 pm
So if you use a digital output you will only get a digital output, either high or low. The threshold level will be determined by the setting of the pot on board.
For an analogue output use the AO pin.
I have tried to adjust the pot, but it does not helped me.

The other module i tried that was without pot worked fine. Something tells me that it has something to do with resistance, but i'm nor shure...
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Mar 30, 2020, 03:23 pm
I see those modules offered in a few flavors, some have 4 pins to include a DO (Digital Out) and include a pot for setting the DO Threshold, the chip is likely a comparator and the pot changes the reference. Some with 4 pind include an AO (Analog Out) so the signal level out is dependent on how much light is striking the LDR. Using a simple meter and powering the module you should be able to measure the outputs. There isn't much to these things. The three pin versions I can buy 10 on Amazon for about $12.00 USD (https://www.amazon.com/dp/B07QKJPWCG/ref=sspa_dk_detail_0?psc=1&pd_rd_i=B07QKJPWCG&pd_rd_w=x9f6s&pf_rd_p=48d372c1-f7e1-4b8b-9d02-4bd86f5158c5&pd_rd_wg=k7VVC&pf_rd_r=38PACB2N1K55DR2WR02E&pd_rd_r=24a0dbc7-02f1-4c51-bd5c-c01ab7d31a63&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExSkNJMVhUN1BHMDFLJmVuY3J5cHRlZElkPUEwNTYyMTI2MVlONUw4NExQQzRYNCZlbmNyeXB0ZWRBZElkPUEwMTEwMzUwSjdFQ0xIUTk1NzBXJndpZGdldE5hbWU9c3BfZGV0YWlsJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==). That version is a DO version. I also see the 4 pin versions for a buck or two on Ebay.

Check the unit using a meter then worry about connecting it to something. You have started this thread in a half dozen forums and left the threads hanging. This is not difficult or complex.

Ron
Title: Re: LDR Photoresistor and resistance
Post by: Grumpy_Mike on Mar 30, 2020, 03:26 pm
Quote
Something tells me that it has something to do with resistance,
Someone is telling you exactly what is happening but you are choosing to ignore them.
Have you tried using the AO connector and reading the analogue signal off that?

Quote
I have tried to adjust the pot, but it does not helped me.
How have you tried adjusting the pot? Expose it to a small amount of light, then adjust the pot until the signal flips from a big to small reading ( or the other way round ). Then that will be the threshold of light you need to trigger this DIGITAL signal.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 03:33 pm
Someone is telling you exactly what is happening but you are choosing to ignore them.
Have you tried using the AO connector and reading the analogue signal off that?
How have you tried adjusting the pot? Expose it to a small amount of light, then adjust the pot until the signal flips from a big to small reading ( or the other way round ). Then that will be the threshold of light you need to trigger this DIGITAL signal.
No, i have not tried that. I just know that my other LDR module without pot works fine. I just wonder why this is working an not the other with the pot.

Yes, i have tried that. My basement have good light (almost daylight). The monitor shows 4095 and i adjust the pot slowely. Around half way the light on the module goes low and the monitor shows around 100 or less. When i trye to really slowly adjust it uppwards again, th number jumps to 4095.

My other LDR without potmeter works just fine. Same output and same code. I just swap the module.
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Mar 30, 2020, 03:36 pm
Some of the modules have a sensitivity adjustment (trip point). These modules have a comparator perhaps Schmitt trigger built in so it saturates at a given brightness or dimness (is that a word?).  The one you need does not have this circuit and what you need to actually get a range of values.  
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 03:44 pm
Some of the modules have a sensitivity adjustment (trip point). These modules have a comparator perhaps Schmitt trigger built in so it saturates at a given brightness or dimness (is that a word?).  The one you need does not have this circuit and what you need to actually get a range of values. 
Okay. probably the best answer so far. :)

I can't see that i have done something wrong here. Other than used a wrong LDR sensor.

But, i'm not 100% sure...
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Mar 30, 2020, 04:02 pm
You started with ordering photo resistors and asked the difference in part numbers. Then no comment? Now you say you have modules. Post #2 you state this is the module I have less any link? You are all over the map and nobody knows exactly what you have. You have been told and had it explained numerous tomes in other forums how to do what you want to do and just left things hanging.

You want to measure 4 or 5 light levels then just build a simple circuit. Take a Vout and use your code. You have an analog signal. The module we ended up with is nothing close to what you started this thread with so what's it going to be?

Ron
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Mar 30, 2020, 04:13 pm
It's a simple problem.

This one gives you continuous values it's just an LDR with a voltage divider

(https://i1.wp.com/www.pulsr.me/wp-content/uploads/2018/04/BDAA100008_KY-018_LDR20Sensor20Module20Keyes20Black_1.jpg?fit=2832%2C1896)

This also gives you a signal out but it's amplified

(https://mytechtools.com.pk/wp-content/uploads/2019/05/LDR-Photoresistor-Light-Sensor-Module-For-Arduino-A.jpg)

This has a comparator circuit to output a 0v or VCC based on a threshold set by the potentiometer

(https://cdn.instructables.com/F7C/3IAR/IPTJL1DD/F7C3IARIPTJL1DD.LARGE.jpg?auto=webp&width=1024&fit=bounds)
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 06:10 pm
Thanks Wolframor :)

I think you just solved my problem. I just have the wrong LDR for my use. The other sensor i tried is not mine. Just one i barroved of a friend. But this was identical to the first module you posted picture of.

I think i have to order som of theese :)
Title: Re: LDR Photoresistor and resistance
Post by: jremington on Mar 30, 2020, 06:28 pm
You have an LDR module that works fine.

You just don't know how to use it properly, and you won't get anywhere proceeding the way you have, so far in this forum. I'm out.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 06:36 pm
Yes, it works, but nok the way i want. The problem is for me solved.

My goal is not to be a king in this forum. Actually i have learned wery much the last three month. For 4 month ago i didn't know what an arduino was.

Now, i building this:
(https://i.ibb.co/fCvW5xs/8-D3734-F8-F544-432-B-AE48-2965-B6-E8145-F.jpg) (https://ibb.co/WctXw2L)

Youtube is that platform that have given me almost all answers. Inn here i have never felt welcome.
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Mar 30, 2020, 06:42 pm
Nice work!  Looks pretty good.  I see some good techniques in there.  Have a look at larryd's posts about how to prototype... he's got some amazing ideas and you might enjoy it.  Perhaps you can demonstrate what i does?
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 06:47 pm
Thanks. I'm not a pro, but this circuits works perfectly. Just some mounting to do :)

Yes, larryd has made som awsome things :)
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 30, 2020, 07:24 pm
My english is not wery good, but i can try to explain what it does, ors what it should do :)

When its finnished this box going to control temperature in my basement and i hav connected it with blynk that shows me temperature and humidity in the basement. I also going to connect an heater with relay. An lcd screen has now been mountet in the box cover.

I have also an separate temperature warning sensor innside the box that gives a warning sound and send me notification to phone when the box gets too hot.

I will also mount a fan in the box. Most for fun. :)
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Mar 30, 2020, 10:52 pm
So if the object is temperature control how does light levels and LDR schemes figure into it?

Ron
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 31, 2020, 01:13 am
For this project i just need a ldr for the lcd to go in sleep mode when light is off. It can go days between my visits in the basement and lcd is the most power consuming unit in this project. Not for the money, but for the potensial heat innside the box.

Just remember that this project is most for fun. I startet with one thing, and ended up with many new ideas that was implentet.

But it actually works wery well and the system has runnes for several weeks now without problem :)
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Mar 31, 2020, 01:49 am
OK that makes sense but the question begged. Then all you need is a single channel of Light/No Light.

Ron
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 31, 2020, 02:04 am
OK that makes sense but the question begged. Then all you need is a single channel of Light/No Light.

Ron
Yes, to this project yes. But i have an other project also :)
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 31, 2020, 05:53 am
I found an standalone photoresistor that came with the Arduino Kit i bought for several mounth ago. It worked perfectly and now i regret bying a bounch of the LDR modules i have.

But i'm learning on my way, and i did not break the bank, so i will survey :)
Title: Re: LDR Photoresistor and resistance
Post by: Grumpy_Mike on Mar 31, 2020, 12:11 pm
Quote
But i'm learning on my way,
Given your response to my answers I would question that.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 31, 2020, 01:30 pm
Given your response to my answers I would question that.
Whatever...
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Mar 31, 2020, 01:32 pm
I found an standalone photoresistor that came with the Arduino Kit i bought for several mounth ago. It worked perfectly and now i regret bying a bounch of the LDR modules i have.

But i'm learning on my way, and i did not break the bank, so i will survey :)
It's ok I think we all have plenty of "extra" parts and modules that may be good somewhere one day... :)
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Mar 31, 2020, 02:17 pm
I found an standalone photoresistor that came with the Arduino Kit i bought for several mounth ago. It worked perfectly and now i regret bying a bounch of the LDR modules i have.

But i'm learning on my way, and i did not break the bank, so i will survey :)
Agree, you can never have too many parts.

Ron
Title: Re: LDR Photoresistor and resistance
Post by: Grumpy_Mike on Mar 31, 2020, 02:44 pm
Whatever...
The what ever means that fewer people are going to want to help you in future. ************** you
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 31, 2020, 02:52 pm
The what ever means that fewer people are going to want to help you in future. ************** you
No, that means I don't care what you think of me.

I also don't have the time or the desire to discuss with you.

But i really think your nick maybe fits you well :)
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Mar 31, 2020, 02:53 pm
It's ok I think we all have plenty of "extra" parts and modules that may be good somewhere one day... :)
Yes, some day they will be usefull.... maybe :)
Title: Re: LDR Photoresistor and resistance
Post by: TomGeorge on Apr 01, 2020, 10:49 am
Hi,
Did you google

ESP32 LDR

Tom... :)
Title: Re: LDR Photoresistor and resistance
Post by: Smajdalf on Apr 01, 2020, 03:23 pm
No, that means I don't care what you think of me.
While Grumpy_Mike is often *** he is sometimes right on simple things. Such as here. You are using your module wrong. It has two outputs: you want to use the analog one marked as AO. You are using the "wrong" one (marked as DO). If you have time look at the module again, try to find a schematic and learn how it works. It is simple but useful circuit.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Apr 01, 2020, 03:27 pm
While Grumpy_Mike is often *** he is sometimes right on simple things. Such as here. You are using your module wrong. It has two outputs: you want to use the analog one marked as AO. You are using the "wrong" one (marked as DO). If you have time look at the module again, try to find a schematic and learn how it works. It is simple but useful circuit.
No, my module has no analog pin. Image i pasted earlier is an image i found on the internet i thought was the same, but is is'nt.

So Grumpy is right, bus the sametime not.....

My fault by the way...
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Apr 01, 2020, 03:30 pm
While Grumpy_Mike is often *** he is sometimes right on simple
:D

I wanna know what *** means
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Apr 01, 2020, 03:35 pm
Perhaps the pin out will help... most of the pins are analog and digital.

(https://cdn.instructables.com/FQM/7X6B/J7GGGD9O/FQM7X6BJ7GGGD9O.LARGE.jpg)
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Apr 01, 2020, 03:37 pm
Perhaps the pin out will help... most of the pins are analog and digital.

(https://cdn.instructables.com/FQM/7X6B/J7GGGD9O/FQM7X6BJ7GGGD9O.LARGE.jpg)
I have seen it.

It does not helped me. It's much easyer to use an standalone LDR with two legs. Works as a charm, and much cheaper too :)
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Apr 01, 2020, 03:43 pm
Bjerknes, perhaps there's a communication issue... Grumpy was pointing out that you can't use a digital pin to read analog data.  If it's working now then you have it on an analog pin.  Perhaps its a small language issue.
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Apr 01, 2020, 03:46 pm
Bjerknes, perhaps there's a communication issue... Grumpy was pointing out that you can't use a digital pin to read analog data.  If it's working now then you have it on an analog pin.  Perhaps its a small language issue.
Maybe... but i uset the same pin. I just changed the LDR sensor and the second one worket fine. I'm sure it can be fixed with the right code etc. but it's much simplier to use an sensor that works out of the box :)
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Apr 01, 2020, 03:47 pm
Good then all is fine
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Apr 01, 2020, 03:49 pm
Good then all is fine
Yes, my problem is solved. My main priority is to move on an not stop too long for finding solutions on problems that can be solved with a simple sensor change :)
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Apr 01, 2020, 06:23 pm
For future reference, all of this would have gone much, much better if you had posted exactly what module you had, by part number and a link so those with something to offer would know exactly what you had. Things also go better when someone explains their project in detail including what they hope to achieve like the objective. While apparently everything came out well we likely could have been here much sooner.

Ron
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Apr 01, 2020, 06:32 pm
I think it's a language barrier
Title: Re: LDR Photoresistor and resistance
Post by: Ron_Blain on Apr 01, 2020, 07:09 pm
I think it's a language barrier
Maybe but I am hard pressed to buy that on this one. Posting a picture of something you don't have as something you are working with is not a language issue. Then I say well they looked similar? Whatever someone has they got somewhere and producing a link should be a -3 on a scale of 1 to 10.  :) I can appreciate you being the kinder soul but much of what this thread has been through reflects and eerie similarity to a thread I was involved in on another forum we share. Not once but two threads on that forum. So yes, maybe I am a little callous.

Ron
Title: Re: LDR Photoresistor and resistance
Post by: wolframore on Apr 01, 2020, 07:14 pm
Nah, all good, I'm just on here helping out a little due to Covid19 - having fun... no worries, I don't see how you put up with some of the rude folks asking for help and not listening or cooperating.  I just ignore those :D
Title: Re: LDR Photoresistor and resistance
Post by: TomGeorge on Apr 02, 2020, 01:23 am
Yes, my problem is solved. My main priority is to move on an not stop too long for finding solutions on problems that can be solved with a simple sensor change :)
So a circuit diagram and  the final working code would be good to finish the thread.
Thanks.. Tom.. :)
Title: Re: LDR Photoresistor and resistance
Post by: Bjerknez on Apr 02, 2020, 02:02 am
My circuit diagram it's just in my head, but here is the code for the two units i have.

This is code for the main sensor with LCD, temperature sensor, LED, LDR etc.

Code: [Select]
#include <LiquidCrystal_I2C.h>
#include <DHT.h>;
LiquidCrystal_I2C lcd(0x27, 20, 4);

byte CelciusSymbol[] = {
  B00111,
  B00101,
  B00111,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

#define DHTPIN 19     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

int sensorPin = 34;
int sensorValue = 0;
int redled = 13;
int blueled = 12;
int greenled = 14;

int freq = 5000;
int ledChannel = 13;
int ledChannel2 = 12;
int ledChannel3 = 14;
int resolution = 8;

BlynkTimer timer;

char auth[] = "***";

char ssid[] = "***";
char pass[] = "***";

void startup() {
  lcd.begin();
  lcd.backlight();
  ledcWrite(redled, 255);

  delay(1000);
  lcd.setCursor(0, 2);
  lcd.print("Ver.2.0");
  delay(1000);

  lcd.setCursor(0, 3);
  lcd.print("Starting up");
  delay(2000);

  ledcWrite(blueled, 0);
  ledcWrite(redled, 200);
  ledcWrite(greenled, 30);

  lcd.setCursor(11, 3);
  lcd.print(".");
  delay(500);

  lcd.setCursor(12, 3);
  lcd.print(".");
  delay(500);

  lcd.setCursor(13, 3);
  lcd.print(".");
  delay(500);

  lcd.setCursor(14, 3);
  lcd.print(".");
  delay(500);

  lcd.setCursor(15, 3);
  lcd.print(".");
  delay(500);

  lcd.setCursor(16, 3);
  lcd.print(".");
  delay(1000);

  lcd.clear();
}

void sensorData(){
    // some code for writing temperature and humidity values to serial monitor
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  Serial.print("Fuktighet: ");
  Serial.print(hum);
  Serial.print(" %, Temperatur: ");
  Serial.print(temp);
  Serial.println(" Celsius");

  lcd.createChar(0, CelciusSymbol);

  // code for showing temperature innside the box
  lcd.setCursor(0, 0);
  lcd.print("FURTEBUA");

  lcd.setCursor(13, 0);
  lcd.print("Ver.2.0");

  lcd.setCursor(0, 1);
  lcd.print("--------------------");

  // code for showing temperature values on LCD display
  lcd.setCursor(0, 2);
  lcd.print("Temperatur: ");

  // code for showing temperature values on LCD display
  lcd.setCursor(13, 2);
  lcd.print(temp);
  lcd.write(0);

  lcd.setCursor(19, 2);
  lcd.print("C");

    // code for showing temperature innside the box
  lcd.setCursor(0, 3);
  lcd.print("Fuktighet: ");

  // code for showing humidity values on LCD display
  lcd.setCursor(13, 3);
  lcd.print(hum);
  lcd.print(" %");

  // some code that makes the value "sensorValue"
  sensorValue = analogRead(sensorPin); // read the value from the sensor
  Serial.println(sensorValue); //prints the values coming from the sensor on the

  // some statements that turns on and off the LCD display regards to light in the room
  if (sensorValue > 3000) {
    lcd.noBacklight();
    ledcWrite(redled, 15);
    ledcWrite(greenled, 0);
    ledcWrite(blueled, 0);
  }
  if (sensorValue < 3000) {
    lcd.display();
    lcd.backlight();
    ledcWrite(redled, 0);
    ledcWrite(greenled, 15);
    ledcWrite(blueled, 0);
  }
  // some code that sends virtual data to the Blynk app
  Blynk.virtualWrite(V5, temp);
  Blynk.virtualWrite(V6, hum);
}

void setup()
{
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(2000L, sensorData);
  Serial.begin(9600);

  // configure LED PWM functionalitites
  ledcSetup(ledChannel, freq, resolution);
  ledcSetup(ledChannel2, freq, resolution);
  ledcSetup(ledChannel3, freq, resolution);

  // attach the channel to the GPIO to be controlled
  ledcAttachPin(redled, ledChannel);
  ledcAttachPin(greenled, ledChannel2);
  ledcAttachPin(blueled, ledChannel3);

  pinMode(redled, OUTPUT);
  pinMode(greenled, OUTPUT);
  pinMode(blueled, OUTPUT);
  pinMode(sensorPin, INPUT);
  ledcWrite(redled, 0);
  ledcWrite(greenled, 0);
  ledcWrite(blueled, 0);
  dht.begin();
  startup();
}

void loop() {
  Blynk.run();
  timer.run();
}


And this is the code for the internal temperature sensor inside project box:

Code: [Select]
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

BlynkTimer timer;

int dark=1000; //Specified in Hz
int light=1300; //Specified in Hz
int buzzPin=15;
int timeOn=300; //specified in milliseconds
int timeOff=300; //specified in millisecods

char auth[] = "***";

char ssid[] = "***";
char pass[] = "***";

int ledred = 14;
int ledyellow = 12;
int ledblue = 13;

void buzzer(){
 tone(buzzPin, dark);
 delay(timeOn);
 noTone(buzzPin);
 tone(buzzPin, light);
 delay(timeOff);
}

void sensorData(){
  sensors.requestTemperatures();
  Serial.print("Temperatur: ");
  Serial.println(sensors.getTempCByIndex(0));
  Blynk.virtualWrite(V5, sensors.getTempCByIndex(0));
  ledgrid();
}

void ledgrid(){
  if (sensors.getTempCByIndex(0) <20){
  digitalWrite(ledblue, HIGH);
  digitalWrite(ledyellow, LOW);
  digitalWrite(ledred, LOW);
  noTone(buzzPin);
  }
if (sensors.getTempCByIndex(0) >=20 && sensors.getTempCByIndex(0) <=25){
  digitalWrite(ledblue, LOW);
  digitalWrite(ledyellow, HIGH);
  digitalWrite(ledred, LOW);
  noTone(buzzPin);
}
if (sensors.getTempCByIndex(0) >25){
  digitalWrite(ledblue, LOW);
  digitalWrite(ledyellow, LOW);
  digitalWrite(ledred, HIGH);
  buzzer();
  Blynk.notify("WARNNG! Over 60 grader i boksen!");
  }
}

void setup()
{
  timer.setInterval(10000L, sensorData);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(ledred, OUTPUT);
  pinMode(ledyellow, OUTPUT);
  pinMode(ledblue, OUTPUT);
  pinMode(buzzPin, OUTPUT);
}

void loop() {
  Blynk.run();
  timer.run();
  }