In Part I of this tutorial, we learned how to present data (or values) using a potentiometer (POT) and an organic light-emitting diode (OLED) display. For this project, the POT was an analog sensor (potentiometers can also be digital), which acts as a resistor to control the flow of an electrical current. OLED technology uses LEDs in which light is produced by an organic molecule.
In Part II, we will present data using two additional analog sensors:
- Soil moisture sensor – measures the volumetric water content in the soil
- Light dependent resistor (LDR) – a photoresistor or light-sensitive electronic component
See Part I to review the basics of interfacing an OLED display with Arduino. Here, we will start by discussing how to interface soil and LDR sensors with Arduino.
The soil moisture sensor consists of two parts: a sensor probe and a sensor circuit. The sensor probe has two exposed leads, which act as a variable resistor (much like POT). Its resistance varies according to the water content of the soil. This resistance is inversely proportional to soil moisture.
This means that the higher the water content in the soil, the better the conductivity and lower resistance. Conversely, if there is little or no water in the soil, the sensor will have low conductivity and higher resistance.
This probe is connected to the sensor circuit. The circuit is built using an operational amplifier (op-amp), which works as a comparator. As its name suggests, a comparator is a device that compares two voltages or currents. It then emits a digital signal that indicates which of the two is larger.
For this project, it provides both an analog and digital output. The analog output voltage is adjusted between 0 and 5 V as the probe resistance varies. The digital output is between 0 and 5 V, according to the threshold voltage configured in the POT. A POT trimmer is used here. It is a variable resistor that can adjust or calibrate circuits.
The trimmer (or Trim POT) is used to adjust the sensitivity of the probe. Two LEDs serve as indicators.
1. Power LED – indicates the sensor is active
2. Output LED – turns on when the digital output (D0) is low (0 V)
Pin names, functions and connections…
Light dependent resistor or LDR is also a variable resistor, but it works on the principle of photoconductivity, which means its resistance depends on the intensity of light. It is made of cadmium sulfide (Cds) material. When light hits this material, the photons lead to an increase in conductivity.
Essentially, the greater the light, the more photons, which increases conductivity and decreases resistance. The opposite is also true. If there is little light and few photons, there will be little conductivity but more resistance.
This change in resistance is converted into an analog voltage output between 0 and 5 V using a pull-down resistor.
Pin names, functions and connections…
Circuit Diagram
Circuit Connections
This circuit is built using just four components: an Arduino NANO board, the OLED display, an LDR module and the soil moisture sensor.
- The LDR module has three pins: the +V, GND, and signal pins. The +V and GND pins are connected to the +5 V and GND pins on the Arduino board. The signal pin is connected to the board's A1 analog input pin.
- The soil moisture sensor module also has the same three pins: the +V, GND, and signal pins. The +V and GND pins are connected to the +5 V and GND pins on the Arduino board. The signal pin is connected to the board's A0 analog input pin.
- The OLED has four interface pins (as discussed in part I of this tutorial): VCC, GND, SDA, and SCL. The VCC and GND pins are connected to the +5 V and GND pins on the Arduino, providing power to the display. The SDA and SCL pins are connected to the Arduino pins A4 (SDA) and A5 (SCL) for data communication.
- The Arduino receives its power supply from a computer's USB port. The integrated voltage regulator chip will provide a 5V supply to the sensor modules and the OLED display.
Circuit operation
- First, the soil moisture sensor detects the water content in the soil. The conductivity between its two probes varies depending on the humidity level and provides an analog voltage output. If the humidity level is low, the conductivity will also be low, but the output voltage will be high (approx. 5 V) — and vice versa. This means that as the soil moisture level increases, the analog output voltage decreases.
- This analog output voltage is read by the Arduino, which converts it into a corresponding digital value between 0 and 1023. This digital value is later converted into a percentage (between 0 and 100%).
- As the soil moisture content increases, the analog output voltage decreases and the corresponding percentage value increases — or vice versa.
- The LDR module also provides an analog output voltage according to the light intensity. As the LDR increases, the analog output voltage also increases – or vice versa. If the light dims, the analog output voltage will also decrease.
- This analog output voltage is also read by the Arduino and converted into a corresponding digital value between 0 and 1023. This digital value is later converted into a percentage (between 0 and 100%).
- The Arduino converts the values from both sensors into a percentage range (between 0 and 100%) and displays them on the OLED.
Software program
The Arduino board microcontroller (ATMega328) performs these tasks when using the program below:
1. Reads the analog voltage output of both sensors
2. Converts sensor data into a percentage range (between 0 and 100%)
3. Displays sensor data values on OLED display
This program was written in C/C++ language using Arduino IDE software. It is also compiled and loaded into the Arduino microcontroller using the same software.