Go Down

Topic: LDR Photoresistor and resistance (Read 1 time) previous topic - next topic

wolframore

Bad Boys Race Our Young Girls But Violet Generally Wins - Get Some Now :) - ELI ICE man

Bjerknez

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 :)

Ron_Blain

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

wolframore

I think it's a language barrier
Bad Boys Race Our Young Girls But Violet Generally Wins - Get Some Now :) - ELI ICE man

Ron_Blain

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

wolframore

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
Bad Boys Race Our Young Girls But Violet Generally Wins - Get Some Now :) - ELI ICE man

TomGeorge

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.. :)
Everything runs on smoke, let the smoke out, it stops running....

Bjerknez

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();
  }

Go Up