Close
0%
0%

Homemade Spectrometer

Open source experiment kit made with the AS7262 (six colors) and AS7263 (near infrared) spectral sensors and the Raspberry Pi

Similar projects worth following
I have divided this project into two parts. The first section was done with the AS7262 six-color spectral sensor and the experiments were the construction of a filter spectrometer, sensing a RGB LED light, sensing colored solutions, and an IoT monitoring system. The second section was made with the AS7263 NIR (near infrared) spectral sensor to assess plant foliage health, so it explains how to use the sensor's channel readings and the standard Normalized Difference Vegetation Index (NDVI) equation to calculate an estimated NDVI value, which is used to determines as “HEALTHY” or “UNHEALTHY” leaf.

How does my project works?
1. First, I will build a module to accommodate the AS7262 sensor. The goal is to prevent strange light interference.
2. Then, the pHat module will be configured to interface the AS7262 sensor with the Raspberry Pi board.
3. The AS7262 6-channel Visible Light Sensor libraries will be installed.
4. Tests with colored filters begin to verify the response of the sensor to different tonalities such as the red, green, blue, yellow, and white.
5. The second experiment will be done with an RGB LED to find out the light spectrum of its generated colors. The AS7262 sensor will be used to know if its colors are pure or a mixture of several colors.
6. The following experiment will be done with liquid substances of different colors. Here a container will be used and it will be adapted to a new module so that the AS7262 sensor can monitor the container color. The goal is to find out what percentage of each color these substances make up.
7. The fourth experiment consists of adapting an IoT monitoring system in real time. The goal is to do experiments and send data to the internet cloud so that colleagues around the world can see the data from our experiments in real time.
8. The fifth and last experiment will be a plant foliage health monitor of a green area of my community. Here I will use the AS7263 NIR (near infrared) sensor, and I will adapt a new module to do the tests. The objective is to analyze samples of plant leaves and verify their health status as "HEALTHY" or "UNHEALTHY".

Below you can see a video that shows working this prototype.

datasheets.zip

Sensor datasheets

x-zip-compressed - 1.23 MB - 09/10/2023 at 05:38

Download

stl_files.zip

3D files in STL format

x-zip-compressed - 9.59 kB - 09/10/2023 at 05:36

Download

  • 1 × Raspberry Pi 4B
  • 1 × Raspberry Pi 3B+
  • 1 × AS7262 6-channel Visible Light Sensor
  • 1 × AS7263 NIR Sensor
  • 1 × Qwiic pHAT module

