Notifications
Clear all

arduino nano 33 iot plant watering system

3 Posts
2 Users
0 Likes
151 Views
(@tshupp0501)
Member
Joined: 1 year ago
Posts: 1
Topic starter  

i have tried to make this work but i keep getting errors 

.inoC++
#include "arduino_secrets.h"
/*
  Sketch generated by the Arduino IoT Cloud Thing
 
  Arduino IoT Cloud Variables description
 
  The following variables are automatically generated and updated when changes are made to the Thing
 
  float current_Temp;
  float currrent_Humid;
  int current_Moisture;
  int trigger_Level;
  bool pump_Status;
 
  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/
 
// Adafruit GFX Library - Version: Latest
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
 
// Adafruit SSD1306 - Version: Latest
#include <Adafruit_SSD1306.h>
#include <splash.h>
 
// DHT sensor library - Version: Latest
#include <DHT.h>
#include <DHT_U.h>
 
// Wire Library for I2C
#include <Wire.h>
 
// Set OLED size in pixels
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
 
// Set OLED parameters
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
// Define DHT22 Parameters
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
 
// Define variables for Temperature and Humidity
float temp;
float hum;
 
// Sensor constants - replace with values from calibration sketch
 
// Constant for dry sensor
const int DryValue = 2650;
 
// Constant for wet sensor
const int WetValue = 1800;
 
// Variables for soil moisture
int soilMoistureValue;
int soilMoisturePercent;
 
// Analog input port
#define SENSOR_IN 0
 
// Relay Port
#define RELAY_OUT 3
 
// Pump Status Text
String pump_status_text = "OFF";
 
// Variable for pump trigger
int pump_trigger = 30;
 
// IoT Cloud Thing Properties file
#include "thingProperties.h"
 
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();
 
  // Initialize I2C display using 3.3 volts
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  display.clearDisplay();
 
  // Initialize DHT22
  dht.begin();
 
  // Set ADC to use 12 bits
  analogReadResolution(12);
 
  // Set Relay as Output
  pinMode(RELAY_OUT, OUTPUT);
 
  // Turn off relay
  digitalWrite(RELAY_OUT, LOW);
 
  // Set Pump Status to Off
  pump_Status = false;
 
}
 
void loop() {
  // Call Arduino IoT Cloud for updates
  ArduinoCloud.update();
 
  // Get temperature and Humidity
  temp = dht.readTemperature();
  hum = dht.readHumidity();
 
  // Pass temperature and humidity values to cloud variables
  current_Temp = temp;
  currrent_Humid = hum;
 
  // Get soil mositure value
  soilMoistureValue = analogRead(SENSOR_IN);
 
  // Determine soil moisture percentage value
  soilMoisturePercent = map(soilMoistureValue, DryValue, WetValue, 0, 100);
 
  // Keep values between 0 and 100
  soilMoisturePercent = constrain(soilMoisturePercent, 0, 100);
 
  // Print raw value to serial monitor for sensor calibration
  Serial.println(soilMoistureValue);
 
  // Pass soil moisture to cloud variable
  current_Moisture = soilMoisturePercent;
 
  // See if pump should be triggered
  // See if moisture is below or equal to threshold
  if (soilMoisturePercent <= pump_trigger) {
    // Turn pump on
    pumpOn();
 
  } else {
    // Turn pump off
    pumpOff();
  }
 
  // Cycle values on OLED Display
  // Pump Status
  printOLED(35, "PUMP", 40, pump_status_text, 2000);
  // Temperature
  printOLED(35, "TEMP", 10, String(temp) + "C", 2000);
  // Humidity
  printOLED(30, "HUMID", 10, String(hum) + "%", 2000);
  // Moisture
  printOLED(35, "MOIST", 30, String(soilMoisturePercent) + "%", 2000);
 
 
}
 
void pumpOn() {
  // Turn pump on
  digitalWrite(RELAY_OUT, HIGH);
  pump_status_text = "ON";
  pump_Status = true;
 
}
 
void pumpOff() {
  // Turn pump off
  digitalWrite(RELAY_OUT, LOW);
  pump_status_text = "OFF";
  pump_Status = false;
 
}
 
void printOLED(int top_cursor, String top_text, int main_cursor, String main_text, int delay_time){
  // Prints to OLED and holds display for delay_time
  display.setCursor(top_cursor, 0);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println(top_text);
 
  display.setCursor(main_cursor, 40);
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.print(main_text);
  display.display();
 
  delay(delay_time);
  display.clearDisplay();
 
}
 
 
void onTriggerLevelChange()  {
  // Changes when Pump Trigger Level slider is activated
 
  pump_trigger = trigger_Level;
 
} and i keep getting this error : ompilation terminated.
exit status 1

Compilation error: arduino_secrets.h: No such file or directory and cant seem to get it to work ay idea of whats going on? any help would be appreciated!!!!!!

 

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@tshupp0501  In order to be of asistance, pleae read the help especially how to include source code. It is to the right above the list of current posts.

Your error is you do not have a secrets file as the error message says.

 arduino_secrets.h: No such file 

This error is a result of not following the correct IOT procedures. Please watch Bills video at HERE  and read the article at HERE

I forget when the secrets file is created but it is fairly early in the process.

Good luck.

Screenshot 2024 03 11 at 08.45.12

 

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

Since I need to refresh my knowledge on the new Arduino IOT cloud, I just did a quick project.

1. Make sure the Arduino Create Agent is running.

2. Create your Device, this is where the Secret Key is created, make sure you download the pdf so you have a copy.

3. Create your thing. This is where you input your network credentials that creates the secrets.h file

4. Now create a new sketch. I had to fiddle with it a bit to get connected but when I quit and re-opened the sketch the secrets file and the other files were there. The last screen grab shows that.

Good luck.

Screenshot 2024 03 11 at 10.53.19

 

Screenshot 2024 03 11 at 10.55.21
Screenshot 2024 03 11 at 10.54.03
Screenshot 2024 03 11 at 10.57.04

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote