top of page
Search
Writer's picturePrince Altidor

Got code to work plus more

last week i got my code to work for the soil sensor an the pump (motor) it ran smoothly nothing went wrong then i went on and took up my biggest challenge was getting my humidity sensor to work but the one i was using when i first originally started this project wouldnt show up i really dont know why so i obtained anew DHT22 sensor and it works perfectly then i started to make ints where these veriable would turn on or of a fan now im in a delima for transmiting both 5v and 12v but i know i want to use a usbc PD cause not mony projects use them and its better in the long run i could use a voltage regulatro but i dont know yet now my next code and hardware challenge is either a lcd to show the varible such as temp and humidity but mainly geting my online dash board to show all varibles and buttons that i may add later such as reset turning the system off remotely im still thinking of what buttons i could code in that could make this project better then what i envision























//soil sensor files begin

#include "Adafruit_seesaw.h"

int tooDry = 345; //set low parameter for plant

int tooWet = 420; //set high parameter for plant

Adafruit_seesaw ss;

#define MOTOR 12

//soil sensor files end

//DHT sensor files begin

#define FAN 13

#include "DHT.h"


int nothumid = 35; //set low parameter for plant

int toohumid = 70; //set high parameter for plant

#define DHTPIN 14 // Digital pin connected to the DHT sensor

// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --

// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!

//#define DHTTYPE DHT11 // DHT 11

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

//#define DHTTYPE DHT21 // DHT 21 (AM2301)


// Connect pin 1 (on the left) of the sensor to +5V

// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1

// to 3.3V instead of 5V!

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)

// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)

// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor


// Initialize DHT sensor.

// Note that older versions of this library took an optional third parameter to

// tweak the timings for faster processors. This parameter is no longer needed

// as the current DHT reading algorithm adjusts itself to work on faster procs.

DHT dht(DHTPIN, DHTTYPE);



void setup() {

//DHT sensor set up begin

Serial.println(F("DHTxx test!"));


dht.begin();

//DHT sensor set up ends

pinMode(FAN , OUTPUT);

//soil sensor set up Begin

Serial.begin(115200);

pinMode(MOTOR , OUTPUT);

Serial.println("seesaw Soil Sensor !");


if (!ss.begin(0x36)) {

Serial.println("ERROR! seesaw not found");

while (1);

} else {

Serial.print("seesaw started!: ");

Serial.println(ss.getVersion(), HEX);

//soil sensor set up ends

}

}


void loop() {



// Wait a few seconds between measurements.

delay(2000);


// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

float h = dht.readHumidity();

uint16_t humread = dht.readHumidity(0);


// Read temperature as Celsius (the default)

float t = dht.readTemperature();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);


// Check if any reads failed and exit early (to try again).

if (isnan(h) || isnan(t) || isnan(f)) {

Serial.println(F("Failed to read from DHT sensor!"));

return;

}


// Compute heat index in Fahrenheit (the default)

float hif = dht.computeHeatIndex(f, h);

// Compute heat index in Celsius (isFahreheit = false)

float hic = dht.computeHeatIndex(t, h, false);


Serial.print(F(" Humidity: "));

Serial.print(h);

Serial.print(F("% Temperature: "));

Serial.print(t);

Serial.print(F("°C "));

Serial.print(f);

Serial.print(F("°F Heat index: "));

Serial.print(hic);

Serial.print(F("°C "));

Serial.print(hif);

Serial.println(F("°F"));

Serial.println(humread);

if (humread <= toohumid) {


//Serial.print ("hello");


digitalWrite(FAN, LOW); //turns the motor on

delay(500);

Serial.print("FAN LOW ");

}

else if (humread >= nothumid) {

digitalWrite(FAN, HIGH);

Serial.print("FAN, HIGH ");

}

delay(250);

//DHT sensor void loop ends


//soil sensor loop begins

float tempC = ss.getTemp();

uint16_t capread = ss.touchRead(0);


Serial.print("Temperature: "); Serial.print(tempC); Serial.println("*C");

Serial.print("Capacitive: "); Serial.println(capread);

delay(100);

if (capread <= tooDry) {


//Serial.print ("hello");


digitalWrite(MOTOR, HIGH); //turns the motor on

delay(500);

Serial.print("MOTOR HIGH ");

}

else if (capread >= tooWet) {

digitalWrite(MOTOR, LOW);

Serial.print("MOTOR LOW");

}

delay(250);

//soil sensor loop ends

}


Comentarios


bottom of page