Hello There…
I am Johan, I am currently working on an automated farming system using the IoT cloud platform. I am using an Arduino nano 33 IoT, a DHT22 sensor attached to pin 2, a LDR sensor on pin A0 and an analog temperature sensor (KY-013) on analog pin A1. And the sensors are powered from an external breadboard power supply as I am not sure if the nano 33 IoT has a 5v pin. But I am facing an issue with my code as my DHT22 and LDR sensor is not switching on, the readings from the temperature sensor are going haywire and the <DHT.h> and <SimpleDHT.h> libraries are not working. I would like to understand whether it is with my code or any other issues in my code.
This is my code
#include "thingProperties.h";
#include <SimpleDHT.h>;
#define pinDHT22 A2;
SimpleDHT22 dht22(pinDHT22);
#define TEMP_PIN A1;
#define LIGHT_PIN A0;
int Vo;
float R1 = 10000; // value of R1 on board
float logR2, R2, T;
float c1 = 0.001129148, c2 = 0.000234125, c3 = 0.0000000876741;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
}
void onTemperatureChange() {
Vo = analogRead(TEMP_PIN);
R2 = R1 * (1023.0 / (float)Vo - 1.0); //calculate resistance on thermistor
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // temperature in Kelvin
temperature = T - 273.15;
Serial.print(temperature);
}
void onHumidityChange() {
int humidity = 0;
Serial.print(pinDHT22);
}
void onLightChange() {
analogWrite(LIGHT_PIN, INPUT);
Serial.print(analogRead(LIGHT_PIN));
}
This is mt thingProperties.h code
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char THING_ID[] = "daf1adac-56e2-48b4-bb72-ee92aee4ccbf";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)
void onLightChange();
void onTemperatureChange();
int light;
CloudRelativeHumidity humidity;
float temperature;
void initProperties(){
ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(light, READWRITE, 3 * SECONDS, onLightChange);
ArduinoCloud.addProperty(humidity, READ, 3 * SECONDS, NULL);
ArduinoCloud.addProperty(temperature, READWRITE, 3 * SECONDS, onTemperatureChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
Please find the below attachment to see what happened to my Dashboard
Please let me know if you find any issue in my code. I would really appreciate your help
Thank you