Tuesday, 30 June 2015

Arduino shed/outdoor monitor, batteries and solar panels

A brief update, I put in place my shed/outdoor monitoring system last weekend, installed the solar panel and monitors, and have so far had to change the batteries already, so at the moment it looks like they are only lasting 3-4 days maximum.

Upon investigating my 9v solar panel is giving out 2-3 volts, which is pretty useless. I'm trying to charge my 4 AA batteries (6 volts).

So my next plan of action is to take the solar panel back down and work out why it's only producing this very low voltage, I'm now wondering if the connections on the rear split the panel into two and I'm only connecting to one half (even so doubling 3 volts isn't near the 9v I was expecting), so a bit more investigation is needed.

(Yes I removed the plastic film cover! But it is inside a plastic box for protection, but even so I'd not expect the voltage drop to be that dramatic)

Graphs were being produced before the power failure though as you can see below:

(note the flat line towards the end is where the batteries died and I'd not written a failsafe into my graphing to 0/ignore results)

Monday, 22 June 2015

Arduino ESP8266 1-wire Dallas temperature, soil, rain, moisture, solar power unit

Arduino Uno outdoor sensors project. Here is the first posting for my Arduino UNO outdoor monitoring unit. The idea for this is to act as a small weather station, and also to feedback on the condition of the garden. So this is my second version of my earlier garden controller (several years ago).
I bought a bunch of sensors recently, which included:

  • 1-wire Dallas temperature sensor DS18B20
  • Rain sensor module with LM393
  • Light dependant resistor LDR5528 (+10k resistor)
  • Soil moisture sensor with LM393
  • ESP8266 wifi module
  • 9v Solar panel + 1N4007 diode
  • Water float sensors (x2)

The goal is to setup a stand-alone Arduino that will connect to my wifi (signal may be an interesting problem, we'll come to that) and then feed back a lot of environmental information to my server, that I can then graph/log and alert depending on the inputs.

First job was to get the ESP8266 wifi module working. This was a new item to me, but it's principle was simple, it was a stand-alone wifi module that you could communicate using 2-wires serial (TX and RX), so you could open a serial session, connect to your wifi AP using WPA2, WEP, etc, and then set it to send data in an HTTP GET session. The simple commands made this an excellent add-on for me to include in my project, and the price is excellent (Around £3).
Connecting it up, you need power (3.3v), also you need to pull CH_PD to positive, which I did through a 10k resistor. So my wiring diagram worked out as:
(Credit to enio in arduino forums for image)
I connect VCC, GND, CH_PD for power. then TX and RX to the Arduino. To test the connectivity I used my Arduino UNO, loaded a blank sketch and connect RX to data_rx and TX to data-tx (pins 0 and 1 digital), that let me type into the serial console and it was passed straight to the ESP8266. Various AT command sets are available all over the internet, so a few tests I did:
(Full list on wikipedia http://wiki.iteadstudio.com/ESP8266_Serial_WIFI_Module#AT_Commands)
After receiving valid replies I knew the unit was operating correctly, and making a quick sketch to connect to my WIFI using softserial started working (using softserial allowed me to use alternative digital pins for talking to the ESP8266 whilst still having my serial console to monitor and upload sketches).
After some trial and error, I found this wifi module dropped out or didn't respond to commands. Upon checking various forums and information, I found this was probably due to the current this was pulling. Originally I was powering it via the 3.3v output on the Arduino, however this couldn't provide enough power, especially when I added all my other sensors, etc and I started to get issues with no reply to the AT commands. Therefore I decided I needed to power this separately. The solution (since I would be powering this from a bank of AA batteries) was to use a LM2596 DC-DC step-down power supply (also known as a buck converter).
I set this up on my multimeter and set it to produce 3.3v so this would supply the ESP8266 directly. (I'll have to see over time how inefficient this method would be, as I know it'll be wasting energy from the battery packs)

1-wire temperature sensor DS18B20
I've used these temperature sensors many times before, I have one in each of the Raspberry PI's around the house and have created a basic temperature 'network' within the house to monitor room temperatures in previous blog posts. I'm using the same sensor again, so as before simply connecting the 3 pins up and including the "OneWire.h and DallasTemperature.h" libraries into my sketch and it was up and running. PIN connections for the DS18B20 are as follows:
So in my setup (You can't quite see this in the picture unfortunately as it's wrapped in black tape) I have connected GND to ground, VDD to +5v, DQ to a digital pin, and then via a 4k7 resistor DQ is also connected to 5v.

Soil moisture sensor with LM393
The soil moisture sensor is a regular two pin/probe style that you stick in the ground, and then measure the resistance between pins. The unit I bought came with a basic LM393 control circuit shown below:

The pin connections are simple, on the left you connect the soil measuring probe, the right are 4 connections, top and bottom are +VE (3.3v) and GND, then you have an analogue out or digital out. The digital out (high or low) is controlled using the variable resistor on the board, so you can set the threshold. I opted for analogue so connecting to the analogue inputs and then read the values shown. Read this as a typical integer from the digital input.

Rain sensor with LM393
This is the same as the soil moisture sensor and came with the LM393 sensor as above.

9v solar panel
To power my arduino I decided to go with a battery pack and use a solar panel to top the batteries up. I purchased a battery pack, the model I chose had 6xAA batteries so produced approx 9v. This created several problems. Firstly the cheap solar panel I bought only produced 220ma 2 watts at 9v, so even at full sunlight it was producing the same voltage as the batteries, therefore this would not charge them (generally you need a higher voltage to charge) and at low current.
Therefore I decided to modify my battery pack to exclude 2 AA batteries, taking the voltage down to 6v which would be more suitable for the solar panel to charge them, and also will reduce the amount of power lost through the heat dissipation on the Arduino Uno.

(NOTE, I'm not an expert on batteries and power, so please do correct me if I make some glaring errors here!)
These are the solar panels I'm using (A chinese import) and currently with their protective plastic film over them. I'm planning on fitting these into a plastic container, to keep them protected from the elements. Although this will reduce their output slightly it will protect them over time.
I should also mention that I have connected in a 1N4007 1A 400v rectifier diode to ensure no power from the batteries are lost back into the solar panels during darkness, etc.
Below is the power pack that I've put in my two dummy batteries to reduce the voltage/number of cells:

Testing the Arduino Uno and the LM2596 powering all the devices the pack was providing enough power. I'll monitor this for amount of current consumed, etc, later in the testing/implementation.

Light Dependant Resistor LDR5528
This was a simple off the shelf LDR that I connected up to the Arduino analogue input ports with a 10k resistor in parallel (to the 5v feed). I then read this during the normal sampling periods.

The code I've used is a combination of various of my older projects put together with some libraries to control the various input sensors. The libraries I've used are as follows:
#include <LowPower.h> - This is to be used to help reduce idling power consumption

#include <stdlib.h> - for dtoi and related functions
#include <SoftwareSerial.h> - for communication to the ESP8266
#include <OneWire.h> - for the 1-wire temperature communication protocol
#include <DallasTemperature.h> - 1-wire temperature

I set a few definitions near the top of the code (for SSID, WPA2 password and the url to GET when sending data).
Setup involves setting the various input and output pins to their relevant values and initialise the softwareserial.
The main code loop is fairly straight forward, I read each of the sensors in turn, display the output to the serial monitor and then use the ESP8266 to send the data to my webserver.

The code is available in full on my github page, so feel free to take a look, and if you can spot any improvements please commit them as I'd like to get some feedback and improvements on my code:

(NOTE: There are a few extras I've missed off here, I'll post further blog entries with tweaks and changes as I make them and when I implement the final system)

Friday, 12 June 2015

Follow up to Marmitek/Haibrain SC9000 PSU failure

This is a bit of a follow up to my previous post on the Haibrain SC9000 X10 alarm unit that I use at home. I decided to bite the bullet and purchase a replacement power supply (£15 so not cheap, but then again not too pricey) and it arrived a few days later. I've finally got round to fitting it and as I did made a few observations and notes for the future.

I took quite a few photos which are all in this post, so apologies for it being graphically heavy.

Firstly, the new unit arrived, and unboxing showed it to be identical to the original, no change to voltage, current, etc. So first thing I did was connected it up as a test and checked, yep the alarm would now sound and all the X10 commands started to flow, so it appears this IS a faulty power supply that causes the alarm sounder not to trigger and the X10 commands to fail. At least I'd now determined the root cause of the fault, it wasn't the overall alarm unit.
Next, I wanted to try and see WHY the original failed and if possible make the new one last longer. One thing I'd always noted was that it ran hot, as most step-down transformers give off heat this isn't unusual, but they generally have vents or at least some way of expelling the heat. This one doesn't, the power supply is a sealed black brick, no vents or anything and when I say it ran hot, you wouldn't want to hold it in the palm of your hand long, it's that sort of heat. So my thinking is I give it some vents before I put the new one into service to help loose the heat, my thinking is most electronics prefer to run cool than hot and it might stop the failure occurring again.
This meant my favourite (ha ha) thing of all time, take something brand new that I've just paid for, take it apart and modify it! But luckily these PSUs have 4 clear screws and a simple case, so taking it apart isn't a challenge. Once opened up, split the two halves of the case carefully as one circuit board stays in one side, the other in the base as you can see from this photo with the case carefully separated:

The right is the "base" which has the main transformer and a circuit board that covers the base, along with at the top right the 2-pin mains in socket.
The left "top" holds a much smaller IC-containing board and the output wire that feeds to the alarm (4-wire). The small circuit board has a single screw in it (just visible on photo, bottom left) so take that out and the top casing comes completely clear. This was ideal, my thinking was to make air vents right along where that bulky transformer sat as that's where the heat was generated, and it was VERY snug alongside other electronics, so a good bet.
I set about the case with my dremel, and here I show my failure as a practical/mechanical/precision person, the air holes are horrible, not neat, but I sanded them down so no rough edges and I think they'll do the job.
As you can see they aren't neat, but should allow a bit of heat to escape. Putting it all back together and it looks like the vents are in the right place, right over the transformer.

Now since I fitted the front of the SC9000 to a wall, and then fitted the cable into the gap between the plaster and wall (inside the wall), the next problem was re-feeding the wire to the right place. So I decided not to, and to simply cut the cables and join them back up using a connector block. That way I didn't have to re-trace the cabling in the wall and make life a lot easier!
As you can see, I was feeling quite neat today and even used a connector block (instead of twisting the wires together and taping them together). I then wrapped the block in tape so it was secure and no potential for shorts or anything getting in there.

Putting it all back together, power on and it all worked fine!
(Note for later, when the batteries are low, the green battery light stays on! I thought the power supply had blown somewhere in the process as the green light stayed on. Seems the green light not only shows it's running on batteries, but also that the batteries are low!)

Next, I decided to properly pull apart the old supply, as I'd like to find what failed and possibly fix it, so in future I have a way of repairing these things with just a few parts.
Below are a load of photos of the teardown, I've not yet had time to investigate all the parts but will do very shortly and probably try a trial and error of replacing parts until I discover the failed unit. However as you'll see there are quite a few scorch marks on components, so I'll be starting work there, which is also where I believe the mains part of the circuit resides, hence this bit will be more susceptible to mains spikes, etc, (which is what Marmitek/Haibrain state as the issue when the PSU fails, it's a mains spike)

The main split board from above

The smaller IC board

The top corner of the main board, no obvious damage here.

 After removing the transformer, some scorching of the main board was clear, I'm now suspecting this is where the issue is.

 Underneath shows more heat damage.

 Closer view of the high voltage components that sit almost exactly underneath the transformer.

After inspection I suspect looking at these components closely, however they are only a couple of resistors, so I'm not hopeful that it would be something as simple as these failing!