This tutorial uses the AS7263 NIR (near infrared) spectrometer sensor to assess plant foliage health. It explains how to uses the sensor’s channel readings and the standard Normalized Difference Vegetation Index (NDVI) equation to calculate an estimated NDVI value. It then prints the value and a “HEALTHY” or “UNHEALTHY” statement to the Serial Monitor and turns on an RGB LED to green or red to indicate whether the foliage is within the healthy or unhealthy range, respectively.
Background & Methodology
Leaf colour is a valuable indicator of a plant’s condition, and healthy leaves must have an abundance of chlorophyll to effectively photosynthesize. Our eyes perceive a healthy leaf as green because chlorophyll reflects wavelengths in the green region of the electromagnetic spectrum, while the other visible wavelengths are absorbed – notably those in the red region. Chlorophyll also reflects a high percentage of near-infrared wavelengths that are not visible to the naked eye.
To this end, remote sensing practitioners use NDVI to assess foliage health by measuring the difference between the amount of near-infrared (strongly reflected) and red (easily absorbed) light that is reflected off the foliage, using the following equation:
NDVI always ranges from -1 to +1, and healthy foliage falls within the 0.2 to 0.8 range.
For this tutorial, we will apply this method to a single plant’s leaves by plugging in readings from the AS7263 NIR sensor into the NDVI equation. The sensor detects wavelengths across 6 channels and puts out readings as counts per μW/cm2, which gives a measure of the amount of incident light that is being reflected at each wavelength. Two of the sensor’s channels are close to the wavelengths that are typically used in the NDVI equation. These channels are S and V, giving out readings for the 680 nm (still in the red range) and 810 nm (near-infrared) wavelengths, respectively. Once the NDVI value is calculate, we can use an ifelse statement to signal whether the foliage is within a healthy range.
Parts
- (1) Arduino Uno microcontroller (MCU)
- (1) 830 Tie Points Breadboard
- (1) Qwiic AS7263 NIR Spectral Sensor
- (1) Qwiic Shield for Arduino
- (1) Qwiic Cable
- (4) M-M wires
- (1) RGB LED
*** In this case, you do not need resistors because the AS7263 sensor and LED together, on average, pull 5V – the MCU’s total output voltage.
Wiring
1. Assuming that the pins are already soldered to the Qwiic Shield, secure the shield to the MCU and use the standard Qwiic cable to connect the AS7263 sensor to the shield. For more information on the sensor’s hook up click here.
2. Then insert the RGB LED pins into the breadboard and connect the pins to the MCU through the shield with the M-M wires, as shown in the diagram below.
3. Connect the MCU to your computer.
*** To achieve optimal performance, the sensor should point down onto the foliage. It is also important to note that, per the sensor’s datasheet, the sensor is not designed for high energy UV (ultraviolet) environments, including upward looking outdoor applications.
Code
1. Open your Arduino software and install the Sparkfun AS726X Arduino Library. Go to Sketch > Include Library > Manage Library… and search for “SparkFun AS726X.” Install the 1.0.4 version of the library. This library includes functions and example code for both the AS7263 NIR and AS7262 VIS (visible wavelengths) sensors.
2. Before running any new code, confirm that your sensor is functioning by running some sample code from the Sparkfun Library. Go to File > Examples > Sparkfun AS726X > Example_BasicReadings. Upload the example code and open your serial monitor, the printouts should look like this:
3. If the sensor is functioning, then copy and paste the below code into a new sketch and upload, the code is commented throughout for your reference. Point your sensor down at your plant.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/* Final Project Tutorial - Evaluating Foliage Health with the AS7263 NIR Spectral Sensor * Mariya Lupandina, 22.03.30 * This tutorial uses the AS7263 NIR (near infrared) spectrometer sensor to assess plant foliage health. It explains how to uses the sensor’s channel readings and the standard NDVI equation to calculate an estimated NDVI. It then prints the value and a "HEALTHY" or "UNHEALTHY" statement to the serial monitor and turn on an RGB LED to green or red to indicate whether the foliage is healthy or unhealthy, respectively. This code was adapted from the Example1_BasicReadings and Example2_SensorSettings code in the library written for the Sparkfun AS726X Spectral Sensor (Visible or IR), written by Nathan Seidle & Andrew England @ SparkFun Electronics, July 12th, 2017. https://github.com/sparkfun/Qwiic_Spectral_Sensor_AS726X and from Lesson 4: RGB_LED in the ELEGOO Starter Kit tutorial package, written by Unknown, December 8th, 2016. https://www.elegoo.com/pages/arduino-kits-support-files */ #include "AS726X.h" //load the Sparkfun AS726X library AS726X sensor; //create the sensor object byte GAIN = 0; //don't worry about this byte MEASUREMENT_MODE = 2; //turn on Mode 2 to get measurements in the desired S & V channels //define NDVI equation variables float a; float b; float NDVI_est; //define pins for RGB LED int BLUE = 3; int GREEN = 5; int RED = 6; void setup() { Wire.begin(); Serial.begin(115200); //remember to change baud rate to 115200 in the serial monitor when you open it pinMode(RED, OUTPUT); //set pin modes for RGB LED pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT); digitalWrite(RED, LOW); //set initial LED state digitalWrite(GREEN, LOW); digitalWrite(BLUE, LOW); sensor.begin(); //command for sensor to begin running } void loop() { sensor.takeMeasurements(); //command for sensor to begin taking measurements if (sensor.getVersion() == SENSORTYPE_AS7263) { //indicate which sensor is connected based on Sparkfun sample code NDVI_est = NDVI_eq(sensor.getCalibratedV(), sensor.getCalibratedS()); //run NDVI equation function with S (680 nm) & V channels' (810 nm) readings Serial.print(" Reading: S["); //print raw S & V channel readings to the serial monitor Serial.print(sensor.getCalibratedS(), 2); Serial.print("] V["); Serial.print(sensor.getCalibratedV(), 2); Serial.println("]"); Serial.print(" NDVI estimate = "); //print NDVI estimate to the serial monitor Serial.println (NDVI_est); if (( NDVI_est > 0.2) && (NDVI_est < 0.8)) { // if NDVI estimate is between 0.2 & 0.8 this indicates healthy foliage Serial.println(" HEALTHY"); digitalWrite(GREEN, HIGH); //turn on green LED to indicate healthy foliage } else { Serial.println(" UNHEALTHY"); // if NDVI estimate is outside the above range, then foliage is unhealthy digitalWrite(RED, HIGH); //turn on red LED to indicate unhealthy foliage } Serial.println(); //insert row between readings } delay(5000); //create 5 second delay between readings } float NDVI_eq(float a, float b) { //create function for NDVI equation float result; result = (a-b)/(a+b); //NDVI equation, where a = infrared wavelength reading & b = red wavelength reading return result; } |
4. Open your serial monitor, the printouts should look like this:
and depending on your plant’s condition, your RGB LED should light up as green or red.
References
Detailed Digikey Article about the AS726X’s Design and Operation
Sparksfun AS726X NIR/VIS Spectral Sensor Hookup Guide
NASA Page Describing Near-Infrared’s Use in Determining Vegetation Health
One reply on “Interpreting AS7263 NIR Spectral Sensor Readings to Determine Plant Foliage Health and Turn on an LED”
I tried the sample code but it says I2C error. How to remove this error?