View all 8 components

  • 3. Building A Filter Spectrometer

    Guillermo Perez Guillen09/10/2023 at 03:24 0 comments

    In this chapter I will show you how to assemble a filter spectrometer, as well as the first tests with the six colors that the AS7262 sensor detects. Personally I can tell you that this project is exceeding my expectations since it works fine.

    Device Assembly

    I used 3mm MDF board to build the filter spectrometer, as it has good tamper resistance and because it would allow me to experiment until I got the right dimensions to mount the AS7262 sensor. Below I show you the cuts I made.

    The dimensions of the large strips are 20(W) x 60(L)mm, and the short ones are 20(W) x 20(L)mm. I have then joined them with Kola Loka glue as shown below.

    The "U" shaped figure is placed in the middle of the "O" shaped figures. I have also put a base of 75(W) x 75(L)mm as shown in the image below.

    I have used wood sandpaper to reduce the protruding edges. In the end I have mounted the sensor by means of a 20(W) x 45(L)mm strip as shown in the following image.

    You should also consider using a drill and silicone, as well as having four screws. Here, I think I spent more time trying to center the sensor.

    Schematic

    I have carried out three experiments, which I describe below. The first two I have repeated the examples of the installed library, and the third example is a modification that I have made to capture data in a text file for future analysis.

    Library Installation

    I have installed the library from the following github repository: https://github.com/pimoroni/as7262-python

    It is a stable library and you just have to enter the following command:

    python3 -m pip install as7262

    Additionally, I have installed the following library that is used for the AS7262 (visible light) and AS7263 (infrared light) sensors: https://github.com/HeyLlama/as726x-python

    git clone https://github.com/pimoroni/as7262-python
    
    cd as7262-python
    
    sudo ./install.sh --unstable

    Spectrum

    Below I show you the code of this example. Here we obtain the values of the spectrum of visible colors detected by the sensor (violet, blue, green, yellow, orange and red). Note that the AS7262 sensor has a 16-bit ADC, so it measures an integer part and a decimal part.

    spectrum.py

    
    
    
    

     Before the test, I show you the colored filter strips that I used in my experiment. I have used strips of paper with color on both sides with the dimensions of 20(W) x 50(L)mm. Through experimentation, I discovered that sometimes inserting one color strip was enough, and in other cases two or three color strips were inserted to detect color satisfactorily.


    Bar Graph

    The following code shows us a bar graph of colors detected. Unlike the previous experiment, this one shows us the values qualitatively. In this way we can deduce that the filter absorbs one or more colors, and they are the same colors that the sensor detects.

    bargraph.py

    
    
    
    

    Below is an example of the graph obtained for the blue filter.

    Data Captured

    Here we use the AS7262 functions to operate the board. It begins with some initial setup, and then puts the board into measurement mode 2, which continuously takes measurements for all colours. This is returned as a list called "results", which is then printed in a mostly human-readable form. Additionally, a text file is created to save the sensor values each interaction, and the script is interrupted when we use Ctrl+C.

    datacaptured.py

    
    
    
    

     Below I show you an example of data captured for the green filter.

    My idea is to use this data to make graphs in excel and analyze the information statistically.

    Conclusion

    According to what was seen in chapter one (introduction), a part of the light emitted by the lamp reaches the AS7262 light sensor due to diffraction. Next I show you the most important conclusions with the color filters.

    • A blue filter weakens the yellow, orange and red signals very strongly.
    • In contrast, a red filter will block blue and green...
    Read more »

  • 2. Getting Started

    Guillermo Perez Guillen09/10/2023 at 02:43 0 comments

    In this chapter I will show you the main features of Raspberry Pi 3B+, Qwiic pHAT module and AS7262 sensor. Also we learn how to setup the Raspberry Pi and how to detect the peripheral of the sensor.

    Raspberry Pi 3B+

    The Raspberry Pi 3 B+ provides you with the same Pi as before, but now with gigabit and PoE capable Ethernet, as well as better overheating protection for the 64-bit processor. This computer small has a Broadcom BCM2837, an ARM Cortex-A53 64-bit Quad Core Processor System-on-Chip operating at 1.4GHz. The GPU provides OpenGL ES 2.0, hardware-accelerated OpenVG and 1080p30 H.264 high-profile decode. It is capable of 1Gpixel/s, 1.5Gtexel/s or 24 GFLOPs of general-purpose compute. 

    • Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz
    • 1GB LPDDR2 SDRAM
    • 2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE
    • Gigabit Ethernet over USB 2.0 (maximum throughput 300 Mbps)
    • Extended 40-pin GPIO header
    • Full-size HDMI
    • 4 USB 2.0 ports
    • CSI camera port for connecting a Raspberry Pi camera
    • DSI display port for connecting a Raspberry Pi touchscreen display
    • 4-pole stereo output and composite video port
    • Micro SD port for loading your operating system and storing data
    • 5V/2.5A DC power input
    • Power-over-Ethernet (PoE) support (requires separate PoE HAT)

    SparkFun Qwiic pHAT v2.0 

    The SparkFun Qwiic pHAT connects the I2C bus (GND, 3.3V, SDA, and SCL) on your Raspberry Pi to an array of Qwiic connectors on the HAT. Since the Qwiic system allows for daisy-chaining boards with different addresses, you can stack as many sensors as you’d like. The Qwiic pHAT V2.0 has four Qwiic connect ports (two on its side and two vertical), all on the same I2C bus. It also add a simple 5V screw terminal to power boards that may need more than 3.3V and a general-purpose button. This pHAT is compatible with any Raspberry Pi that utilizes the standard 2x20 GPIO header.

    • 4x Qwiic Connection Ports
    • 1x 5V Tolerant Screw Terminal
    • 1x General Purpose Button
    • HAT-compatible 40-pin Female Header

    AS7262 6-channel Visible Light Sensor

    The SparkFun AS7262 spectrometer detects wavelengths in the visible range at 450, 500, 550, 570, 600 and 650nm of light each with 40nm of full-width half-max detection. The board also has multiple ways for you to illuminate objects that you will try to measure for a more accurate spectroscopy reading. There is an onboard LED that has been picked out specifically for this task, as well as two pins to solder your own LED into. The AS7262 Breakout is unique in its ability to communicate by both an I2C interface and serial interface using AT commands.

    • 6 visible channels: 450nm, 500nm, 550nm, 570nm, 600nm and 650nm, each with 40nm FWHM
    • Visible filter set realized by silicon interference filters
    • 16-bit ADC with digital access
    • Programmable LED drivers
    • 2.7V to 3.6V with I2C interface
    • 2x Qwiic connectors

    Applications: 

    • Visible spectrometry.
    • Spectral Color Matching and monitoring
    • Authentication and counterfeit detection
    • Detection of color mixture effects (e.g. textiles, paints, etc.)
    • Fluid monitoring and analysis (using reagents)
    • ID marker detection

    Below you can see the spectral responsivity of this sensor.

    Configuring the Pi

    To get started with your Qwiic pHAT, simply plug it into the headers on the Raspberry Pi with the letters facing you. We'll use the Qwiic pHAT v2.0 in the following image to connect a Qwiic device.

    Once the pHAT is plugged in, you can start plugging in AS7262 6-channel Visible Light Sensor.

    The Raspberry Pi Configuration via Desktop GUI

    You can use the Desktop GUI by heading to the Pi Start Menu > Preferences > Raspberry Pi Configuration. A window will pop up with different tabs to adjust settings. What we are interested is the Interfaces tab. Click on the tab and select Enable for I2C. Click on the OK button.

    imageIt's recommend restarting your Pi to ensure that the changes to take effect....

    Read more »

  • 1. Introduction

    Guillermo Perez Guillen09/10/2023 at 02:33 0 comments

    Optics

    I assume you already have basic knowledge of optics. Optics is the study of light. Optics describes how light is created and how it travels. An important part of optics is the study of what happens when light hits different surfaces. When light hits a surface, it may be reflected, refracted, or absorbed.

    • Reflection occurs when light hits a surface and bounces back. Reflected light makes images appear in mirrors and in other smooth, shiny surfaces.
    • Refraction happens when light changes direction, or bends, when it moves from one material to another. For example, light traveling through the air refracts when it hits water. This can make a straw in a glass of water look bent at the surface of the water.
    • Some surfaces absorb, or take in, light. This causes the surface to heat up. For example, a sidewalk heats up on a hot, sunny day because it is absorbing light.

    Spectrophotometry

    Spectrophotometry is the quantitative measurement of the interaction of ultraviolet (UV), visible, and infrared (IR) radiation with a material and has an impact on a wide field of science and technology.  Spectrophotometry uses photometers, known as spectrometers, that can measure the intensity of a light beam at different wavelengths. 

    Types of spectrometers:

    • Infrared spectrum: study and identification of chemical substances
    • Ultraviolet spectrum: identification of molecules, black light.
    • NMR spectrometer: atomic/nuclear absorption.
    • Reflectance spectrometer: this is the spectrum used in paint and body shops to measure color (konica minolta, etc.)
    • Double beam spectrometer.
    • Single beam spectrometer. A double-beam spectrometer compares the light intensity between two light paths, one path containing a reference sample and the other the test sample. A single-beam spectrometer measures the relative light intensity of the beam before and after a test sample is inserted. Although comparison measurements from double-beam instruments are easier and more stable, single-beam instruments can have a larger dynamic range and are optically simpler and more compact. Additionally, some specialized instruments, such as spectrometers built onto microscopes or telescopes, are single-beam instruments due to practicality.

View all 3 project logs

  • 1
    Software apps and online services
    • Python
    • ThingSpeak IoT Platform
    • Excel
  • 2
    Hand tools and fabrication machines
    • 3D Printer
    • Drill
    • Soldering iron
    • Silicone
    • Glue
    • Screws

View all instructions

Enjoy this project?

Share

Discussions

Guillermo Perez Guillen wrote 09/10/2023 at 20:39 point

This project fits "Save the World Wildcard" challenge, since it is a kit that can be useful for both re-engineering education and green hacks topics... this is an open source kit that will grow in the future

  Are you sure? yes | no

zyndram wrote 09/10/2023 at 14:20 point

You are planing create more mobile device?

O64+hat or raspberry pi zero + Hat etc

  Are you sure? yes | no

Guillermo Perez Guillen wrote 09/10/2023 at 20:15 point

Thank you for your comment... your idea is good and in the future I will make those improvements

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates