Solar Powered Mini-Weather Station



  • @Totche, the original 3v7, 1000mAh lion battery is tucked under the circuit board. You can see the arch of the plastic cover toward the bottom of the picture on the left, just below the DHT22. It is connected to the circuit with the black and red wired connector so it can easily be removed when working with the device.



  • Hi, did you feed the NRF24L01 directly from the 3.7 V battery? The specs are alowing 3.6 V max?!? And you are taking about a maximum output of over 4 V of the battery.
    That sound not healthy for the NRF.



  • @Andreas-Maurer You can connect the NRF24 on the VCC out from the arduino. because he used an arduino nano pro on 3.3 volt. and the arduino can handle voltages from 3.3 to 12 DC.



  • Hi, I have my weatherstation up and running. The only problem is my rainsensor. It's totally not accurate. Do you have the same?

    Floris



  • @floris, you have to adjust the sensitivity of the rain sensor. I splashed some water on the sensor pad and used a small screwdriver to adjust the potentiometer on the interface board until it triggered to my satisfaction. It took a few iterations to get it to trigger at the level I was looking for.



  • @Salmoides
    How is this sensor performing? I assume it has to be mounted where it can receive direct sunlight for charging the solar panel. Do you have problems with sunlight heating the enclosure and elevating temperature readings? I intercept readings from my neighbor's 433Mhz outdoor sensor and the temperature soars when the sensor is under direct summer sunlight.



  • @Salmoides great thread and project

    Was trying to follow the wiring on the back side of the board to wire my project and was wondering how you wrap the wires around the posts sticking through the board for soldering.
    Also is there a wiring diagram?



  • @5546dug Wire wrapping is done with a wire wrapping tool, it is done in lieu of soldering and can be easily undone or 'unwrapped'. It was very common for prototyping in the past.



  • @Dwalt Thanks for info but the slant I get from you is this is the old way and now it is just plain soldering.
    I also see wire size is an issue.


  • Hero Member

    @Salmoides said:

    Then I found this.

    SolarLight.jpg

    It’s entitled “16 LED Solar Power Motion Sensor Security Lamp Outdoor Waterproof Light” (http://www.ebay.com/itm/271693521438) that you can get for $9.00. I now had a $21 weather station ready to be built.

    Taking apart the lamp, I removed the LED panel (worth at least $2.00) and the control board (this has some good stuff on it like a PIR, a light sensor, and the battery charging circuitry, but its use is well beyond my skills), and put them away for another project.

    @Salmoides I mesure less than 1 V at the solar panel wires, which cannot power up the regulator for the arduino.

    Do you have the same mesure ?


  • Hero Member

    @epierre said:

    @ mesure less than 1 V at the solar panel wires, which cannot power up the regulator for the arduino.

    Do you have the same mesure ?

    I have a couple of these units as well and just checked one. It's a cloudy day, but under a bright light it reported 4.3V at the solar panel wires. You might have a bad unit.

    Cheers
    Al


  • Hero Member

    @5546dug I am using wire wrap as well (well, I am old...). The upside of wirewrap is that it does not require electricity, very zen like, you can't make fatal mistakes and you can rescue or replace an arduino without a reflow station. the downside is that there is a limit to the currents (its not bad, but don't try to wire 220v, 3A using wire wrap...), there is a limit to the amount of wires that go to the same post and at times it is slower than soldering (for someone who is practiced). it is very very good for prototyping.


  • Hero Member

    @Sparkman strange for I tested again and this was good...



  • @Salmoides I have tried compiling this code you supplied in the thread prior to uploading to the promini, but it has an issue with the bmp180 code , it cannot read the sea level pressure. I see you set your altitude at 221 meters but I am not able to comprehend the error code on line 101.
    enclosed is the screen shot of the issue.
    I use ver 1.4 and lib 1.4



  • Screenshot (53).png
    So dumb of me to forget screenshot



  • just not sure where the readSealevelPressure(altitude) parameter is found
    I donot see it in the sketch and cannot find it in github



  • It's defined in the Adafruit_BMP085 library .cpp file. Did you include the library?



  • I used the supplied code from @Salmoides first reply in this thread.



  • Edit

    @Pieter-Jan-Stiers , I have tried various combinations of the " include " line in the setup for BMP085 sensor part and it will not compile.

    I tried adding the file Adafruit_BMP085_Unified-master.h but the sketch said no such file existed.
    However I did download and extract from github and put it in the file ....users/documents/arduino/libraries, I see it in the IDE but that is all
    see screen shot at the moment I have it commented out and sketch still does not find read SealevelPressure

    Any ideas? As I said I am using the sketch from the first post in this thread from @Salmoides

    Do I need to create in setup the line

    include <Adafruit_BMP085.cpp>

    Screenshot (56).png


  • Hero Member

    Did you close & reopened Arduino IDE after you placed the new library?



  • Yes
    Is file placed is the right area?


  • Hero Member

    You can also try it via the menu 'Sketch -> Import Library ... '

    Also make sure you are method readSeaLevelPressure is spelled exactly like it is defined in the .h file...



  • @rvendrame I seem to beat a loss as to what to do next
    I tried putting the file thru the >file import method and still I get error messages saying cant compile as above.
    When I include the unified file there are additional errors all above my paygrade.
    I have messed with the line readSealevelPressure<altitude> and the include lines but get nowhere.
    I think there is reference to this in original .cpp file but # including this is also errors.
    I have remane the files after saving and rebooted ide a few times ...no luck.

    a
    Any ideas or is the file from @Salmoides not compatable anymore?



  • here is a screen shot of the latest errScreenshot (57).png or code(s)


  • Hero Member

    How is your 'Sketchbook location' defined? (in "preferences...") Looking into the error message, it looks you are mixing windows slash "\" and unix slash "/" ...



  • After consultation in the troubleshooting category, I downloaded afresh copy of Adafruit-BMP085-library into my arduino library overwriting what was there and now code compiles.
    So on to uploading the code to promini and see what the next issue might/will be.



  • @Salmoides Hi Salmoides,
    Great Project!!

    I had the sensors and was looking for a project like this!

    I got it to run on the breadboard, and sync with domoticz. and the plan is to power it out with some 18650 cells+solar panel, but i have some questions for you.

    1. aren't you using any resistors for the i2c sensors? or the dht22?
    2. how hare you connecting the battery? when fully charged it can go up to 4.2v i belive this whould burn some sensors.. are you connecting it to the arduino raw pin and feeding the sensors with the regulated 3.3v pin!?
    3. the potentiometer, are you using it only as a resistor? or are you regulating it?

    thanks for sharing, and here are some screenshots of my implementation.

    QuarterSizeRender.png
    domoticz_solar.png



  • I don't seem to be able to get the DHT22 working. I have stripped this project down to the following prototype, and am still not able to get the DHT22 to work. I'm using the DHT example (not MySensors) script and continue to get timeout errors for both Temp and Humidity. I have tried a 4.0k ohm, 10k omh and no resistor.

    DHT22 Solar_bb.png

    I am just wanting to know if I might be missing something, and to also verify that other people have got the DHT22 working with a Arduino Pro Mini 8mhs - 3.3 volt using its regulated vcc pin. I have ordered new DHT22 modules from a different source just to see what happens.

    Thanks in advance for any input.


  • Hardware Contributor

    One thing comes to mind is that DHT has 3.3v as minimum power.
    If you have a "weak" pro mini board delivere power below that maybe is a problem. Can you measure the power?

    I have a 3.3v pro mini running a DHT22 fine, so it should work - but I also know there is a big difference in different hardware even if its called pro mini.



  • @gbfromhb I did not use the resistor and no Vcc connection through it to D4.
    My output is straight to pro mini.
    Vcc and gnd make up the other two connections.



  • @5546dug thanks for the input. I had also tried it with 4k ohm, 10k ohm and no resistor and connection to VCC to pin 2 of the DHT.

    @sundberg84 thanks for your input as well. I tried two different Pro Minis also, but from the same supplier. I think I'm going to go after a new Pro Mini from a different supplier.


  • Mod

    @gbfromhb I seemed to have similar problems as you using the DHT22 (Straight from China, marked AM2302). Reported 2% hudity and 0 degrees, with data line directly connected to pin3 (no pullup) on 8MHz Pro Mini.
    Switched from the MySensors DHT library to this one: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib
    Now works like a charm with the dht22_test.ino sketch:

    dht22_test.ino
    LIBRARY VERSION: 0.1.20
    
    Type,	status,	Humidity (%),	Temperature (C)	Time (us)
    DHT22, 	OK,	45.4,	25.9,	5216
    DHT22, 	OK,	45.7,	26.0,	5240
    DHT22, 	OK,	45.6,	26.0,	5136
    DHT22, 	OK,	45.4,	26.0,	5128
    DHT22, 	OK,	45.3,	26.1,	5176
    DHT22, 	OK,	45.1,	26.1,	5176
    ... etc ...
    
    

    You could give this library a try; it might work with yours!



  • @Yveaux thank you for the information. I was going to post my solution tomarrow morning. I found first the library you had suggested, and found a second one that I settled on. Yesterday my top thought on this was it was a timing issue, and the slower 8Mhz pro mini. I had ruled out voltage as the issue. The library you directed me in their last revision addressed timing issues with slower clock speeds. It did work great. I did find a different one that seems to have a few more functions that I need and it seems to work great also.

    https://github.com/adafruit/DHT-sensor-library

    I seemed to get more accurate temperature when I put a 10k ohm resistor between pin 1 and 2 on the DHT22.


  • Mod

    @gbfromhb Good to hear you've sorted things out!
    I'll give the Adafruit lib a try someday.


  • Admin

    If/when you guys have evaluated the best DHT library, maybe we should update the one distributed in the MySensors bundle?


  • Mod

    @hek tricky, as we seem to be the only ones having issues with the library included with MySensors. I only have one DHT22 so I cannot test with other sensors...



  • @hek I think this is a good idea to update the DHT library that is being distributed. I have tried the DHT11 & DHT22 on both of these these libraries and they seem to work. It is pretty interesting the revision logs for both of these have addressed lower clock speed issues that were resolved in different versions, and the current library that is being distributed has not been touched for over over 2 years. The library that @Yveaux is using has been updated in that last 6 months, and the one I'm currently using has been updated in the last month. Both of these libraries have been around for 3 or 4 years. There is also one more library that I was looking at that I have not tried and that is: https://github.com/piettetech/piettetech_dht.

    I choose the one I did, because it had some functions that enabled me to work with Fahrenheit easier.

    I don't think we are the only ones that have had issues with the DHT library that have been resolved by changing library. Take a look at the bottom of this post:
    http://forum.mysensors.org/topic/1894/pro-mini-is-giving-a-frequent-time-out-on-dth11-read-out/8


  • Admin

    Yep, would be great if someone had time to evaluate the different options and get back to me with a suitable choice.



  • Please add an wiring diagram. Especially for the solar panel, battery and connection to the Nano.



  • @5546dug Have you a wiring diagram?



  • I've build something like this that logs temperature to an SD card, so no radio or gateway involved. Been getting NaNs from my DHT22 every few readings since I switched from a 5v Pro Mini to a 3.3v one. This never happened on the 5v one, so I guess I'll try switching library as well!



  • @hek I like the following library https://github.com/adafruit/DHT-sensor-library (ladyada).

    This seems to be working fine with the Arduino Pro Mini 8mhz.
    Here is a MySensors example using this library:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * Version 1.1 - Glenn Byron - September 6, 2015 - Converted to new DHT library written by ladyada 
     * 
     * DESCRIPTION
     * This sketch provides an example how to implement a humidity/temperature
     * sensor using DHT11, DHT21, DHT-22 
     * http://www.mysensors.org/build/humidity
     */
     
    #include <SPI.h>
    #include <MySensor.h> 
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 2
    #define DHTTYPE DHT22
    // DHTTYPE choices: DHT11, DHT21, DHT22
    
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    MySensor gw;
    DHT dht(HUMIDITY_SENSOR_DIGITAL_PIN, DHTTYPE);
    float lastTemp;
    float lastHum;
    boolean metric = false; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()  
    { 
      Serial.begin(115200);
      Serial.flush();
      Serial.println("MySensors: DHT example");
      
      gw.begin();
      dht.begin();
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Humidity", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      
      metric = gw.getConfig().isMetric;
    
      delay(2000);
    }
    
    void loop()      
    {  
      float temperature = dht.readTemperature(!metric);
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("Temperature: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.readHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("Humidity: ");
          Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    


  • @Bazeman

    If i'm not mistaken, the solor panel is directly connected to the power input of the solar charger. @Salmoides wired a mini/microUSB to the power cables to make it easy connect/disconnect. It's this one, from what I can see in the pictures. http://www.aliexpress.com/item/5PCS-Micro-USB-5V-1A-18650-Lithium-Battery-Charger-Board-With-Protection-Module/1852341893.html

    From there, it's pretty straight forward. The battery is connected to the B+ and B- leads. The OUT+ and OUT- would be connected to the VIN/RAW and GND on your Nano, respectively.



  • The lamp is not shipped to NL and many other countries 😒 . Did anyone find it in Europe?



  • In The Netherlands they used to have it at Action .
    But haven't been there lately


  • Hero Member



  • There seems to be a similar one for sale right now at groupdeal.nl
    but just for another 9 hours or so...


  • Plugin Developer

    I really liked this project (@Salmoides ThankYou for sharing it)
    Expecially the solar powered box.

    I've successully prototyped one, but would like to report something to pepople trying to also make this.

    The solar panel included in the box, is outputting 6V, while the Charger board is sized to acced only 5V as input.
    The consequence, is (at least on my prototype) that when there is enought sun, the charger board don't charge the battery (the blue led lights on, and the red seems to vibrate slighty : I guess this is a "protection mode" when VCCin is to high). If i remove the solar panel, and put a usb cable in the charger input, then the RED led lights on, and the barrety is being charged.

    I guess that slighly modifying the charger board, would allow it to accept 6V as input, but this is too far from my electronic skills (Anyone?)

    As a workaround, I've ordered a StepDown module to reduce the 6V provided by the solar panel to 5V for the charger input. I guess It will do the job. I will report back as soon as I get the StepUp module from china.

    HTH those interested in this excellent project.

    BTW @Salmoides , How did you solved it? Does your Solar panel outputs 5V, instead of 6V? Does your charger works with 6V input (might be slighly diffrent board or mine has an issue)? Did you modified the charger or added extra component to reduce the input voltage ?

    Cheeers to evereyone !


  • Mod

    @soif said:

    StepDown module to reduce the 6V provided by the solar panel to 5V for the charger input.

    Put one or two silicon diodes in series with the solar panel. Each diode will lower the voltage by approx 0.7volts


  • Plugin Developer

    @Yveaux thank you for the amazing fast and really helpful answer.

    Droping the voltage by 0.7v would certainly change the charger beahaviour to behave properly, and not be in "protection mode", Definitively better than inserting a stepDown module.
    I assume that I put the diode in serie from the VCC+ out of the Solar panel TO the VCC+ IN of the charger (right?), ie:
    Solar VCC out ------ --->| ---- Charger VCC in.

    3 questions:

    • Is there any diode reference recommendation, or any value do the job (1N400x) ?
    • Will the diode "eat" some current, ot just drop the voltage -0,7v. ?
    • BTW what is a "Silicon" diode?

    thank you very much for your valuable support !

    Berst regards,


  • Mod

    @soif Your connection idea is correct. If you mount it in reverse, it simply won't work.
    The actual voltage drop over the diode will depend on the amount of current flowing through it, so that's why you might require 2 in series.

    An 1N400x will do just fine. The higher the x, the more current it can handle.
    The diode will consume some current, but that will be less then a step-down converter.
    Most diodes nowadays use silicon as semiconductor. Years ago Germanium diodes were used, which have a lower voltage drop.

    As a reference: everything you need to know about diodes


  • Plugin Developer

    @Yveaux Thank you very much for the diode explanation, as well as the very interesting diode tutorial.
    Thanks to you, I've learned something more today.

    I'm gonna test it very soon, and will report back.


  • Mod


  • Plugin Developer

    This is similar to the one I have also bought at aliexpress 😉



  • Hello, thank you for this beautiful project.

    I have recreated it with a DHT22, a BMP180 and a BH1750FVI on a breadboard. From there everything is transferred to Domoticz via WiFi gateway. Everything is working properly. Only the light sensor makes problems ...

    The reading of the sensor gives correct values in Lux. These are sent right to the gateway. The Gateway appears to be wrong to interpret these values. It transmits incorrect values via WiFi.

    What can I do against it? Did anyone have an idea?

    I'm using MySensors 1.5 on Arduino 1.6.7.

    Thomas

    0_1454423311883_wrong_Lux.JPG



  • @Salmoides
    Hi, where i can find light pipe lie this?



  • I have one of these lights and got it with the plan of dissembling it for this very project but it was too good lol so think I'll buy another to dissect. The only disappointing thing is how the light is always on at a dim level so drains the battery. I'd much rather have it only activate on motion detection with the PIR.



  • Dear...
    Great project...[ when i got my stuff i am going to build to...

    Only how do you use the motionsensor of this light...[ new one or do you use the build in one ]
    In the sketch is can not see this motionsensor?
    Only in our Vera controller is see arm and bypass?
    Can you set the level of the lights, in vera?
    Two times temperature?
    And how is your battery action in the winter-period?



  • Hi,

    Here is the fritzing shema ; could you please tell me if it is correct before I begin the building of the weather station ?

    Thanks for your support !

    0_1457780151323_Untitled Sketch_bb.jpg



  • @Elfnoir

    This is great.....[ and great for a dummy like me ]
    Would you please tell me all the hardware you use?
    Or the strength of the resistor etc etc



  • Hi,
    The left resistor is a 1Mohm 2W(I'll confirm the power value once I'll received it), the right one is 4,7kohm, 1/4W.
    For the Hardware, I read the beginning of the post, but unfortunately I'm also a newby, and need to have a validation of this diagram, because I'm not sure if it is correct, and I don't want to burn my house if I'll do cabling mistakes 😉
    I am not able to put the file created under fritzing, but if someone wants it, tell me how to do it please.

    Thanks for your feedback!
    Regards.



  • Hi all,

    the lamp used as a basis for this desing is now frequently offered at Aliexpress. Price is around $10,-. DOn't know about quality, but looks very simular.

    Ralph



  • Hello All,
    Long time reader, first time poster.
    I've been building my-sensors in combo with Domoticz for a while now , and this project is one of my favorites.
    I can confirm that the fritzing schema is correct, i checked it against the one i build. (whish i had the schema earlier, it would have been so much easier ;-))
    I used the followin library from Rob Tillaart for the DHT22 (http://playground.arduino.cc/Main/DHTLib / https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib) because the standard was not working...
    Change line 37 to dht DHT;
    comment out line 51
    From line 78 i changed the code to this :

    delay(2000);
          int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
          temp = DHT.temperature;
                 //Serial.print("Temperature DHT :");
                 //Serial.println(temp);
          if (isnan(temp)) {
              lastTemp = -1;
          } else if (temp != lastTemp) {
            lastTemp = temp;
            if (!metric) {
              temp = temp * 1.8 + 32.0;
            }
            gw.send(msgTemp.set(temp, 1));
            }
          hum = DHT.humidity;
          if (isnan(hum)) {
              lastHum = -1;
          } else if (hum != lastHum) {
              lastHum = hum;
              gw.send(msgHum.set(hum, 1));
          }
    

    And it is working like a charm.
    Now i ordered one of these : Wind Sensor
    I want to trie to get it working with this build.
    And indeed the lamp is stil available Solar Lamp

    Hope this helps,
    With Regard's
    Peer



  • Hi,
    Thanks for your help! I'm waiting for the LiPo charger, because I purchased a wrong one to pursue my implementation...

    • Could you tell me how I can comment our line 51 please? Just like this?
      'dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
    • Also, do you have already implement the Wind Speed Module, or it's under shipment? Do you use Domoticz as domotic software? It's to know how to implement this kind of child on it?
    • Is the solar panel providing enough power to have the weather station always working? (I'm living in France on Paris latitude, and I would like to know if the quantity of sun is enough, or I need a second solar panel)
    • And it appears my Barometric Pressure sensor gave me also the humidity and temperature; Why do we have 1DHT22 and 1BMP180 ?
    • And finally, how do you deal with the battery level, as I didn't see at the beginning of this post how it is implemented inside Vera? Because I would like to implement it in Domoticz
      Many thanks for your feedback!


  • Hi,
    Commenting is done with //
    so //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
    The wind sensor is stil in shipment, so can't tell you anything about it, and i use Domoticz as controler software.
    I presume you have your gateway setup and connected, so the node should show up in domoticz with all the childs.
    I tested the the weather station only a few day's past monyh, because it is still under construction, but those day's it held out (I live near Eindhoven the Netherlands, so weather conditions are almost the same as yours ;-)).
    The battery reports through the potentiometer to A0, if the battery level = 100% the readout of A0 should be 1023 (adjustable with the portentio meter.
    Here is my sketch in total, althoug verry crude it works, it yust needs a lot of cleanup when i am done, but i need the sensor first to work.

       #include <SPI.h>
        #include <MySensor.h>  
        #include <dht.h>
        #include <BH1750.h>
        #include <Wire.h> 
        #include <Adafruit_BMP085.h>
        
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define CHILD_ID_LIGHT 2
        #define CHILD_ID_BARO 3
        #define CHILD_ID_BTEMP 4
        #define CHILD_ID_WINDSPEED 5
        #define CHILD_ID_RAIN 6
        #define CHILD_ID_RAINRATE 7    
        
        #define MESSAGEWAIT 500
        #define nRainIn A2
        #define DIGITAL_INPUT_RAIN_SENSOR 3
        #define HUMIDITY_SENSOR_DIGITAL_PIN 5
        #define ENCODER_PIN 2
        #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
    
        //int encoder_pin = 7; // pulse output from the module
        unsigned int rpm; // rpm reading
        volatile byte pulses; // number of pulses
        unsigned long timeold;
        // number of pulses per revolution
        // based on your encoder disc
        unsigned int pulsesperturn = 1;
        boolean metric = false;
        int altitude = 16; // meters above sealevel
        float lastBmpTemp = -1;
        float lastPressure = -1;
        float lastHum = -1;
        float lastTemp = -1;
        double temp;
        double hum;
        int BATTERY_SENSE_PIN = A0;
        int lastRainValue = -1;
        int nRainVal;
        boolean bIsRaining = false;
        String strRaining = "NO";
        int lastBatteryPcnt = 0;
        int updateAll = 60;
        int updateCount = 0;
        uint16_t lastLux;
        // unsigned long SLEEP_TIME = 60000;
        unsigned long SLEEP_TIME = 600;
        int batteryBasement = 800;
        float batteryConstant = 100.0 / (1023 - batteryBasement);
            
        Adafruit_BMP085 bmp = Adafruit_BMP085();
        BH1750 lightSensor;
        dht DHT;
        MySensor gw;
    
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
        MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
        MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);    
        MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
        MyMessage msgRainRate(CHILD_ID_RAINRATE, V_RAIN);
    
        void counter()
        {
          //Update count
          pulses++;
        }
    
        void setup()  
        {
          analogReference(INTERNAL);
          gw.begin(incomingMessage, 3, true);  
          //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
          bmp.begin();
          gw.sendSketchInfo("Weather Sensor", "1.0");
          gw.present(CHILD_ID_HUM, S_HUM, "WS Humidity");
          gw.present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
          gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
          gw.present(CHILD_ID_BARO, S_BARO, "WS Pressure");
          gw.present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
          gw.present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
          gw.present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
          gw.present(CHILD_ID_RAINRATE, S_RAIN, "WS RainRate");
    
          pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
          lightSensor.begin();
          metric = gw.getConfig().isMetric;
          pinMode(ENCODER_PIN, INPUT);
          //Interrupt 0 is digital pin 2
          //Triggers on Falling Edge (change from HIGH to LOW)
          attachInterrupt(0, counter, FALLING);
          // Initialize
          pulses = 0;
          rpm = 0;
          timeold = 0;
        }
        
        void loop()      
        {
          updateCount += 1;
          if (updateCount == updateAll) {
            lastTemp = -1;
            lastHum = -1;
            lastLux = -1;
            lastBmpTemp = -1;
            lastPressure = -1;
            lastRainValue = -1;
            lastBatteryPcnt = -1;
            updateCount = 0;
          }
          delay(2000);
          int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
          temp = DHT.temperature;
                 //Serial.print("Temperature DHT :");
                 //Serial.println(temp);
          if (isnan(temp)) {
              lastTemp = -1;
          } else if (temp != lastTemp) {
            lastTemp = temp;
            if (!metric) {
              temp = temp * 1.8 + 32.0;
            }
            gw.send(msgTemp.set(temp, 1));
            }
          hum = DHT.humidity;
          if (isnan(hum)) {
              lastHum = -1;
          } else if (hum != lastHum) {
              lastHum = hum;
              gw.send(msgHum.set(hum, 1));
          }
          uint16_t lux = lightSensor.readLightLevel();
          if (lux != lastLux) {
              gw.send(msgLux.set(lux));
              lastLux = lux;
          }
          float pressure = bmp.readSealevelPressure(altitude) * 0.01;
          float bmptemp = bmp.readTemperature();
          if (!metric) {
            bmptemp = bmptemp * 1.8 + 32.0;
          }
          if (bmptemp != lastBmpTemp) {
            gw.send(msgBtemp.set(bmptemp,1));
            lastBmpTemp = bmptemp;
          }
          if (pressure != lastPressure) {
            gw.send(msgPressure.set(pressure, 0));
            lastPressure = pressure;
          }
          
          nRainVal = analogRead(nRainIn);
                 Serial.print("RainVal :");
                 Serial.println(nRainVal);
          bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
                 Serial.print("Is Raining :");
                 Serial.println(bIsRaining);
          if(bIsRaining){
              strRaining = "YES";
          }
          else{
              strRaining = "NO";
          }
      
      //Serial.print("Raining?: ");
      //Serial.print(strRaining);  
      //Serial.print("\t Moisture Level: ");
      //Serial.println(nRainVal);
      //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
    
          gw.send(msgRain.set(bIsRaining));
          nRainVal = nRainVal * -1;
          gw.send(msgRainRate.set(nRainVal));
          
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
          if (lastBatteryPcnt != batteryPcnt) {
            gw.sendBatteryLevel(batteryPcnt);
            lastBatteryPcnt = batteryPcnt;
         }
    
         if (millis() - timeold >= 1000) {
            //Don't process interrupts during calculations
            detachInterrupt(0);
            rpm = (60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses;
            timeold = millis();
            Serial.print("RPM = ");
            Serial.println(rpm,DEC);
            Serial.println(pulses);
            pulses = 0;        
            rpm = rpm,DEC;
            if (rpm == 0) {
              rpm = 1;
            }
            gw.send(msgWindSpeed.set(rpm, 1));
            //Restart the interrupt processing
            attachInterrupt(0, counter, FALLING);
          }
          gw.sleep(SLEEP_TIME);
        }
    
        void incomingMessage(const MyMessage & message) {
        // We only expect one type of message from controller. But we better check anyway.
         if (message.isAck()) {
           Serial.println("This is an ack from gateway");
         }
        }```
    And there is the puls counter which i abandoned for the wind speed meter (wanted to build my own with a optocoupler, but changed my mind).
    
    Hope this is helpfull.
    Regard's 
    Peer


  • @Elfnoir,
    Could you please send me the fritzing schema, or attach it here ?
    I want to add the windmeter i bought.
    I got it today, and with a little help from google i got it working.

    Greetz Peer



  • @peerkersezuuker 0_1459719366114_Weather Station.fzz

    And thanks for your feedback and support!



  • So here it is :
    0_1459792588384_upload-3adeb2e3-0d4c-41e1-a7d7-e973e5081210

    And the code (still very rude but it works)

        #include <SPI.h>
        #include <MySensor.h>  
        #include <dht.h>
        #include <BH1750.h>
        #include <Wire.h> 
        #include <Adafruit_BMP085.h>
        
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define CHILD_ID_LIGHT 2
        #define CHILD_ID_BARO 3
        #define CHILD_ID_BTEMP 4
        #define CHILD_ID_WINDSPEED 5
        #define CHILD_ID_RAIN 6
        #define CHILD_ID_RAINRATE 7    
        
        #define MESSAGEWAIT 500
        #define nRainIn A2
        #define DIGITAL_INPUT_RAIN_SENSOR 3
        #define HUMIDITY_SENSOR_DIGITAL_PIN 5
        #define ENCODER_PIN 2
        #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
    
        const int  windSpeedPin = 2; // contact on pin 2 digital
        int windSpeedPinCounter = 0; // impuls counter
        int windSpeedPinStatus = 0; // actual impuls
        int windSpeedPinStatusAlt = 0; // oude Impuls-Status
        unsigned long windmeterStart;
        unsigned long windmeterStartAlt = 0;
        int windSpeed; // Variable voor Wind Speed
        int beaufort = 0; // Variable Wind in Beaufort
        const int windmeterTime = 10000;
        //float knoten = 0.0;
        //float wind = 0.0;
        int knoten = 0.0;
        int wind = 0.0;
       
        boolean metric = false;
        int altitude = 16; // meters above sealevel
        float lastBmpTemp = -1;
        float lastPressure = -1;
        float lastHum = -1;
        float lastTemp = -1;
        double temp;
        double hum;
        int BATTERY_SENSE_PIN = A0;
        int lastRainValue = -1;
        int nRainVal;
        boolean bIsRaining = false;
        String strRaining = "NO";
        int lastBatteryPcnt = 0;
        int updateAll = 60;
        int updateCount = 0;
        uint16_t lastLux;
        // unsigned long SLEEP_TIME = 60000;
        unsigned long SLEEP_TIME = 600;
        int batteryBasement = 800;
        float batteryConstant = 100.0 / (1023 - batteryBasement);
            
        Adafruit_BMP085 bmp = Adafruit_BMP085();
        BH1750 lightSensor;
        dht DHT;
        MySensor gw;
    
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
        MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
        MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);    
        MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
        MyMessage msgRainRate(CHILD_ID_RAINRATE, V_RAIN);
    
        void setup()  
        {
          analogReference(INTERNAL);
          gw.begin(incomingMessage, 3, true);  
          //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
          bmp.begin();
          gw.sendSketchInfo("Weather Sensor", "1.0");
          gw.present(CHILD_ID_HUM, S_HUM, "WS Humidity");
          gw.present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
          gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
          gw.present(CHILD_ID_BARO, S_BARO, "WS Pressure");
          gw.present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
          gw.present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
          gw.present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
          gw.present(CHILD_ID_RAINRATE, S_RAIN, "WS RainRate");
    
          pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
          lightSensor.begin();
          metric = gw.getConfig().isMetric;
        }
        
        // Wind Meter https://github.com/chiemseesurfer/arduinoWeatherstation/blob/master/weatherstation/weatherstation.ino
        
        float windmeter()
        {
            windmeterStart = millis(); // Actual start time measuringMessung
            windmeterStartAlt = windmeterStart; // Save start time
        
            windSpeedPinCounter = 0; // Set pulse counter to 0
            windSpeedPinStatusAlt = HIGH; // Set puls status High
        
            while ((windmeterStart - windmeterStartAlt) <= windmeterTime) // until 10000 ms (10 Seconds) ..
            {
                windSpeedPinStatus = digitalRead(windSpeedPin); // Read input pin 2
                if (windSpeedPinStatus != windSpeedPinStatusAlt) // When the pin status changed
                {
                    if (windSpeedPinStatus == HIGH) // When status - HIGH
                    {
                        windSpeedPinCounter++; // Counter + 1
                    }
                }
                windSpeedPinStatusAlt = windSpeedPinStatus; // Save status for next loop
                windmeterStart = millis(); // Actual time
            }
        
            windSpeed =  ((windSpeedPinCounter * 24) / 10) + 0.5; //  WindSpeed - one Pulse ~ 2,4 km/h, 
            windSpeed = (windSpeed / (windmeterTime / 1000)); // Devided in measure time in seconds
            Serial.print("wind Speed :");
            Serial.println(windSpeed);    
            knoten = windSpeed / 1.852; //knot's
        
            return knoten;
        }
        
        void loop()      
        {
          updateCount += 1;
          if (updateCount == updateAll) {
            lastTemp = -1;
            lastHum = -1;
            lastLux = -1;
            lastBmpTemp = -1;
            lastPressure = -1;
            lastRainValue = -1;
            lastBatteryPcnt = -1;
            updateCount = 0;
          }
          delay(2000);
          int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
          temp = DHT.temperature;
                 //Serial.print("Temperature DHT :");
                 //Serial.println(temp);
          if (isnan(temp)) {
              lastTemp = -1;
          } else if (temp != lastTemp) {
            lastTemp = temp;
            if (!metric) {
              temp = temp * 1.8 + 32.0;
            }
            gw.send(msgTemp.set(temp, 1));
            }
          hum = DHT.humidity;
          if (isnan(hum)) {
              lastHum = -1;
          } else if (hum != lastHum) {
              lastHum = hum;
              gw.send(msgHum.set(hum, 1));
          }
          uint16_t lux = lightSensor.readLightLevel();
          if (lux != lastLux) {
              gw.send(msgLux.set(lux));
              lastLux = lux;
          }
          float pressure = bmp.readSealevelPressure(altitude) * 0.01;
          float bmptemp = bmp.readTemperature();
          if (!metric) {
            bmptemp = bmptemp * 1.8 + 32.0;
          }
          if (bmptemp != lastBmpTemp) {
            gw.send(msgBtemp.set(bmptemp,1));
            lastBmpTemp = bmptemp;
          }
          if (pressure != lastPressure) {
            gw.send(msgPressure.set(pressure, 0));
            lastPressure = pressure;
          }
          
          nRainVal = analogRead(nRainIn);
                 Serial.print("RainVal :");
                 Serial.println(nRainVal);
          bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
                 Serial.print("Is Raining :");
                 Serial.println(bIsRaining);
          if(bIsRaining){
              strRaining = "YES";
          }
          else{
              strRaining = "NO";
          }
      
          //Serial.print("Raining?: ");
          //Serial.print(strRaining);  
          //Serial.print("\t Moisture Level: ");
          //Serial.println(nRainVal);
          //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
    
          gw.send(msgRain.set(bIsRaining));
          nRainVal = nRainVal * -1;
          gw.send(msgRainRate.set(nRainVal));
    
          wind = windmeter();
          Serial.print("Wind :");
          Serial.println(wind);
          gw.send(msgWindSpeed.set(wind));
          
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
          if (lastBatteryPcnt != batteryPcnt) {
            gw.sendBatteryLevel(batteryPcnt);
            lastBatteryPcnt = batteryPcnt;
          }
          gw.sleep(SLEEP_TIME);
       }
    
        void incomingMessage(const MyMessage & message) {
        // We only expect one type of message from controller. But we better check anyway.
         if (message.isAck()) {
           Serial.println("This is an ack from gateway");
         }
        }```
    
    Still need some cleaning and calibrating (rain and wind sensor)
    [0_1459792799776_Weather-station.fzz](/uploads/files/1459792799984-weather-station.fzz) 
    
    Regard's Peer


  • Oh yeah, a little source mentioning :
    Weather Station
    Weather Station Code

    Greetz Peer



  • Please can you ex-plane how i can remove 1 of the sensors in the sketch...
    I will try to build more of this sensors...
    Only 1 rain and 1 baro is good for me



  • This is my project!!!!

    0_1459952652761_schema-2_bb.jpg

    // Example sketch för a "light switch" where you can control light or something 
    // else from both vera and a local physical button (connected between digital
    // pin 3 and GND).
    // This node also works as a repeader for other nodes
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <DHT.h> 
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    
    //pin sensori
    #define PIR_PIN 2                   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define HUMIDITY_TEMPERATURE_PIN 3  // sensore temperatura umidita
    #define RELAY_PIN  4                // relay pin
    int BATTERY_SENSE_PIN = A1;         // Pin carica batteria o pannello solare
    int FOTORESIST_SENSE_PIN = A2;      // Pin fotoresistenza
    
    //interupt per sleep arduino
    #define INTERRUPT PIR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    
    //id per vera
    #define CHILD_ID_RELE 1   // Id relay
    #define CHILD_ID_HUM 2    // id temperatura
    #define CHILD_ID_TEMP 3   // id umidita
    #define CHILD_ID_PIR 4    // Id pir
    #define CHILD_ID_LIGHT 5  // Id luminosita (fotoresistenza)
    
    //definizione per nodo vera
    #define NODE_ID 10
    #define SN "meteo station"
    #define SV "1.4"
    
    //variabili
    bool state_relay;                 //stato relay
    float batt_valore;                //dichiaro la variabile valore che memorizzerà il valore della batteria dal pin analogico
    float batt_volt;                  //volt batteria
    float batt_charged_percent;       //percentuale carica batteria
    float last_batt_charged_percent;  //percentuale carica batteria precedente
    float batt_min_voltage = 0.5;     //tensione minima batteria
    float batt_max_voltage = 5;       //tensione massima batteria
    float fotoresistenza_valore;      //dichiaro la variabile valore che memorizzerà il valore della fotoresistenza dal pin analogico
    float last_fotoresistenza_valore; //dichiaro la variabile valore precedente
    
    int lux_vera;                      //valore luminosita da inviare a vera
    
    MySensor gw;
    
    // sensore temperatura umidita
    DHT dht_int;
    float lastTemp_int = -1;
    float lastHum_int = -1;
    
    boolean metric = true; 
    
    MyMessage msgRelay(CHILD_ID_RELE,V_LIGHT);
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED);
    MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    
    void setup()  
    {  
      gw.begin(incomingMessage, NODE_ID, false);    
      
      gw.sendSketchInfo(SN, SV); 
    
      //Sensore umidita temperatura
      dht_int.setup(HUMIDITY_TEMPERATURE_PIN);
      
      gw.present(CHILD_ID_RELE, S_LIGHT);       //light vera
      gw.present(CHILD_ID_HUM, S_HUM);          //umidity vera
      gw.present(CHILD_ID_TEMP, S_TEMP);           // temp vera
      gw.present(CHILD_ID_PIR, S_MOTION);          // motion vera
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);  //light level (fotoresistenza)
      
      metric = gw.getConfig().isMetric;
      
      // Then set relay pins in output mode
      pinMode(RELAY_PIN, OUTPUT);   
      
      //PIR
      pinMode(PIR_PIN, INPUT);
      
      state_relay = 0;  
      //GestisciRelay();
      digitalWrite(RELAY_PIN, LOW);
      gw.send(msgRelay.set(state_relay)); 
         
    }
    
    void loop() 
    { 
        gw.process();
      
        //sensore temperatura umidita
        delay(dht_int.getMinimumSamplingPeriod());
    
        float temperature_int = dht_int.getTemperature();
        if (isnan(temperature_int)) 
        {
            lastTemp_int = -1;
            Serial.println("Failed reading temperature from DHT");
        } 
        else if (temperature_int != lastTemp_int) 
        {
          lastTemp_int = temperature_int;
          if (!metric) 
          {
            temperature_int = dht_int.toFahrenheit(temperature_int);
          }
          gw.send(msgTemp.set(temperature_int, 1));
          Serial.print("T int: ");
          Serial.println(temperature_int);
        }
      
        float humidity_int = dht_int.getHumidity();
        if (isnan(humidity_int)) 
        {
            lastHum_int = -1;
            Serial.println("Failed reading humidity from DHT");
        } 
        else if (humidity_int != lastHum_int) 
        {
            lastHum_int = humidity_int;
            gw.send(msgHum.set(humidity_int, 1));
            Serial.print("H int: ");
            Serial.println(humidity_int);
        }
        //sensore temperatura umidita
        
        //fotoresistenza    
        for(int i=0;i<150;i++)
        {
          fotoresistenza_valore += analogRead(FOTORESIST_SENSE_PIN);  //read the input voltage from battery or solar panel      
          delay(2);
        }
        fotoresistenza_valore = fotoresistenza_valore / 150;    
               
        Serial.print ("fotoresistenza: ");
        Serial.println(fotoresistenza_valore); 
    
        if (fotoresistenza_valore != last_fotoresistenza_valore) 
        {
          lux_vera = (int) fotoresistenza_valore;
          gw.send(msgLux.set(lux_vera));
          last_fotoresistenza_valore = fotoresistenza_valore;
        }    
        //fotoresistenza
        
        //pir relay
        // Read digital motion value
        boolean tripped = digitalRead(PIR_PIN) == HIGH; 
        Serial.println("pir:");      
        Serial.println(tripped);
        gw.send(msgPir.set(tripped?"1":"0"));  // Send tripped value to gw 
        
        //accende la luce con il buio
        if (fotoresistenza_valore < 200)  //poca luce
        {
          if (tripped == 1) 
          {
             state_relay = 1;     
          }
          else
          {
             state_relay = 0;     
          }
        }
        //accende la luce con il buio
        
        GestisciRelay();
        //pir relay
        
        //battery    
        for(int i=0;i<150;i++)
        {
          batt_valore += analogRead(BATTERY_SENSE_PIN);  //read the input voltage from battery or solar panel      
          delay(2);
        }
        batt_valore = batt_valore / 150;    
               
        Serial.print ("batt_valore: ");
        Serial.println(batt_valore);
        
        batt_volt = (batt_valore / 1024) * batt_max_voltage;
        Serial.print ("batt_volt: ");
        Serial.println(batt_volt);
        
        ////////////////////////////////////////////////
       //The map() function uses integer math so will not generate fractions
       // so I multiply battery voltage with 10 to convert float into a intiger value
       // when battery voltage is 6.0volt it is totally discharged ( 6*10 =60)
       // when battery voltage is 7.2volt it is fully charged (7.2*10=72)
       // 6.0v =0% and 7.2v =100%
       //batt_charged_percent = batt_volt*10;   
       //batt_charged_percent = map(batt_volt*10, 60 , 72, 0, 100);
        batt_charged_percent = batt_volt * 10;   
        batt_charged_percent = map(batt_volt * 10, batt_min_voltage * 10 , batt_max_voltage * 10, 0, 100);
        //batt_charged_percent = (batt_volt / batt_max_voltage) * 100;
        Serial.print ("batt_charged_percent: ");
        Serial.println(batt_charged_percent);
           
        if (last_batt_charged_percent != batt_charged_percent) 
        {
            gw.sendBatteryLevel(batt_charged_percent);
            last_batt_charged_percent = batt_charged_percent;        
        }
        //battery
        
        delay(50);
        
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.   
        gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME);
        
        
    } 
     
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
         // Change relay state_relay
         state_relay = message.getBool();
         GestisciRelay();
        
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
       
      
    }
    
    
    
    void GestisciRelay()
    {
        //Serial.print(" GestisciRelay state_relay:");
        //Serial.println(state_relay);
      
        if (state_relay == 0)
        {
          digitalWrite(RELAY_PIN, LOW);
          gw.send(msgRelay.set(state_relay));
          //Serial.println("SPENTO RELAY");
        }
        else 
       {
          digitalWrite(RELAY_PIN, HIGH);
          gw.send(msgRelay.set(state_relay));
          //Serial.println("ACCESO RELAY");
       } 
    
      
    }
    
    
    

    On vera
    0_1459952879015_vera-image.jpg

    On board
    0_1459952958112_IMG_20160406_162541.jpg



  • I purchased a solar kit

    Solar Panel
    battery 12v
    landstar solar charge controller

    I want to insert into Arduino in output of charge controller (I have 12 volts)

    to lower the voltage can I use a mobile charger Car 1 Ah

    do you heat so much?

    Thank

    @Salmoides Good Project!!!!!



  • what are the resistors? Or what do you u use between the wires?
    Look simple to me..



  • @Dombo71 look a fritzing schematic



  • @gigi said:

    @Dombo71 look a fritzing schematic

    Can you share the fritzing file please





  • 0_1459971075004_schema-pannello-solare-2_bb.jpg

    New fritzing

    I have two questions?

    1. voltage divider for more 5 v (battery voltage 12-13 volts)
    2. I use a auto phone charger for step down (12v --> 5 V) - warmers if I close in a box?

    Thank



  • @gigi said:

    0_1459971075004_schema-pannello-solare-2_bb.jpg

    New fritzing

    I have two questions?

    1. voltage divider for more 5 v (battery voltage 12-13 volts)
    2. I use a auto phone charger for step down (12v --> 5 V) - warmers if I close in a box?

    Thank

    Is your fritzing correct?
    On the green wire (light sensor?) you measure on ground where I guess you should measure between the resistor and the sensor.



  • @Petjepet said:

    On the green wire (light sensor?) you measure on ground where I guess you should measure between the resistor and the sensor.

    0_1460011587951_LdrUp_down.jpg

    Is the same

    0_1460011676140_vdivider.jpg

    voltage divider



  • @gigi I know but in your breadboard picture the now mentioned V output is connected directly to ground. 😏

    0_1460012243066_Knipsel.JPG



  • @Petjepet I Know, thank

    on board as I did your chart

    0_1460012626053_schema-pannello-solare-2_bb-2.jpg
    Thank



  • Back to the weather station.
    I was having problems reporting wind speed to domoticz (in hardware my sensor was listed, but there was no device creation)
    After a question on their forum, i learned tha i had to implement gust and direction to the sensor becaus Domoticz is aspectiong these to before it vreates a device.
    I had to remove the rainrate because the sketch was getting to big.
    Here is the latest sketch i am using :

    
    
    
        #include <SPI.h>
        #include <MySensor.h>  
        #include <dht.h>
        #include <BH1750.h>
        #include <Wire.h> 
        #include <Adafruit_BMP085.h>
        #include <MySigningAtsha204.h>
        
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define CHILD_ID_LIGHT 2
        #define CHILD_ID_BARO 3
        #define CHILD_ID_BTEMP 4
        #define CHILD_ID_WINDSPEED 5
        #define CHILD_ID_RAIN 6
        
        #define MESSAGEWAIT 500
        #define DIGITAL_INPUT_RAIN_SENSOR 3
        #define HUMIDITY_SENSOR_DIGITAL_PIN 5
        #define ENCODER_PIN 2
        #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
    
        const int  windSpeedPin = 2; // contact on pin 2 digital
        int windSpeedPinCounter = 0; // impuls counter
        int windSpeedPinStatus = 0; // actual impuls
        int windSpeedPinStatusAlt = 0; // oude Impuls-Status
        unsigned long windmeterStart;
        unsigned long windmeterStartAlt = 0;
        int windSpeed; // Variable voor Wind Speed
        int beaufort = 0; // Variable Wind in Beaufort
        const int windmeterTime = 10000;
        //float knoten = 0.0;
        //float wind = 0.0;
        unsigned int knoten;
        unsigned int wind;
       
        boolean metric = false;
        int altitude = 16; // meters above sealevel
        float lastBmpTemp = -1;
        float lastPressure = -1;
        float lastHum = -1;
        float lastTemp = -1;
        double temp;
        double hum;
        int BATTERY_SENSE_PIN = A0;
        int lastRainValue = -1;
        int nRainVal;
        boolean bIsRaining = false;
        String strRaining = "NO";
        int lastBatteryPcnt = 0;
        int updateAll = 60;
        int updateCount = 0;
        uint16_t lastLux;
        // unsigned long SLEEP_TIME = 60000;
        unsigned long SLEEP_TIME = 600;
        int batteryBasement = 800;
        float batteryConstant = 100.0 / (1023 - batteryBasement);
    
        MyTransportNRF24 radio;  // NRFRF24L01 radio driver
        MyHwATMega328 hw; // Select AtMega328 hardware profile
        MySigningAtsha204 signer(true); // Select HW ATSHA signing backend
        
        Adafruit_BMP085 bmp = Adafruit_BMP085();
        BH1750 lightSensor;
        dht DHT;
        MySensor gw(radio, hw, signer);
    
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
        MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
        MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);
        MyMessage msgWGust(CHILD_ID_WINDSPEED, V_GUST);
        MyMessage msgWDirection(CHILD_ID_WINDSPEED, V_DIRECTION);   
        MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
    
        void setup()  
        {
          analogReference(INTERNAL);
          gw.begin(incomingMessage, 3, true);  
          //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
          bmp.begin();
          gw.sendSketchInfo("Weather Sensor", "1.0");
          gw.present(CHILD_ID_HUM, S_HUM, "WS Humidity");
          gw.present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
          gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
          gw.present(CHILD_ID_BARO, S_BARO, "WS Pressure");
          gw.present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
          gw.present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
          gw.present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
    
          pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
          lightSensor.begin();
          metric = gw.getConfig().isMetric;
        }
        
        // Wind Meter https://github.com/chiemseesurfer/arduinoWeatherstation/blob/master/weatherstation/weatherstation.ino
        
        float windmeter()
        {
            windmeterStart = millis(); // Actual start time measuringMessung
            windmeterStartAlt = windmeterStart; // Save start time
        
            windSpeedPinCounter = 0; // Set pulse counter to 0
            windSpeedPinStatusAlt = HIGH; // Set puls status High
        
            while ((windmeterStart - windmeterStartAlt) <= windmeterTime) // until 10000 ms (10 Seconds) ..
            {
                windSpeedPinStatus = digitalRead(windSpeedPin); // Read input pin 2
                if (windSpeedPinStatus != windSpeedPinStatusAlt) // When the pin status changed
                {
                    if (windSpeedPinStatus == HIGH) // When status - HIGH
                    {
                        windSpeedPinCounter++; // Counter + 1
                    }
                }
                windSpeedPinStatusAlt = windSpeedPinStatus; // Save status for next loop
                windmeterStart = millis(); // Actual time
            }
        
            windSpeed =  ((windSpeedPinCounter * 24) / 10) + 0.5; //  WindSpeed - one Pulse ~ 2,4 km/h, 
            windSpeed = (windSpeed / (windmeterTime / 1000)); // Devided in measure time in seconds
            Serial.print("wind Speed : ");
            Serial.println(windSpeed);    
            knoten = windSpeed / 1.852; //knot's
        
            return windSpeed;
        }
        
        void loop()      
        {
          updateCount += 1;
          if (updateCount == updateAll) {
            lastTemp = -1;
            lastHum = -1;
            lastLux = -1;
            lastBmpTemp = -1;
            lastPressure = -1;
            lastRainValue = -1;
            lastBatteryPcnt = -1;
            updateCount = 0;
          }
          delay(2000);
          int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
          temp = DHT.temperature;
                 //Serial.print("Temperature DHT :");
                 //Serial.println(temp);
          if (isnan(temp)) {
              lastTemp = -1;
          } else if (temp != lastTemp) {
            lastTemp = temp;
            if (!metric) {
              temp = temp * 1.8 + 32.0;
            }
            gw.send(msgTemp.set(temp, 1));
            }
          hum = DHT.humidity;
          if (isnan(hum)) {
              lastHum = -1;
          } else if (hum != lastHum) {
              lastHum = hum;
              gw.send(msgHum.set(hum, 1));
          }
          uint16_t lux = lightSensor.readLightLevel();
          if (lux != lastLux) {
              gw.send(msgLux.set(lux));
              lastLux = lux;
          }
          float pressure = bmp.readSealevelPressure(altitude) * 0.01;
          float bmptemp = bmp.readTemperature();
          if (!metric) {
            bmptemp = bmptemp * 1.8 + 32.0;
          }
          if (bmptemp != lastBmpTemp) {
            gw.send(msgBtemp.set(bmptemp,1));
            lastBmpTemp = bmptemp;
          }
          if (pressure != lastPressure) {
            gw.send(msgPressure.set(pressure, 0));
            lastPressure = pressure;
          }
          
          bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
          if(bIsRaining){
              strRaining = "YES";
          }
          else{
              strRaining = "NO";
          }
      
          //Serial.print("Raining?: ");
          //Serial.print(strRaining);  
          //Serial.print("\t Moisture Level: ");
          //Serial.println(nRainVal);
          //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
    
          gw.send(msgRain.set(bIsRaining, 1));
    
          wind = windmeter();
          Serial.print("Wind : ");
          Serial.println(wind);
          int wdirection = 1;
          int wgust = 1;
          gw.send(msgWindSpeed.set(wind, 1));
          gw.send(msgWGust.set(wgust, 1));
          gw.send(msgWDirection.set(wdirection, 1));
          
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
          if (lastBatteryPcnt != batteryPcnt) {
            gw.sendBatteryLevel(batteryPcnt);
            lastBatteryPcnt = batteryPcnt;
          }
          gw.sleep(SLEEP_TIME);
       }
    
        void incomingMessage(const MyMessage & message) {
        // We only expect one type of message from controller. But we better check anyway.
         if (message.isAck()) {
           Serial.println("This is an ack from gateway");
         }
        }
    
    

    regards Peer



  • Hi,
    It means that there is no possibility to implement wind speed on this weather station... ok.
    I've just received the good Li-Ion charging component, I can continue with the construction!

    I'll post if I will be facing for some trouble, or when it will be finished.



  • @Salmoides - I must congratulate you on a very neat and professional build.

    I'm not sure if you are still hanging around this forum but even if you aren't, others may find the following suggestion helpful.

    @Salmoides said*:

    With it [the rain detector] I get 0.98 mA [drain] during the gw.sleep command

    There is a very easy, but often overlooked, method to disable sensors to reduce battery drain that requires no additional components. Because the sensor draws approximately 1ma, that is well within the 'drive' capacity of an Arduino output pin (which is about 20ma). So, all you need to do is wire the "+" power pin of the rain sensor to a spare output pin and "digitalWrite(pin,HIGH)" to turn it on and "digitalWrite(pin,LOW)" to turn it off.

    IMPORTANT: You should check the specs of the processor you are using to make sure the I/O pin can 'drive' or 'source' more than the required current of the sensor you wish to switch. I'd suggest allowing a 50% safety margin.

    Paul



  • @AffordableTech

    Looks like a feasible idea, as my stn does consume all the battery on bad days, and yes I needed the diode between the solar and controller to get to the right voltage

    cheers doug



  • Hello, it a nice job
    I am french so I beg your pardon for my poor English
    Can you , please show me how the lipo and the solar cell are connected and how the arduino is powered by the little shield (Charger Board ) at the right of picture over the DHT ?
    Thanks



  • @gigi: Besides the already adressed error in the Fritzing I have anaother question. In the diagram there is a charge controller for 12V. The original design in this threat uses a 5V charging module. What module are you using or planning to use?
    Thanks Ralph



  • @Renard : Bonjour! Je fais le raccordement cette semaine j'espère, je galère sur la déclaration dans Domoticz et l'étalonnage pour controler la charge de la batterie, mais je dirais:

    • OUT+ et - sur RAW et GND de l'Arduino
    • B+ B- à la batterie
    • "+ et -" au panneau solaire, c'est ce qu'il me semble sur les photos.

    @bisschopsr : Hi, There is no charge controler 5 or 12 volts. On my Fritzing to understand better the scheme (Post #70), I draw batteries and solar panel, but Fritzings following are with 12volts charger, I don't know why. If you purchased a solar lamp, it's to avoid 5 or 12volts charger and use the sun 😉



  • Merci pour la réponse
    C 'est donc l'arduino qui gère la décharge..
    Je vais donc mettre "Arduino Compatible Solar Charger shield -LiPo rider" a la place ...

    Thanks for answer
    It is the arduino wich control the discharge
    I put "Arduino Compatible Solar Charger shield -LiPo rider" without control of lipo capacity



  • Thanks for the anwer @Elfnoir. I looked back at your schedule and there is some logic between the solar panel, the batteries and the other components (as the power consumers). That logic in the middle is what I refered to as charge controller. I would like to know what part this is.
    Thanks again.
    Ralph



  • @Renard c'est bien l'arduino qui gère la décharge et envoi l'info à Domoticz; c'est pour cela que tu dois étalonner le min/max avec le potentiomètre
    it is the Arduino which manages the discharge and send the info to Domoticz ; that's why you have to calibrate the min / max with the potentiometer

    @bisschopsr If I well understand your question, the module which take the solar power to charge the battery with providing in the same time power to the arduino, and provide power of the battery to the arduino when there is no sun or at night: it's the Lipo Ride. There is no monitoring from the Arduino to the Lipo, but the Arduino read the level of voltage coming from the battery and send it to Domoticz.
    Do I understand well your question please?



  • @Elfnoir You understood the question correct :). That was the answer I was looking for. So your battery is something like a 3.7V LiOn?
    Thanks again
    Ralph



  • @bisschopsr yes, the battery inside the “16 LED Solar Power Motion Sensor Security Lamp Outdoor Waterproof Light” (http://www.ebay.com/itm/271693521438) is 3.7v 800mAh.



  • @Elfnoir Thank you very much. I found a local LED lamp with 3.6V 600mAh NiMh battery. I'm going to try and make a simular solution from that one.



  • @Salmoides I built this weather station (exactly as decribed above in the initial message) and have some problems with the radio when going about 15 meters from the gateway.
    I have several other nodes on similar distance working just fine.

    I guess the metal top of the case (where the solar panel is in) is causing the issue. Is there a way to change that? Maybe an additional antenna wire (how)?



  • @Petjepet The metal is definitely influencing the radio performance. It’s 2.4 GHz like the home wifi signal, so you might understand the impact if you compare these two. A solution to use a radio with an external antenna that can be placed outside the metal case. There is a radio with ext. antenna available, you might need an additional extension cable of say 15-30 cm. Does this help.

    Regards,

    Ralph



  • @bisschopsr That must be the same one I use for the gateway with the external antenna.
    I also saw once a wire connected to the standard radio but can't recall where I saw that.



  • @Petjepet Yes, you are probably using this version for the GW (I know I am :-)). I have also see people hacking the original module by attaching a wire antenna instead of the on board printed antenna. The advantage of the other antenna based board is, you can actually bring the antenna to the outside. Something more difficult to do with a wire hack.



  • I have been adapting this mini-weather station code to he API 2.0 and add it the battery sensor. Here's my first attemp

    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 2
    #define MY_PARENT_NODE_ID  0
    #define MY_PARENT_NODE_IS_STATIC
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>
    #include <BH1750.h>
    #include <Wire.h> 
    #include <Adafruit_BMP085.h>
    
    #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LIGHT 2
    #define CHILD_ID_BARO 3
    #define CHILD_ID_BTEMP 4
    #define CHILD_ID_WINDSPEED 5
    #define CHILD_ID_BATTERY 6
        
    #define MESSAGEWAIT 500
    #define DHT_DATA_PIN 3          // Pin 3 digital = DHT11 or DHT12
    #define windSpeedPin 4          // Pin 4 digital = Anenometer
    #define SENSOR_TEMP_OFFSET 0
    #define STABILIZATION_TIME 500  // Let the sensor stabilize 0.5 seconds before reading
    
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    static const uint64_t UPDATE_INTERVAL = 60000;
    
    #define BATTERY_FULL 7400 // 3,000 millivolts when battery is full (assuming 2xAA)
    #define BATTERY_ZERO 2800 // 1,700 millivolts when battery is empty (reqires blown brownout detection fuse, use 2,800 otherwise)
    
    const float ALTITUDE = 162; // <-- adapt this value to your own location's altitude.
    
    int windSpeedPinCounter = 0;        // impuls counter
    int windSpeedPinStatus = 0;         // actual impuls
    int windSpeedPinStatusAlt = 0;      // oude Impuls-Status
    unsigned long windmeterStart;
    unsigned long windmeterStartAlt = 0;
    int windSpeed;                      // Variable voor Wind Speed
    int beaufort = 0;                   // Variable Wind in Beaufort
    const int windmeterTime = 10000;
    //float knoten = 0.0;
    //float wind = 0.0;
    unsigned int knoten;
    unsigned int wind;
    
    long oldvoltage = 0;
    bool metric = true;
    float lastBmpTemp;
    float lastPressure;
    float lastHum;
    float lastTemp;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    
    int updateAll = 60;
    int updateCount = 0;
    uint16_t lastLux;
    
    unsigned long SLEEP_TIME = 60000;
    
    
    Adafruit_BMP085 bmp = Adafruit_BMP085();
    BH1750 lightSensor;
    DHT dht;
    
    MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE);
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
    MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
    MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);
    MyMessage msgWGust(CHILD_ID_WINDSPEED, V_GUST);
    MyMessage msgWDirection(CHILD_ID_WINDSPEED, V_DIRECTION);
    
    void setup()
    {
      analogReference(INTERNAL);
      dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
      if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) 
      {
        Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
      }
      // Sleep for the time of the minimum sampling period to give the sensor time to power up
      // (otherwise, timeout errors might occure for the first reading)
      sleep(dht.getMinimumSamplingPeriod());
      if (!bmp.begin()) 
      {
        Serial.println("Could not find a valid BMP085 sensor, check wiring!");
        while (1) {}
      }  
      metric = getConfig().isMetric;
    }
    
    void presentation()  
    {
      lightSensor.begin();
      
      sendSketchInfo("Weather Sensor", "4.1.C");
      
      present(CHILD_ID_HUM, S_HUM, "WS Humidity");
    //  present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
      present(CHILD_ID_BARO, S_BARO, "WS Pressure");
      present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
      present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
      present(CHILD_ID_BATTERY, S_CUSTOM, "WS Battery"); 
    }
    
    // Wind Meter https://github.com/chiemseesurfer/arduinoWeatherstation/blob/master/weatherstation/weatherstation.ino
    
    float windmeter()
    {
      windmeterStart = millis(); // Actual start time measuringMessung
      windmeterStartAlt = windmeterStart; // Save start time
      
      windSpeedPinCounter = 0; // Set pulse counter to 0
      windSpeedPinStatusAlt = HIGH; // Set puls status High
        
      while ((windmeterStart - windmeterStartAlt) <= windmeterTime) // until 10000 ms (10 Seconds) ..
      {
        windSpeedPinStatus = digitalRead(windSpeedPin); // Read input pin 2
        if (windSpeedPinStatus != windSpeedPinStatusAlt) // When the pin status changed
        {
          if (windSpeedPinStatus == HIGH) // When status - HIGH
          {
            windSpeedPinCounter++; // Counter + 1
           }
         }
         windSpeedPinStatusAlt = windSpeedPinStatus; // Save status for next loop
         windmeterStart = millis(); // Actual time
       }
       windSpeed =  ((windSpeedPinCounter * 24) / 10) + 0.5; //  WindSpeed - one Pulse ~ 2,4 km/h, 
       windSpeed = (windSpeed / (windmeterTime / 1000)); // Devided in measure time in seconds
       Serial.print("wind Speed : ");
       Serial.println(windSpeed);    
       knoten = windSpeed / 1.852; //knot's
       return windSpeed;
    }
    
    void loop()      
    {
      updateCount += 1;
      if (updateCount == updateAll) 
      {
        lastTemp = -1;
        lastHum = -1;
        lastLux = -1;
        lastBmpTemp = -1;
        lastPressure = -1;
        updateCount = 0;
       }
    
       long voltage = readVcc();
       if (oldvoltage != voltage) { // Only send battery information if voltage has changed, to conserve battery.
          send(voltage_msg.set(voltage / 1000.0, 3)); // redVcc returns millivolts and set wants volts and how many decimals (3 in our case)
          sendBatteryLevel(round((voltage - BATTERY_ZERO) * 100.0 / (BATTERY_FULL - BATTERY_ZERO)));
          oldvoltage = voltage;
       }
        
       delay(2000);
    
       // Force reading sensor, so it works also after sleep()
       dht.readSensor(true);
      
       // Get temperature from DHT library
       float temperature = dht.getTemperature();
       if (isnan(temperature)) 
       {
        Serial.println("Failed reading temperature from DHT!");
       }
       else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) 
       {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
        if (!metric) 
        {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        temperature += SENSOR_TEMP_OFFSET;
        send(msgTemp.set(temperature, 1));
    
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
        }
        else 
        {
          // Increase no update counter if the temperature stayed the same
          nNoUpdatesTemp++;
        }
    
        // Get humidity from DHT library
        float humidity = dht.getHumidity();
        if (isnan(humidity)) 
        {
          Serial.println("Failed reading humidity from DHT");
        } 
        else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) 
        {
          // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
          lastHum = humidity;
          // Reset no updates counter
          nNoUpdatesHum = 0;
          send(msgHum.set(humidity, 1));
    
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
        }
        else 
        {
          // Increase no update counter if the humidity stayed the same
          nNoUpdatesHum++;
        }
        uint16_t lux = lightSensor.readLightLevel();
        if (lux != lastLux) 
        {
          send(msgLux.set(lux));
          lastLux = lux;
        }
        float pressure = bmp.readSealevelPressure(ALTITUDE) * 0.01;
        float bmptemp = bmp.readTemperature();
        if (!metric)
        {
          bmptemp = bmptemp * 1.8 + 32.0;
        }
        if (bmptemp != lastBmpTemp) 
        {
          send(msgBtemp.set(bmptemp,1));
          lastBmpTemp = bmptemp;
        }
        if (pressure != lastPressure) 
        {
          send(msgPressure.set(pressure, 0));
          lastPressure = pressure;
        }
    
        wind = windmeter();
        Serial.print("Wind : ");
        Serial.println(wind);
        int wdirection = 1;
        int wgust = 1;
        send(msgWindSpeed.set(wind, 1));
        send(msgWGust.set(wgust, 1));
        send(msgWDirection.set(wdirection, 1));
        sleep(SLEEP_TIME);
    }
    
    void incomingMessage(const MyMessage & message) 
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) 
      {
        Serial.println("This is an ack from gateway");
      }
    }
    
    long readVcc()
    {
      // From http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
      // Read 1.1V reference against AVcc
      // set the reference to Vcc and the measurement to the internal 1.1V reference
    #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
      ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
    #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
      ADMUX = _BV(MUX5) | _BV(MUX0);
    #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
      ADMUX = _BV(MUX3) | _BV(MUX2);
    #else
      ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
    #endif
    
      delay(2); // Wait for Vref to settle
      ADCSRA |= _BV(ADSC); // Start conversion
      while (bit_is_set(ADCSRA, ADSC)); // measuring
    
      uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
      uint8_t high = ADCH; // unlocks both
    
      long result = (high << 8) | low;
    
      result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
      return result; // Vcc in millivolts
    }
    

    It a little big but does what i need and the best thing it's that the anenometer works 👍



  • My experience with using a "Micro USB 5V 1A 18650 Lithium Battery Charger Board With Protection Module" together with the "16 LED Solar Power Motion Sensor Security Lamp Outdoor Waterproof Light"s solar panel is that it's not charging the battery as well as the original built in PCB. Due to the varying voltage (up to 6V) of the solar panel it's not so well suited as a power source for "Micro USB 5V 1A 18650 Lithium Battery Charger Board With Protection Module". I experimented with diodes in serial (2 diodes gave best result) to lower the voltage. However using the original board allowed the battery to charge with a much higher current. I just cut of the motion sensor, and the power switch. It seems to work well. It's even charging a few mA now here when it's raining. My conclusion is that the "Micro USB 5V 1A 18650 Lithium Battery Charger Board With Protection Module" might be used but the original PCB makes a better job charging the battery.

    Cheers!


Log in to reply
 

Suggested Topics

  • 8
  • 1
  • 5
  • 3
  • 2
  • 90

10
Online

11.4k
Users

11.1k
Topics

112.7k
Posts