How to Make Almost Anything

My journey through the MIT course

Week 2: Embedded Programming

This week's task was to write a program for a microcontroller development board to interact (with local input &/or output devices) and communicate (with remote wired or wireless devices)

Introduction and Objective

My objective for Week 2 was to explore the measurement of light intensity for plants, specifically focusing on Photosynthetically Active Radiation (PAR). Due to the high cost of specialized PAR measuring devices, I decided to follow Anthony's advice and experiment with a more accessible phototransistor light sensor. He also walked me through the desired circuit layout, shown below.

Circuit Layout

Sensor Exploration and Circuit Setup

After discussing with Anthony, I set up a circuit using a phototransistor light sensor on a breadboard, connected to a XIAO RP2040 microcontroller. The circuit is designed to measure light intensity within a certain range. Below is the image of the breadboard setup.

Breadboard Setup with Light Sensor

Programming the Microcontroller

To retrieve data from the light sensor, I programmed the XIAO RP2040 development board. The code captures light intensity readings and outputs them to the serial monitor. The block of code used is shown below.

      int analogValue = 0;  // Variable to store the analog input value
      int sensorPin = A0;   // select the input pin for the potentiometer
      
      void setup() {
        // Initialize Serial communication
        Serial.begin(9600);
      }
      
      void loop() {
        // Read the analog input on pin A0
        analogValue = analogRead(sensorPin);
      
        // Send the analog value to the Serial Monitor
        Serial.println(analogValue);
      
        // Wait a bit for better readability
        delay(100);
      }
    

Results

The serial monitor displays the light intensity readings from the sensor. An image of the serial monitor displaying the light intensity readings is shown below.

Serial Monitor Output

Observations and Reflections

The experiment with the phototransistor sensor provided valuable insights into measuring light intensity for plants. Although it does not specifically measure PAR, it serves as a foundational step in understanding light measurement techniques and embedded programming.

Conclusion and Future Steps

This week's project was instrumental in enhancing my understanding of embedded programming and its application in horticulture. Going forward, I plan to further explore and possibly integrate more precise sensors for measuring PAR in my gardening projects.