Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. GUVA-S12SD UV sensor sketch

GUVA-S12SD UV sensor sketch

Scheduled Pinned Locked Moved My Project
2 Posts 1 Posters 980 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tonbor
    wrote on last edited by
    #1

    Re: [0_1534265394169_UVSensor.ino](Uploading 100%) GUVA-S12SD UV sensor sketch required

    [0_1534265424506_UVSensor.ino](Uploading 100%)

    T 1 Reply Last reply
    0
    • T tonbor

      Re: [0_1534265394169_UVSensor.ino](Uploading 100%) GUVA-S12SD UV sensor sketch required

      [0_1534265424506_UVSensor.ino](Uploading 100%)

      T Offline
      T Offline
      tonbor
      wrote on last edited by tonbor
      #2

      /**

      • DESCRIPTION
      • Sensor: CJMCU-GUVA-S12SD/CJMCU-S12D
      • Sensor Arduino
      • SIG -> A0
      • GND -> GND
      • VCC -> 5V or 3.3v
      • part created by Henrik Ekblad henrik.ekblad@mysensors.org
      • Copyright (C) 2013-2015 Sensnology AB
      • Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
      • part Original link : CSDN 博客链接.
      • part by Tonbor august 2018
        */

      // Enable debug prints to serial monitor
      #define MY_DEBUG

      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_NRF5_ESB
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95

      #include <MySensors.h>

      #define UV_SENSOR_ANALOG_PIN 0

      #define CHILD_ID_UV 0

      uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)

      MyMessage uvMsg(CHILD_ID_UV, V_UV);

      int lastSend =0;
      int sensorValue;
      long sum = 0;
      int vout = 0;
      int uv = 0;
      int lastUV = -1;

      void presentation()
      {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("UV Sensor", "1.3");

      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_UV, S_UV);
      

      }
      void setup() {
      Serial.begin(115000);
      }
      void loop()
      {
      uint32_t currentTime = millis();
      sensorValue = 0;
      sum = 0;
      for (int i = 0 ; i < 1024 ; i++ ) {
      sensorValue = analogRead(UV_SENSOR_ANALOG_PIN);
      sum = sensorValue + sum;
      delay(2);
      }
      vout = sum >> 10;
      vout = vout * 4980.0 / 1024;
      Serial.print("The Photocurrent value:");
      Serial.print(vout);
      Serial.println("mV");
      if (vout < 50) {
      uv = 0;
      }
      else if (vout < 227) {
      uv = 1;
      }
      else if (vout < 318) {
      uv = 2;
      }
      else if (vout < 408) {
      uv = 3;
      }
      else if (vout < 503) {
      uv = 4;
      }
      else if (vout < 606) {
      uv = 5;
      }
      else if (vout < 696) {
      uv = 6;
      }
      else if (vout < 795) {
      uv = 7;
      }
      else if (vout < 881) {
      uv = 8;
      }
      else if (vout < 976) {
      uv = 9;
      }
      else if (vout < 1079) {
      uv = 10;
      }
      else {
      uv = 11;
      }

      //Send value to gateway if changed, or at least every 5 minutes
      if ((uv != lastUV)||(currentTime-lastSend >= 5UL*60UL*1000UL)) {
      	lastSend=currentTime;
      	send(uvMsg.set(uv));
      	lastUV = uv;
      }
      
      sleep(SLEEP_TIME);
      

      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      31

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular