I am sorry. I know I should start with a schematic. I have some basic knowledge. The pin connections were just an example for my code. 23, 22, 21 are the only functional pins in my example. Do you have a recommendation for a good schematic program ? Because of my "issue"...ha. I have trouble writing. I could use the mouse and type on a keyboard before I could walk again. I was piecmealing different code from different examples online to try an understand later. It is hard for me to understand properly if the code I get uses the wrong variable definitions.
I am using an ESP32 DEVKITV1. Some generic I bought from wish.
I created a test circuit using 1 Soil Monitor and 1 RGB Led with the chip.
What I did for this was cycle through 3 different colors... and moisture will give a value, depending on if in water or dry...
/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-soil-moisture-sensor
*/
#define AOUT_PIN 4 // ESP32 pin GPIO36 (ADC0) that connects to AOUT pin of moisture sensor
#define dry 3100
#define wet 1500
#define r 21
#define g 22
#define b 23
// #define BLACK setColor(0,0,0);
// #define GREEN setColor(0,255,0);
// #define YELLOW setColor(240,240,0);
// #define RED setColor(255,0,0);
int LED_01[] = {21,22,23};
int BLACK[] = {0,0,0};
int GREEN[] = {0,255,0};
int YELLOW[] = {230,230,0};
int RED[] = {255,0,0};
const int red_pin = 21;
const int green_pin = 22;
const int blue_pin = 23;
const int pin = 21;
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(AOUT_PIN); // read the analog value from sensor
float percentageHumididy = map(value, dry, wet, 0, 100);
// New way 06/25/2024
activateLED(LED_01, GREEN);
activateLED(LED_01, YELLOW);
activateLED(LED_01, RED);
Serial.print("Moisture value: ");
Serial.print(value);
Serial.print(", ");
Serial.print(percentageHumididy);
Serial.println("%");
delay(2500);
// for (int i=255; i>=0;i--) {
// analogWrite(red_pin,80);
// analogWrite(green_pin,0);
// analogWrite(blue_pin,80);
// //Serial.println(i);
// delay(1);
// }
//BLACK;
// analogWrite(red_pin,0);
// analogWrite(green_pin,0);
// analogWrite(blue_pin,0);
activateLED(LED_01, BLACK);
delay(2500);
}
void setColor(int red, int green, int blue) {
analogWrite(red_pin, red);
analogWrite(green_pin, green);
analogWrite(blue_pin, blue);
}
void activateLED(int led[3], int color[3]) {
analogWrite(led[0], color[0]);
analogWrite(led[1], color[1]);
analogWrite(led[2], color[2]);
delay(2500);
}
The colors cycle using analogWrite, with pins D23, D22, D21 on the board. Will any pin D work for this? I was thinking if I ran out of pins, I would use a shift register IC, based on a google search, but I haven't thought that far yet.
I really would like to learn the "proper way" so thank you for taking the time. This is just "something to do" between my naps before my brain hurts from thinking too much.
And yes, to me, "Everything is a joke." now. In reality, I should have been dead, but it wasn't my time. I guess I had to look after my parents until...so I do not take things seriously at all anymore. I can, if I must, but if an opportunity arises to say something "funny", I will.
Thank you,
Mike