Wiring Together the Hardware: Integrating the Light Sensor

Light is a fundamental element for plant growth, making the integration of a light sensor a crucial step in garden monitoring projects like GardenPi. This guide will walk you through the high-level explanation, wiring, and testing of a light sensor with your Raspberry Pi.

Understanding the Role of a Light Sensor in GardenPi

  • Purpose: A light sensor measures the intensity and duration of sunlight exposure, which is vital for understanding and optimizing plant growth conditions.

  • Benefits: With accurate light data, you can adjust plant positioning, watering schedules, and even simulate natural light conditions for indoor gardens.

Connecting the light sensor to your Raspberry Pi involves a few straightforward steps

Step 1: layout your components

  • the LM393 Light sensor

  • wires

  • and your Raspberry Pi we have been working with

Step 2: connect the lm393

Image of LM393 Sensor

With the Raspberry Pi off and referencing the above LM393 and the below Raspberry Pi pinout diagrams, connect the sensor to your Raspberry Pi using the jumper wires. Typically, you'll need to connect the VCC pin to 3.3V on the Raspberry Pi, GND to GND, and DO to SDA (GPIO 2).

In our case we are wiring the power to the breadboard and the data to the pi. Steps for wiring the LM393 sensor to the breadboard and raspberry pi:

  1. Connect the LM393 VIN/VCC (3.3v) pin to the right side positive energy on the bread board to power the board

  2. Connect the LM393 Ground pin to the right side negative energy on the bread board

  3. Connect the LM393 DO pin to the GPIO4 pin (fourth pin left column) on the Raspberry Pi

Following the steps above, your setup should now look similar to the diagram below (not exact because I couldn’t find the exact sensor in Fritzing):

step 3: Testing the Light Sensor with the Raspberry Pi

Once everything is wired and set up, we can now use the below Python script to test if the Raspberry Pi is reading data correctly from the LM393 sensor

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
for i in range(0,10):
    print(GPIO.input(4))
    print(' reading\n')
    time.sleep(5)

Copy the above into a notepad text document or (use an editor like VSCode) and name it something such as ‘lm393Test.py’.

Power on the raspberry pi device and connect to it from the PC using WinSCP. Copy the lm393Test.py file onto the raspberry pi and then use terminal to run it. Example:

sudo python3 lm393Test.py

This should print either 0 or 1 and ‘reading’ every 5 seconds. If not, go back and redo the steps leading to this point. Control the light and tune the in-sensor dial using a Philips head screwdriver to tune the appropriate light level. Hit Ctrl-C when you want to stop the script. Once the light sensor is tested tuned, the physical construction and testing of the device. Now we can proceed to setup the database and data collection scripts.

Previous
Previous

Database Schema and Setup: The Backbone of GardenPi

Next
Next

Wiring Together the Hardware: Integrating the Amospheric Sensor