Tuesday, June 30, 2015

16: Battery Backup
Post 11 corrected
** revised again 7/16/15 **

When I tested my battery backup circuit (post 11) I failed to let the systems run on both USB input and battery for long enough. Turns out with 5V/1A input from my USB hub the setup drains the battery. And when that happens the USB output drops to 4.10V. Not nice. However, USB input of 2.1 Amps seems to correct the problem.  Wrong again: Anyway, the setup pictured only works if the USB out draws less than 500mV. None of my Nano test setups take this little -- nor does my Particle Core. So regardless of 5V USB input the the system fails when the battery runs down (USB output drops to 4.1V).

Gory details at http://forums.adafruit.com/viewtopic.php?f=15&t=76014

Most USB hubs don't provide 2.1A outputs. So I ordered a 5-pack of 2.1A wall plugs. I'll let you know how they work long-term.

Saturday, June 13, 2015

15: Soil Moisture Sensor: Arduino and Particle Core
-- revised --

I programmed this first on an Arduino Nano. Pretty easy. My guesses at wiring did no damage. The "sunkee soil hygrometer" (probably meant "hydrometer") was mostly marked in Chinese. One tricky part: once you start the program the probe device is on all the time -- drawing current. I first considered turning it on & off with a transistor. But then I wondered, why not just use a digital pin. I don't know if this is as safe, but it's simple and it works. In addition to short patch wires, I tested this using a 50' CAT5 cable between the probe and the interface. It worked fine. See post 27 at http://dicks-raspberry-pi.blogspot.com/.

I had expected these things to be bigger. 
Probe points only about 2" long.
Adjustment screw only useful for digital (ON/OFF) output.

Here's my Particle Core code. The Core can be read anywhere wifi is available (if you know the codes). So the Core can be remote from my Raspberry Pi control program.

/* device: "sunkee soil hygrometer" [SP?]

2 wires from probe "YL" & "69" (?) to interface board 
  no-label<->(YL) & GND<->(69?)
4 wires out to Arduino: "VCC" "GND" "D0" "A0"

Arduino or Particle/Core -- just guessing:

VCC -- 5v (or 3.3) 
  Arduino 5v: analog range=1023:200 (10 bits), 
  Core: analog range=4095:2000 (12 bits)
D0  -- unused: just on/off
A0  -- analog pin
int soil = A3; // read the device
int power = D1; // turn power on just for the reading

void setup() {
    Spark.function("soil1", Soil); // Core-only function
    pinMode(soil, INPUT);
    pinMode(power, OUTPUT);
    digitalWrite(power, LOW);

void loop() {
    // not used

int Soil(String command) {
    digitalWrite(power, HIGH); // turn probe on
    delay(200); // let it settle?
    int raw = analogRead(soil); // high=dry, low=wet
    digitalWrite(power, LOW); // turn probe off
    int read = map(raw,4095,2000, 0,20); 
    return read; // return reading between 0 & 20