Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

How to display LDR and soil-moisture sensor values using an OLED

By Ashutosh Bhatt

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 electric current. The OLED technology uses LEDs whereby the light is produced by an organic molecule.

In Part II, we’ll present data using two additional analog sensors:

  • Soil-moisture sensor – measures the volumetric water content in soil
  • Light-dependent resistor (LDR) – a photoresistor or electronic component that’s sensitive to light

Refer to Part I to review the basics of how to interface an OLED display with Arduino. Here, we’ll begin by discussing how to interface the 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 conductors, which act as a variable resistor (much like the POT). Its resistance varies according to the water content in the soil. This resistance is inversely proportional to the soil’s moisture. 

A soil-moisture sensor

This means that the greater the water content in the soil, the better the conductivity and less resistance. Inversely, if there is little or no water in the soil, the sensor will have poor conductivity and greater 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 outputs a digital signal that indicates which of the two is larger. 

For this project, it provides an analog and digital output. The analog output voltage is set between 0 to 5 V, as the probe resistance varies. The digital output is between 0 and 5 V, as per the threshold voltage set using the POT. A trimmer POT 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…

The light-dependent resistor or LDR is also a variable resistor, but it works on the principle of photoconductivity, which means that its resistance depends on the intensity of the light. It’s made up 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 the conductivity and decreases the resistance. The opposite is also true. If there is little light and few photons, there is little conductivity but more resistance.

This change in resistance is converted into an analog voltage output of between 0 and 5 V using a pull-down resistance.

For this project, we use an LDR module that has the same circuit arrangement with three pins.

Pin names, functions, and connections…

Circuit diagram

Circuit connections
This circuit is built using only 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 with the Arduino board’s +5 V and GND pins. The signal pin is connected to the analog input pin A1 of the board.
  • The soil-moisture sensor module also has the same three pins: the +V, GND, and signal pins. The +V and GND pins are connected with the Arduino board’s +5 V and GND pins. The signal pin is connected to the analog input pin A0 of the board.
  • The OLED has four interfacing pins (as discussed in part I of this tutorial): VCC, GND, SDA, and SCL. The VCC and GND pins are connected with Arduino’s +5 V and GND pins, providing the power supply to the display. The SDA and SCL pins are connected with Arduino’s A4 (SDA) and A5 (SCL) pins for data communication.
  • Arduino receives its power supply from a computer’s USB port. The onboard voltage regulator chip will provide a 5V supply to both the sensor modules and the OLED display. 

Circuit operation

  • First, the soil-moisture sensor senses the water content in the soil. The conductivity between its two probes varies based on the moisture level and provides an analog voltage output. If the moisture level is low, the conductivity is also low but the output voltage is 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 Arduino, which converts it into a corresponding digital value between 0 and 1023. This digital value is further 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 gives an analog output voltage as per the intensity of light. As it increases per the LDR, the analog output voltage also increases — or vice versa. If the light decreases, so does the analog output voltage.
  • This analog output voltage is also read by Arduino and converted into a corresponding digital value between 0 and 1023. This digital value is further converted into a percentage (between 0 and 100%).

  • Arduino converts both sensor values into a percentage range (between 0 and 100%) and displays it on the OLED.

The operating circuit

Software program
The Arduino board microcontroller (ATMega328) performs these tasks when using the below program:

1. Reads the analog voltage output from both sensors
2. Converts the sensor data into a percentage range (between 0 to 100%)
3. Displays the sensors’ data values on the OLED display

This program is written in C/C++ language using Arduino IDE’s software. It’s also compiled and uploaded to Arduino’s microcontroller using the same software.



Filed Under: Electronic Projects, Sensors
Tagged With: Arduino, ldr, lightdependentresistor, oled, program, resistor, sensors, soilmoisturesensor
 

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Op amp non inverting amplifier not working
  • Measure AC current accurateley (100mA to 10A)
  • Avalanche Pulser
  • Fpga wake up
  • RCF Subwoofer Amplifier PIC16F870-I/SP please help me about hex code

RSS Electro-Tech-Online.com Discussions

  • How to search component to replace my burn RF inductor?
  • Need a ducted soldering fan for solder smoke extraction
  • Someone please explain how this BMS board is supposed to work?
  • bluetooth jammer
  • Disabled son needs advice please
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering