#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <EloquentTinyML.h>
#include <eloquent_tinyml/tensorflow.h>
#include <Arduino.h>
#include "model.h"
#define NUMBER_OF_INPUTS 3
#define NUMBER_OF_OUTPUTS 3
#define TENSOR_ARENA_SIZE 2 * 1024
Eloquent::TinyML::TensorFlow::TensorFlow<NUMBER_OF_INPUTS, NUMBER_OF_OUTPUTS, TENSOR_ARENA_SIZE> tf;
#define DHTPIN 15 // DHT22 data pin is connected to GPIO 15
#define DHTTYPE DHT22 // DHT type is DHT22
DHT dht(DHTPIN, DHTTYPE);
const int photoresistorPin = 2; // Photoresistor sensor connected to GPIO 2
void setup() {
Serial.begin(115200);
pinMode(photoresistorPin, INPUT);
tf.begin(model);
dht.begin();
}
void loop() {
// Read temperature and humidity from DHT sensor
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Read light intensity from photoresistor
int lightIntensity = analogRead(photoresistorPin);
// Print sensor values
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Light Intensity: ");
Serial.println(lightIntensity);
float input[3] = {temperature, humidity, lightIntensity * 1.0};
// Predict using TensorFlow model
float predictions[NUMBER_OF_OUTPUTS];
tf.predict(input, predictions);
Serial.print("Predictions: ");
for (int i = 0; i < NUMBER_OF_OUTPUTS; ++i) {
Serial.print(predictions[i]);
Serial.print(" ");
}
Serial.println();
delay(2000); // Delay for 2 seconds before the next iteration
}