Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Leon Scurtu
Published

UV lamp, self activation, based on UV level.

UV lamps help tremendously with growing plants. Pair that with a UV sensor to prevent overusing the lamp, and you can grow anything you want

BeginnerShowcase (no instructions)6 hours66
UV lamp, self activation, based on UV level.

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×7
hanging lamp
×1
uv bulb
×1
Hitec RCD 31425S HS-425BB Pro BB Servo
×1
waveshare Digital LTR390-UV Ultraviolet Sensor (C)
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Story

Read more

Custom parts and enclosures

Cardboard

Carboard half box that helps servo stay grounded so that it can spin and hit the switch, I just taped the servo down and the switch on the carboard, then I bent the carboard so that the servo meets the switch at a 90 degree angle.

Schematics

UV sensor wiring, and servo wiring.

I have broken it down into two photos where the wires for one of the two components are on the Arduino. On the left side, you will need 4 jumper wires that have one female and one male end to connect with the Arduino. I have color-coded the wires and labeled them. Purple will go to 3.3V, orange to GND, yellow to SCL, and blue to SDA. This will connect your Arduino to the UV sensor. For the right side, you will need 3 male wires. The black one will go to GND, the red one will go to 5V, and the yellow one will go to pin 6.

Code

Code for everything

C/C++
It is the code that allows for the servo to turn if the UV sensor dectes there is not enough UV for a plant, the servo will then turn activating the lamp it will keep checking to see if there is enough UV, if yes the servo will turn again turning of the lamp.
#include <Wire.h>
#include <LTR390.h>
#include <Servo.h>

LTR390 ltr390(I2C_ADDRESS);
Servo myServo;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  myServo.attach(SERVO_PIN); // Attach the servo to pin 5

  if (!ltr390.init()) {
    Serial.println("LTR390 not connected!");
  }

  ltr390.setMode(LTR390_MODE_ALS);
  ltr390.setGain(LTR390_GAIN_3);
  Serial.print("Gain : ");
  switch (ltr390.getGain()) {
    case LTR390_GAIN_1: Serial.println(1); break;
    case LTR390_GAIN_3: Serial.println(3); break;
    case LTR390_GAIN_6: Serial.println(6); break;
    case LTR390_GAIN_9: Serial.println(9); break;
    case LTR390_GAIN_18: Serial.println(18); break;
  }
  
  ltr390.setResolution(LTR390_RESOLUTION_18BIT);
  Serial.print("Resolution : ");
  switch (ltr390.getResolution()) {
    case LTR390_RESOLUTION_13BIT: Serial.println(13); break;
    case LTR390_RESOLUTION_16BIT: Serial.println(16); break;
    case LTR390_RESOLUTION_17BIT: Serial.println(17); break;
    case LTR390_RESOLUTION_18BIT: Serial.println(18); break;
    case LTR390_RESOLUTION_19BIT: Serial.println(19); break;
    case LTR390_RESOLUTION_20BIT: Serial.println(20); break;
  }
}

void loop() {
  if (ltr390.newDataAvailable()) {
    if (ltr390.getMode() == LTR390_MODE_ALS) {
      Serial.print("Ambient Light Lux: "); 
      Serial.println(ltr390.getLux());
      ltr390.setGain(LTR390_GAIN_18);                  // Recommended for UVI - x18
      ltr390.setResolution(LTR390_RESOLUTION_20BIT);   // Recommended for UVI - 20-bit
      ltr390.setMode(LTR390_MODE_UVS);             
    } else if (ltr390.getMode() == LTR390_MODE_UVS) {
      float uvIndex = ltr390.getUVI();
      Serial.print("UV Index: "); 
      Serial.println(uvIndex);

      // Control the servo based on the UV index
      if (uvIndex < 0.10) {
        myServo.write(20); // Move servo to position 0
        delay(500);         // Wait for 500ms
      } else {
        myServo.write(160); // Move servo to position 180
        delay(500);          // Wait for 500ms
      }

      ltr390.setGain(LTR390_GAIN_3);                   // Recommended for Lux - x3
      ltr390.setResolution(LTR390_RESOLUTION_18BIT);   // Recommended for Lux - 18-bit
      ltr390.setMode(LTR390_MODE_ALS);
    }
  }
}

Credits

Leon Scurtu
2 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.