Silicon ChipA Water Tank Level Meter with WiFi and More! - February 2018 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Yet another threat to surfing the net
  4. Feature: Turning your garbage into useful electricity by Ross Tester
  5. Project: A Water Tank Level Meter with WiFi and More! by Nicholas Vinen
  6. Review: Navman’s DriveDuo – Satnav and Dashcam by Leo Simpson
  7. Project: 6-Element VHF TV Yagi to kill UHF 4G interference by Leo Simpson
  8. Feature: El Cheapo Modules 13: sensing motion and moisture by Jim Rowe
  9. Serviceman's Log: Smart TVs can be pretty dumb sometimes by Dave Thompson
  10. Product Showcase
  11. Project: Highly versatile & accurate dot/bar 10-LED Bargraph by John Clarke
  12. Project: The Arduino Mega Box Music Player revisited by Bao Smith
  13. Vintage Radio: A more detailed look at the 1919/20 Grebe Synchrophase by Ian Batty
  14. PartShop
  15. Subscriptions
  16. Market Centre
  17. Advertising Index
  18. Notes & Errata: UV Light Box & Timer / Micromite BackPack Touchscreen DDS Signal Generator / Deluxe Touchscreen eFuse / Kelvin the Cricket
  19. Outer Back Cover: Hare & Forbes Machineryhouse

This is only a preview of the February 2018 issue of Silicon Chip.

You can view 37 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "A Water Tank Level Meter with WiFi and More!":
  • WiFi Water Tank Level Meter shield PCB with stackable headers [21110171] (AUD $7.50)
  • Small 2A boost step-up regulator module (MT3608) (Component, AUD $3.00)
  • IPP80P03P4L-07 high-current P-channel Mosfet (Component, AUD $2.50)
  • GY-68 Barometric Pressure/Altitude/Temperature I²C Sensor breakout board (Component, AUD $2.50)
  • DHT22/AM2302 Compatible Temperature and Humidity sensor module (Component, AUD $9.00)
  • 5dBi 2.4GHz WiFi antenna with U.FL/IPX adaptor cable (Component, AUD $12.50)
  • 2dBi omnidirectional 2.4GHz WiFi antenna with U.FL/IPX adaptor cable (Component, AUD $10.00)
  • Elecrow 1A/500mA Li-ion/LiPo charger board with USB power pass-through (Component, AUD $25.00)
  • Arduino sketch (.ino) file and libraries for the WiFi Water Tank Level Meter (Software, Free)
  • WiFi Water Tank Level Meter shield PCB pattern (PDF download) [21110171] (Free)
Items relevant to "El Cheapo Modules 13: sensing motion and moisture":
  • Arduino and BASIC source code for El Cheapo Modules 13 (Software, Free)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Items relevant to "Highly versatile & accurate dot/bar 10-LED Bargraph":
  • 10-LED Bargraph PCB [04101181] (AUD $7.50)
  • 10-LED Bargraph Signal Processing PCB [04101182] (AUD $5.00)
  • 10-LED Bargraph PCB patterns (PDF download) [04101181/2] (Free)
Items relevant to "The Arduino Mega Box Music Player revisited":
  • Firmware (Arduino sketch) for the LC Meter (Mega Box) (Software, Free)
  • Firmware (Arduino sketch) for the VS1053 Music Player (Mega Box) (Software, Free)
  • Geeetech VS1053B MP3/audio shield for Arduino (Component, AUD $10.00)
  • Firmware (Arduino sketch) for the VS1053 Music Player (Mega Box) (Software, Free)
Articles in this series:
  • The Arduino MegaBox from Altronics (December 2017)
  • The Arduino MegaBox from Altronics (December 2017)
  • Arduino LC Meter Shield Kit (January 2018)
  • Arduino LC Meter Shield Kit (January 2018)
  • The Arduino Mega Box Music Player revisited (February 2018)
  • The Arduino Mega Box Music Player revisited (February 2018)
  • Altronics New MegaBox V2 Arduino prototyping system (December 2019)
  • Altronics New MegaBox V2 Arduino prototyping system (December 2019)

Purchase a printed copy of this issue for $10.00.

