Moisture Sensor and Screen Diagram-02.jpg
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

// SOIL MOISTURE CONSTANTS
int thresholdValue = 50;//you can adjust the threshold value

// SENSOR 1
const int analogPin1 = A0;//soil moisture sensor attached to analog pin A0
const int digitalPin1 = 5;//soil moisture sensor attached to digital pin 5

void setup() {
  Serial.begin(9600);

  // SOIL MOISTURE SETUP
  pinMode(digitalPin1, INPUT);//sets the digitalPin as INPUT
  digitalWrite(digitalPin1, LOW);//sets to LOW so no power is flowing through the sensor
    
  Serial.println("OLED FeatherWing test");
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  Serial.println("OLED begun");

  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  Serial.println("IO test");
  // text display tests
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.print("Connecting to SSID\n'adafruit':");
  display.print("connected!");
  display.println("IP: 10.0.1.23");
  display.println("Sending val #0");
  display.setCursor(0,0);
  display.display(); // actually display all of the above
}

void StayDisplay(void)
{
  display.print("A");
}

void loop() {
  display.setCursor(0,0);
  display.clearDisplay();

                   //Wait 1 Second
  
  // SOIL MOISTURE LOOP  
  // sensor 1
  int analogValue1 = analogRead(analogPin1);//analog value from soil moisture sensor
  int digitalValue1 = digitalRead(digitalPin1);//digital value from soil moisture sensor
  int moisture1 = map(analogValue1, 0, 1023, 100, 0);//maps the analog value - 100% very wet/0% - very dry

  display.print("Moisture Levels");

  display.print("\n");

  display.print("Moisture:");
  display.print(moisture1);
  display.print("%");
  display.print("\n");
  display.display();
  
  delay(200);
  display.display();
  display.clearDisplay();
}