Hate to bother you with this simple sketch but it seemed to work initially
and now for some reason it don't. Has to be something simple here I am missing buy can't
seem to see it. What this circuit is supposed to do is when a given temperature is reached
it will either turn on a led and a relay or off. The temps really don't matter here ,just
using values for test purposes. The display reads out 22.5C so it should respond to the code.
Also can you tell me what I would need to do to get it to read in This is going to be a
proof of concept circuit. It will turn on a fan or off at a given temp. Currently the green
led always goes on and the red never .I have tested the led and they do work.
Thanks
Start your code here
// DHT11 Sensor:
// VCC to 5V
// GND to GND
// Data to digital pin 2
// OLED Display:
// VCC to 5V
// GND to GND
// SCL to A5 (SCL)
// SDA to A4 (SDA)
// Arduino Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
int redLed =4;
int greenLed=5;
int RLY1=7;
// OLED display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// DHT11 settings
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize serial communication
Serial.begin(9600);
pinMode(redLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(RLY1,OUTPUT);
// Initialize the DHT sensor
dht.begin();
// Initialize the OLED display
if(!display.begin(SSD1306_SWITCHCAPVCC,0x3C, OLED_RESET)) {
Serial.println(F(“SSD1306 allocation failed”));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
//Relay operation and led’s
if
(“C” < 20 ){
digitalWrite(redLed,HIGH);
digitalWrite(greenLed,LOW);
digitalWrite(RLY1,LOW);
}
if (“C” > 25)
{
digitalWrite(redLed,LOW);
digitalWrite(greenLed,HIGH);
digitalWrite(RLY1,HIGH);
}
// Read temperature as Celsius
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again)
if (isnan(temperature)) {
Serial.println(F(“Failed to read from DHT sensor!”));
return;
}
// Display temperature on OLED
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(F(“Temp: “));
display.print(temperature);
display.print(F(” C”));
display.display();
// Print temperature to Serial Monitor
Serial.print(F(“Temperature: “));
Serial.print(temperature);
Serial.println(F(” C”));
// Wait a few seconds between measurements
delay(2000);
}
Hi.
The first thing in the loop should be reading the temperature.
After having the temperature compare it with your values.
Don’t use “C”, use your actual temperature variable.
Compare with float values like 25.0 and not just 25.
I hope this help.s
Regards,
Sar
Thanks. I believe I killed the post because I resolved my issue, thanks for the great advice though
Thanks. I believe I killed the post because I resolved my issue, thanks for the great advice though