Solar Powered Water Tank Level Meter and Weather Station by Nicholas Vinen The level in some water tanks is easy to check – but others, especially if they’re high up, or remotely located, or have difficult access, can be the proverbial pain in the *#<at>^! Here’s a great way to check your tank level(s), and you don’t even need to be on the same planet (OK, slight exaggeration) to do so. Just call this unit up from anywhere and get an instant reading . . . and a weather report into the bargain! 20 20  S Silicon Chip Celebrating Years Celebrating 3030 Years siliconchip.com.au The final version of our Water Tank Level Meter and Weather Station with the sensor (on 6m cable) at left and the box containing the PCBs (left side of box), 3.7V Li-ion phone battery (right side) and the two solar cells on the lid. We’ve also fitted a higher-performing WiFi antenna. T his Arduino-based unit runs what the local weather is like at any ming skills, you could even make it from solar power and periodi- time – even when you aren’t any- switch a pump on or off, depending cally uploads your water tank where near your tank/home/office . . on the water level. level and outdoor temperature, hu- . anywhere! Circuit description midity and barometric pressure to a More than one tank to check? The circuit for the Water Tank Me“cloud” service. Lucky you . . . but if you have mul- ter/Weather Station is shown in Fig.1. You can check the data at any time from anywhere, using a mobile phone, tiple water tanks to check, that’s no It’s based on an ESP8266 Arduinotablet or PC. It even provides graphs to problem. Just build multiple units, set compatible board. This incorporates show you how these readings change up a separate “channel” for each one the WiFi transceiver and it’s very easy and Bob’s your uncle. to get it connected to the internet. over time. And because we’ve based it on The waterproof pressure sensor conWe’ve published numerous water tank level meter projects in the past but an Arduino-compatible module, the nects across terminal block CON1. this one has to be the easiest to build, software is nice and simple and you These are available from eBay and Alcould modify it if you have any spe- iExpress and can measure water levset up and use. els up to about 6m (that may vary beThat’s because it takes advantage of cial needs. For example, you could change the tween products). an off-the-shelf pressure-based water They simply need to be dropped level sensor which comes already wa- interval at which the water level is checked. If you have some program- into the tank (eg, through a hole in terproofed, with a long lead attached. the top) so that they sit So you just need to on the bottom and can drop it down into the monitor the water prestank, hook it up to the sure there. Arduino-based unit and These sensors operate it will automatically using the 4-20mA curupload the tank levrent loop principle and el to “the cloud”. You require a 24V DC power can then check it anysupply. where in the world, at Basically, the sensor any time. will draw between 4mA We figured that while and 20mA from the powwe were going to the er supply, depending on trouble of doing this, we the sensed pressure (and might as well also measthus water level). ure the local temperaIf exposed to air, at ture, humidity and barnormal atmospheric ometric pressure too. pressures, the current This adds very little to the project cost but A screen grab of the ThingSpeak website, showing real data from our will be around 4mA and under the maximum ratit means you can check test unit monitoring a rain water tank. siliconchip.com.au Celebrating 30 Years February 2018  21 Fig.1: the complete circuit for the Water Tank Level Meter, minus the pressure sensor which is connected via CON1. The WeMos Arduinocompatible board has onboard WiFi and it switches on the power supply to the sensor when necessary, then measures its output via op amp LM358 at analog input A0. The digitised value is sent to a cloud database host service. ed depth of water, the current will be around 20mA. This means that the sensor needs only two wires and these provide power to the unit and also carry the output signal. And because the output signal is a current, the resistance of the long wires or any connections along the way will not affect the reading. It does lead to two problems though: One is how to provide 24V to the sensor when the Arduino board runs from 3.3V/5V and do it in a manner which doesn’t drain the small battery too quickly. And the other is how to measure the sensor’s supply current using the ESP8266. The first problem is solved by using a low-cost MT3608 voltage boost mod22 Silicon Chip ule. This is quite small at 50x21mm, costs just a few dollars and can produce an output of up to 38V with a 3.2-32V input at up to 2A. Its efficiency under load is quite good, around 90%. But to save battery power, we will only power up the MT3608 when making the periodic water level measurement. We chose to measure the current using a simple method. We insert a 10Ω resistor in series with the sensor’s ground connection. With 4-20mA flowing through that portion of the circuit, the voltage across this resistor will be 40-200mV. This reduces the sensor’s supply voltage but it will still work fine at 23.8V and we can easily compensate by adjusting the boost module to produce 24.2V anyway. Celebrating 30 Years Those voltages are a little low to measure directly using the Arduino module, so we provide 16 times amplification using op amp IC1b. This is a standard LM358 singlesupply op amp which will happily run off the 5V supply. The gain is set by the ratio of the 15kΩ and 1kΩ feedback resistors. Its output is 600-3000mV, ie, 0.6-3V and this is fed to analog input A0 on the Arduino via a 1kΩ resistor. This resistor isn’t absolutely necessary but since the LM358 op amp runs off 5V and the Arduino’s supply is 3.3V, there is a remote possibility that the Arduino input could be overdriven. In this case, the resistor limits the current to a safe level. However, LM358 outputs normally siliconchip.com.au Fig.2: PCB overlay for the Water Tank Level Meter Arduino shield PCB with a matching same-size photo at right. Fit the components where shown, starting with the lowest profile parts and working your way up to the taller ones. can only vary up to 1.5V below the positive supply rail, which in this case is nominally 3.5V and thus likely safe. Andthe op amp’s output current is internally limited to around 40mA. Still, the 3.3V and 5V rails can vary by a few hundred millivolts either way so the 1kΩ resistor is a worthwhile and cheap measure to ensure reliable operation. The ESP8266 ADC has a 10-bit resolution (the same as most Arduinos) and so this 0.6-3V level will normally translate into digital readings of around 186-930 for 0-100% of the pressure sensor’s range. That will give a resolution of around 0.13% to the readings [ie, 100 ÷ (930 – 186)]. But keep in mind that a typical water tank is not 6m high, so the resolution will be reduced proportionally. Still, you can expect it to be no worse than half a percentage point. By the way, note that the ESP8266 only has one analog input (A0), compared to the normal six on an Arduino Uno – one of its few weaknesses. Remainder of the circuit As mentioned earlier, the power supply for the water level sensor is only powered up when the sensor is actually being used. This is done by driving digital output pin D7 of MOD1 high, which drives the gate of N-channel small signal Mosfet Q1 high. This is a 2N7000 logic-level Mosfet so the 3.3V at its gate is sufficient to switch it on, pulling the gate of Pchannel Mosfet Q2 low. Q2 is a high-current logic-level device and its gate is normally held at +5V by a 100kΩ pull-up resistor, keeping it off. But when Q1 switches on and pulls its gate low, current can flow from the 5V supply to the VIN+ siliconchip.com.au terminal of MOD4, the boost regulator. It will then generate 24V to drive the water level sensor. Note that there are two voltage level translations occurring with this arrangement; from the 3.3V swing of the output of MOD1 up to a 5V swing at the gate of Q2, and then a 24V change in the output of MOD4. If the sensor is drawing 4mA (ie, the water tank is empty) then you can expect at least 19.2mA (4mA x 24V ÷ 5V) additional drain on the battery. In practice, it will be closer to 25mA. With a full water tank and the sensor drawing 20mA, this will increase to over 100mA. So it’s a good thing that it only needs to be powered up for a second or so each time a measurement is made or the battery would be flat in a few hours. When the power supply for the sensor is off, there is no current flow and so no voltage across the 10Ω resistor. Therefore output pin 7 of IC1b is at 0V and so is analog input A0 of MOD1. The ESP8266 has a built-in WiFi transceiver so we don’t need to add anything extra to the circuit in order to transmit the water tank level over the internet. Weather station Since this unit is likely to be placed outdoors, we thought we might as well add a couple more low-cost components to allow it to monitor ambient air temperature, pressure and humidity. ESP8266 Arduino pin numbering One of the most challenging aspects of But even more confusing is the fact that developing the software for this project was the digital pins are not connected to pins dealing with the strange way the digital pins with a matching number on the IC while are numbered on the WeMos D1 R2 board. others have built-in pull-up or pull-down If you plan on modifying the software, you resistors. will need to be aware of this. And it appears that some of the digital For a start, there’s the incorrect label- pins are not usable at all! ling on some PCBs that was mentioned in The following table indicates which pin the text. On some WeMos boards, the TX numbers you actually need to use in the and RX pins are labelled “0” and “1” (de- software (ESP8266 pin) to access one of spite not being usable as such) and con- the Arduino digital pins. It also shows which sequently, the actual D0 pin is labelled 2, pins have special functions or pull-up/pullD1 is labelled 3 and so on. down resistors. Arduino ESP8266 Additional pin  pin   functions D0 D1 D2 D3 D4 D5 D6 D7 D8 16 5 4 0 2 14 12 13 15 Celebrating 30 Years SCL SDA 10kΩ pull-up 10kΩ pull-up, BUILTIN_LED SCK MISO MOSI SS, 10kΩ pull-down February 2018  23 Parts list – Water Tank Level Meter + 1 4-20mA water level (pressure) sensor with cable [SILICON CHIP Online Shop Cat SC4283] 1 double-sided PCB, coded 21110171, 68.5 x 53.5mm 1 set of four long-pin Arduino stackable headers (included with PCB) 1 WeMos D1 R2 ESP8266-based Arduino board (MOD1) [SILICON CHIP Online Shop Cat SC4414] 1 DHT-22/AM2302 temperature/humidity sensor module (MOD2) [SILICON CHIP Online Shop Cat SC4150] 1 GY-68 temperature/barometric pressure sensor module (MOD3) [SILICON CHIP Online Shop Cat SC4343] 1 MT3608-based 2A boost regulator module (MOD4) [SILICON CHIP Online Shop Cat SC4437] 1 2-way mini terminal block (CON1) 1 2-way pin header with jumper shunt (LK1) 1 4-pin header (for MOD3) 1 M3 x 6mm machine screw and nut 2 small solar panels, around 1W each, 6V open-circuit, approximately 100 x 70mm (SILICON CHIP online shop Cat SC4339) 1 Elecrow mini solar charger module (MOD5) [SILICON CHIP Online Shop Cat SC4308] 1 JST-2.0 2-pin plug with flying leads (included in SC4308) 1 short USB Type A to micro Type B cable 1 single Li-ion cell, 2-4Ah 1 IP65 sealed case with clear lid [eg, Jaycar HB6248 (171 x 121 x 55mm) or Altronics H0330 (186 x 146 x 75mm)] 1 cable gland to suit 7mm diameter cable [eg, Jaycar HP0724, Altronics H4312A] 1 chassis-mounting 2.4GHz WiFi antenna with cable and U.FL/IPX connector (optional) [SILICON CHIP Online Shop Cat 4522 or 4523] 1 small piece open-cell foam (eg, 25 x 25 x 10mm) 1 150ml or 300ml cartridge of clear neutral cure silicone sealant a few short lengths of light-duty hookup wire Semiconductors 1 LM358 dual op amp, DIL package (IC1) 1 2N7000 N-channel Mosfet (Q1) 1 IPP80P03P4L-04 P-channel logic-level Mosfet (Q2) [SILICON CHIP Online Shop Cat SC4318] 2 1N5819 schottky diodes (D1,D2) Capacitors 1 100nF MKT or ceramic Resistors (all 0.25W, 1% metal film) 1 100kΩ 1 15kΩ 2 1kΩ 1 10Ω These are be logged to “the cloud” along with the water tank levels, so you can see what the weather is like, even if you aren’t at home (or on the farm, or wherever your water tank is located). MOD2 is a DHT-22 temperature/hu- (Left) the DHT22 digital temperature and humidity sensor, with the Barometric Pressure/Altitude/ Temperature I²C Sensor board at right. 24 Silicon Chip midity sensor. We described the operation of this device in the El Cheapo Modules 4 article, published in the February 2017 issue. It uses a single wire protocol for communications and this goes to digital I/O pin D3 of MOD1. MOD3 is a GY-68 barometer module based on the BMP180 temperature/ pressure sensor. This has also been described in one of our El Cheapo Modules articles, this time part 11 in the December 2017 issue. Its communication is via I2C so the clock (SCL) and data (SDA) lines are hooked up to the I2C interface pins on MOD1. The ESP8266 chip can query these Celebrating 30 Years sensors immediately before taking a water tank level measurement and sends the measurements to the remote database at the same time. This has a minimal effect on battery life and network traffic. The electronics will need to be mounted in a weatherproof enclosure and/or sheltered position to protect it from rain, etc. But for MOD2 to measure humidity and MOD3, atmospheric pressure, they can’t be in a completely sealed box. We’ll go over some potential solutions to this apparent contradiction later. Note also that, given that the unit is powered by solar panels which need to be in the hot sun, and given that there is some dissipation from the unit itself, the temperature readings are likely to be on the high side on a sunny day. There are some steps you could take to mitigate that, such as installing a small fan to ensure air movement through the enclosure, but we won’t go into great detail on this aspect of the design as the weather data is not meant to be at a BoM level of accuracy. Power supply circuitry We’re using a similar power supply as we did with our Arduino Data Logger (August-September 2017). As with that design, we’re using the Elecrow Mini Solar Charger module (MOD5) which provides a regulated 5V supply for the Arduino at its USB output socket. This is derived from a single Lithium-ion cell (3-4.2V). Once again, we’re using a battery salvaged from an old mobile phone – but you could just as easily buy one from a hobby store or online vendor. The higher the amp-hour (Ah) capacity, the better, provided it will fit in a reasonably-sized enclosure. Our test battery is just under 3Ah which should give around 100 hours of operation (3Ah ÷ 30mA) or around The Elecrow Mini Solar Li-ion Charger module, reproduced same size. siliconchip.com.au The two individual PCBs which were piggy-backed into the form shown below – note that the board on the left is an early prototype which was changed in the final version. four days. The battery is charged from two small (<1W) solar cells, with an open-circuit output voltage of around 6V. They are effectively paralleled using a pair of schottky diodes, D1 and D2. These are included so that if one panel has sun while the other is shaded (eg, due to the shadow of a tree, the water tank etc), there will still be enough voltage supplied to the charger module for it to operate. The forward voltage of these diodes will slightly reduce the available power when both panels are in full sun but we think there’s a good chance they will increase the total power available over the course of a day in a typical installation. If we get an average power of say 1W from the panels for an average of eight hours a day in winter, that 8Wh translates into around 1.5Ah at 5V. Given the ~30mA average current drain of the unit, that should allow it to operate for around 50 hours. While that’s around twice the actual power required, of course, there will be cloudy days and so on, so the excess capacity can go into recharging the battery. Hence, we would not recommend using a smaller set of solar panels than shown here (in fact, more/larger would be better). If you have access to a mains supply near your water tank, you could connect a USB charger to the “USB IN” socket on MOD4 and this will then run the circuit and keep the battery charged. The battery would then run the unit during blackouts and the solar panels would not be necessary. siliconchip.com.au Link LK1, labelled “DEEP SLEEP”, is connected between the RESET input on MOD1 and digital output pin D0. See the separate panel explaining the purpose of this link and what you need to do to be able to use it. Most constructors will probably leave it open. Optional but recommended external antenna While we said earlier that the ESP8266 doesn’t need any extra com- ponents to operate over a WiFi network, given that the unit will almost certainly be located outdoors and possibly some distance from your network, there’s a chance that the onboard PCB track antenna simply won’t be good enough to pick up your WiFi signal. Fortunately, the WeMos board has provision for attaching an external 2.4GHz antenna via a tiny onboard U.FL/IPX RF connector. This shows how the two PCBs are assembled before mounting in the case – again, the top board is changed in the final version (for a start, it’s green!). Use the component overlay and pic overleaf for assembly. Celebrating 30 Years February 2018  25 This end-on view also shows the method of construction. On the bottom is the Arduino WeMos ESP8266 Arduino board, with the top board a shield designed specifically for the project. There are various different antennas available that suit the 2.4GHz band and while they typically have an SMA plug at their base, many of them are supplied with an adaptor cable consisting of a chassis-mount SMA socket at one end and a U.FL/IPX connector at the other. Two suitable antennas are available from the SILICON CHIP Online Shop (see parts list). One has 5dBi gain and is vertically polarised, and is able to be rotated and bent at an angle for optimal reception. The other has 2dBi gain but is smaller and omnidirectional. Both are supplied with suitable adaptor cables that will plug right into the ESP8266 board. Or you could source a suitable antenna yourself. And both of our antennas are waterproof so can be mounted on the outside of the case and the connectors sealed with silicone sealant to prevent water from getting inside. Construction As you can see from the photos, our prototype was wired up on a protoboard shield. The circuit is certainly simple enough to do this, involving only about a dozen components, and it only takes a couple of hours to wire it up. But it’s much easier if you build it on a printed circuit board, which is why we’ve designed one and had it manufactured. The overlay diagram for this PCB is shown in Fig.2. Fit the five resistors in the positions shown. Even though we’ve shown Deep Sleep Mode If link LK1 on the board is bridged, changing the line at the top of the code from “//#define USE_DEEPSLEEP” to “#define USE_DEEPSLEEP” should theoretically reduce overall power consumption. However, the effect is quite small and doing so has some disadvantages. With LK1 in circuit, the ESP8266 IC is able to completely shut down its CPU while in sleep mode. A special timer is included in the ESP8266 IC which drives pin D0 low after a certain time has elapsed, which resets the chip, waking it up and allowing the software to start again. The reason that this doesn’t save a whole lot of power is that the regulators and other circuitry onboard the ESP8266 Arduino module remain powered up, even though the chip itself is in deep sleep mode. And IC1, MOD2 and MOD3 continue to draw power too, albeit not very much (under 1mA total). 26 Silicon Chip The actual reduction in current is just a few milliamps, increasing battery life by a few percent. But because the chip is reset each time, it can’t keep anything in RAM during the sleep time and this affects the code’s ability to reliably determine the water tank minimum and maximum levels. The software feature intended to prevent sensor glitches from affecting the detected minimum and maximum levels is automatically disabled if deep sleep mode is used. Also, if deep sleep is enabled, you need to fit a pull-down resistor at the gate of Q1 as the I/O pin states are no longer under the control of the ESP8266 micro in deep sleep mode. This resistor can be plugged into the header sockets on the board, between D7 and the nearby ground pin. We don’t think the small power saving is worthwhile but you can perform the steps mentioned above if you want to try it. Celebrating 30 Years their colour codes in the table, we suggest you check the values using a DMM before soldering as the colour bands are easy to misread. Follow with IC1; use a socket if you want to but make sure its pin 1 dot is orientated as shown. Next, bend the leads of Q2 so they fit through the board and its tab hole lines up with the corresponding hole in the PCB. Then fasten the tab to the PC using a 6mm M3 machine screw and nut before soldering and trimming the leads. Follow with the 100nF capacitor and then Mosfet Q1. Its flat face must be orientated as shown in Fig.2. Next, fit terminal block CON1 with its wire entry holes facing towards the nearest edge of the board. Then solder modules MOD2 and MOD3, with the orientations shown. You will need to fit a 4-pin header to MOD3 before soldering it to the board. MOD4 can then be mounted to the board, using component lead offcuts (or tinned copper wire). Solder the four wires to the board, then feed them through the holes on the module and push it down before soldering it in place. Finally, fit the four long-pin headers in place along the edge of the PCB, with the socket parts on the top of the board and the pins projecting from the bottom. To do this, you need to solder around the bases of the pins, where they emerge from the bottom of the board. Setting the sensor voltage Before programming the Arduino board, it’s a good idea to adjust MOD4 to give a sensor supply voltage of around 24.2V. It’s easier to do this before the software is loaded because that software will shut down the sensor supply most of the time, to save battery power. Plug the finished shield into the WeMos Arduino board and then connect a spare resistor between pin D7 and 5V. You can do this by plugging the resistor leads into the sockets on top of the shield board. We must caution you that pin D7 is not correctly labelled on all WeMos D1 R2 boards. It’s the ninth digital pin, ie, the second one located on the second 8-pin header on that side of the board. Our WeMos board incorrectly labelled the digital pins 0, 1, 2, 3, ... rather than the correct labelling, which should be siliconchip.com.au TX, RX, 0, 1, 2, 3, ... Having done that, plug the board into your PC’s USB port and measure the voltage between VIN+ and VINon MOD4. You should get close to 5V. Now measure the voltage at the output and adjust the onboard trimpot until it’s close to 24.2V. Note that you will need to turn the trimpot screw anti-clockwise to increase the voltage (counter-intuitively). When finished, remove the extra resistor you plugged in earlier. Should you need to re-adjust this output voltage when the software is loaded, MOD4 will be powered up for a few seconds each time the unit boots up, so you can press the RESET button and quickly measure the output voltage before tweaking the adjustment screw. Or alternatively, unplug the shield and apply 5V via its interface pins, with the extra resistor connected as described above. Loading the software Now unplug the shield from the WeMos ESP8266 Arduino board and re-connect it to your PC using a USB cable, so you can load the software. The Arduino sketch is a .ino file and it can be downloaded from the SILICON CHIP website (free for subscribers). The download package (zip) also includes the required libraries to build it but you will also have to download and install the ESP8266 board files onto your PC. First, install the latest version of the Arduino IDE, if you don’t already have it. This can be downloaded free from www.arduino.cc/en/Main/Software Next, install the ESP8266 board files. This is also a free download but it’s quite large and will take a while. To do this, open up preferences in the Arduino IDE and under “Arduino Board Manager URLs”, enter: http://arduino.esp8266.com/stable/ package_esp8266com_index.json Hit OK, then go to Tools -> Boards -> Board Manager, type in “esp8266” in the search box, click on the entry The “heart” of this project is the purpose-designed water sensor, as shown here. It is rated to measure up to 5m depth (so can handle a pretty large tank!) and comes complete with a 6m cable. Like the other specialised components in this project, it is available from the SILICON CHIP Online Shop (Cat SC4283). which appears below and then click on the “Install” button. This will result in around 160MB of compilers and associated files being downloaded and installed on your computer. You can now go to the Tools -> Board menu and select the “WeMos D1 R2 & mini” entry from the drop-down list. Next, install the supplied libraries using the Sketch -> Include Library -> Add .ZIP Library option, if you didn’t have them already. Setting up a ThingSpeak channel When the unit is operational, the water tank level, temperature, humidity and barometric pressure will be logged periodically to a free internet host called ThingSpeak.com. They store this data in their database and you can then log in and view and plot the data from anywhere in the world. You can also make the plots publically available. Before you finish loading the software, you will need to go to www. thingspeak.com and set up a free account (if you don’t already have one). You will also need to set up a “channel”, which the data will be associated with. Basically, channels let ThingSpeak users track multiple, different sets of data. Create a channel via the website, then click on the “Channel Settings” Resistor Colour Codes     No. Value 1 100kΩ 1 15kΩ 2 1kΩ 1 10Ω siliconchip.com.au 4-Band Code (1%) brown black yellow brown brown green orange brown brown black red brown brown black black brown 5-Band Code (1%) brown black black orange brown brown green black red brown brown black black brown brown brown black black gold brown Celebrating 30 Years tab and enter whatever name and description you want. Then set up the fields as follows: * Field 1 – “Water Tank Level (%)” * Field 2 – “Temperature (C)” * Field 3 – “Humidity (%)” * Field 4 – “Atm Pressure (hPa)” * Field 5 – “Water Tank Level (raw)” * Field 6 – “Temperature 2 (C)” * Field 7 – “Min Tank Level (raw)” * Field 8 – “Max Tank Level (raw)” You can change these names if you want to, the above is only a guide as to what you need. You can enter the elevation, latitude and longitude of your water tank if you want so that the website can show the location where the data is coming from on a map. Having set that all up, click on the “API Keys” tab and make a note of the Channel Number and Write API Key. Next, open up the sketch and modify it so that it can connect to your WiFi network. Near the top of the file, you will see four lines similar to the following: //Constants char WiFiSSID[] = “xxxx”; char WiFiKey[] = “yyyy”; unsigned long myChannelNumber = 1234; const char * myWriteAPIKey = “zzzz”; Change the WiFiSSID[] and WiFiKey[] strings (shown as xxxx and yyyy here) to suit your WiFi network. Then set the myChannelNumber and myWriteAPIKey values to match those you noted earlier when setting up your ThingSpeak account. You can then compile/verify the sketch (CTRL+R) and it’s ready to be uploaded to the WeMos board (CTRL+U). Note that the compile/verify stage February 2018  27 The solar-powered charger consists of a pair of 100 x 70mm solar cells connected in parallel, an Elecrow mini solar charger module (solar cells and charger are available from the SILICON CHIP Online Shop) – see www.siliconchip. com.au/shop –and 3.7V Li-ion battery pack (we salvaged ours from a mobile phone). A pair of schottky diodes in series with the solar cells prevent the cells from loading each other when in partial shade. can take some time (one minute or longer) and the upload process will only start if the compile/verify was successful. If it is successful, you should get a message like the following: Sketch uses 241,141 bytes (23%) of program storage space. Maximum is 1,044,464 bytes. Global variables use 33,292 bytes (40%) of dynamic memory, leaving 48,628 bytes for local variables. Maximum is 81,920 bytes. If there are any errors during this process, messages will appear at the bottom of the Arduino IDE instead, indicating the problem. The most common problem would be if one of the required libraries has not been installed or you already had a conflicting library installed (eg, an old version). Other possible problems are the wrong Board selection or an incorrect change when setting up the WiFi network and channel details. Assuming the code is successfully compiled and uploaded, unplug the ESP8266 board from your PC and plug the shield into it. You are then ready for a proper test. Testing Initial testing can be done by simply plugging the shield into the pro28 Silicon Chip grammed WeMos Arduino board and applying power via the USB cable from your PC. Not only is this convenient but it also means you can monitor the debugging messages in case something goes wrong With the Arduino IDE open, plug the WeMos board into your PC’s USB port and then open the Serial Monitor by pressing CTRL+SHIFT+M (in Windows) or via the Tools -> Serial Monitor menu item. If the Serial Monitor doesn’t open, eg, you may get a message such as “Board at COM7 is not available” at the bottom of the IDE window, you need to select the correct serial port via the Tools -> Port menu option. Then try opening the Serial Monitor again. Once it’s open, make sure the baud rate is set to 115,200 and then press the reset button on the WeMos board. It’s in the corner, next to the USB socket. You may see some “garbage” characters on the Serial Monitor, and then you should get a display like: ESP8266 in normal mode ........... WiFi connected 192.168.0.43 min = 450, max = 450 Uploading data... Done. Celebrating 30 Years If, after the “ESP8266 in normal mode” message, all you see is an ever-increasing row of dots, that’s a sign that the unit is unable to connect to your WiFi network. This could be due to the SSID or encryption key being set incorrectly in the sketch, so check them carefully. If they are correct, you may need to change your router settings to allow the unit to connect (eg, by adding its MAC address to the list of allowed addresses). Or it may be that you’ve set up your router to use an encryption scheme that the ESP8266 does not support. Our router is set up for the modern “WPA2PSK (AES)” method and it works fine. If your device connects to WiFi OK but you get “Error.” rather than “Done.” then that means there was a problem uploading the data to ThinkSpeak. Check that you have set the correct channel number and Write API Key. Assuming it’s working, you can log into the ThingSpeak website and see the (for now, incomplete) data. The charts in your channel will automatically update a few seconds after new data arrives. If you wait long enough (around 10 minutes), you should see the device wake up and then send another set of data points over your WiFi network. Note that the water tank level percentage figures will be invalid because the sensor is not attached and it has not been calibrated yet. The raw/minimum/maximum water tank level values should be a figure on the order of 500 (out of a maximum 65,535) with no sensor attached. Now you can power the unit down and temporarily connect the sensor to CON1, with the red lead to the + terminal and the black lead to the – terminal. Power the unit back up and check the raw data that was logged to ThinkSpeak.com With the sensor in open air (ie, not underwater), our prototype gave a reading of just over 20,000. This should increase if the sensor is put at the bottom of a bucket of water. Note that calculations suggest the reading for a sensor current of 4mA should be around 12,700 but the sensor could draw more than 4mA even at atmospheric pressure and there is also an error due to the input offset voltage of IC1, so the initial reading could be anywhere in the range of about 10,000 to 22,000. siliconchip.com.au Assuming you’re getting a sensible reading, power the unit down and you are ready for the final steps. Final assembly Now to mount the unit in a waterproof box for installation outdoors. We used an IP65 sealed case with clear lid (available from Altronics or Jaycar). It measured 170 x 120 x 55mm which gave us enough room to fit all the parts, including the battery and charger board. We glued the solar panels to the inside of the clear lid, which had just enough space. We recommend using neutral cure silicone sealant to do this. You can also use the same sealant to hold the Arduino PCB, battery and charger module in place. See the internal shots of our prototype for an idea of how you can arrange them. Remember to leave room to plug in the USB cable that goes between the charger board and the Arduino (and so that you can still connect the Arduino to your PC in future, should that be necessary). The two main holes needed to be drilled are a 19mm hole for the cable gland and a 6.5mm hole for the SMA WiFi antenna socket. We placed these on either side of the internal rib at the end of the case, making sure there would sufficient space around the cable gland hole to allow us to fit the internal nut. Remember we mentioned earlier that the barometric pressure and humidity sensors will need access to the outside air to give proper readings. We don’t want rain or other nasties to get into the box but we can’t have it completely sealed either. So we drilled four 3mm holes in the bottom of the case, near the middle, and glued a piece of open-cell foam over them. That will allow outside air to mix with the air inside the case while preventing moisture, dirt and dust from getting in. The box will be orientated so that rainwater will not block the holes in the final installation (ie, with the bottom facing down). Solar panel wiring Once the silicone holding the solar panels onto the inside of the lid had cured, we soldered the anodes siliconchip.com.au of schottky diodes D1 and D2 directly onto the + output pads of the two panels and soldered the cathodes together. The 2.0mm JST cable was then soldered with the positive lead to the joined cathodes of D1 & D2 and the negative lead to the – output pad on one panel, which was then connected to the – output on the other panel with a length of hookup wire (see the photo opposite). We didn’t apply any insulation to the diodes nor anchor them (except via soldered joints) but if you are at all concerned, a thin bead of silicone sealant will both hold them in position and also insulate them. Be careful with the polarity of the JST cable because unfortunately there is no standard for which wire is red and which is black. You need to plug it into the solar input on the charger temporarily to check which wire goes to the + input and make sure that the wire on that side goes to the diode cathodes (we try to supply wires with the correct colour coding with our modules but it isn’t guaranteed). If you haven’t already fitted the cable gland and antenna socket (assuming you’re using one), do so now, then feed the sensor wire through the gland and attach it to the terminal block. Do up the gland tightly to make sure no water can get in and screw the antenna onto the socket. You can then plug the battery into the charger board and the antenna cable onto the Arduino board. Fit the Arduino shield, connect the USB cable which carries power from the charger and plug the lead from the solar panels into the input on the solar board. You can then fit the lid to the case using the supplied screws and waterproof gasket, which is inserted all around the channel in the lid before it is screwed into place. Drop the sensor into the water tank and find a location to mount the main unit where it will receive as much sun during the day as possible, especially in winter. Unfortunately, many water tanks are right next to a building, making this difficult. You may need to mount the unit on a fence post nearby. If the unit stops transmitting data in the early morning in winter, you’ll know the solar panels aren’t getting enough sun to keep the battery chargCelebrating 30 Years er and more (or larger) panels, or a mains power supply, will be required to keep it going. Calibration This is essentially automatic as the unit keeps track of the highest and lowest readings and uses these as the 100% and 0% levels. That means to calibrate the unit, once it’s powered up and running, the tank needs to be filled. If it’s a rainwater tank, you could fill it with a hose, or just wait for a good storm! It checks the last eight readings and if the minimum of all those readings is higher than the maximum value that’s stored in EEPROM, the stored maximum value is updated. This prevents a brief glitch from affecting the maximum value. So basically, once the tank is full, that should be recognised as the 100% level after an hour or so. The same is true (in reverse) for determining the minimum level. But if you powered the unit up for a while with the sensor attached, before it was put into the tank, that should have given the unit time to ascertain the minimum level anyway. So it might be a good idea to leave the unit running for an hour or two before dropping the sensor into the tank, just to be sure. The unit ignores readings with raw values below 5000 for setting the minimum level so that if the sensor is disconnected, it won’t cause the minimum reading to become incorrect. If you ever need to force the unit to recalibrate, you can run a wire between pin D8 (ESP8266 pin 15) and 3.3V and then press the reset button. That will force it to forget the stored minimum and maximum values and calculate them again. You could just let this happen naturally, as the tank empties and fills, or take the sensor out of the tank temporarily (for an hour or two) to re-establish the minimum level, then put it back in and wait for the tank to fill (yes, it will rain eventually!) so it can re-measure the maximum value. The minimum and maximum values are then used to determine the percentage figure which is logged to your channel. The raw values are always logged, so you can re-calculate the level later if you have more accurate minimum and maximum readings on hand. SC February 2018  29