Thoughts, stories and ideas.

Automated Plant Watering System - Part 1

As I finally found sometime at hand, I decided to attend to one of my long standing projects to automate watering of my plants, which have been through stressful troughs of famine and crests of over-watering.




One of the goals were that the system should last long enough while running off a battery. Secondary goals was the use of soil moisture sensors to optimize further.

Bill of materials:

  1. Digispark Attiny85
  2. Common NPN Transistor
  3. 3.7V LiPo
  4. 3V DC Pump
  5. Diode (or LED)


Its a straight forward circuit with the MCU's output controlling the P of NPN Transistor. The Transistor serves to amplify the current as the DC motors are rated at 200mA while Attiny85 is only able to deliver few milliAmps of current.

I modified Digispark Attiny85 by disconnecting the onboard voltage regulator as it consumes ~1mA of current even when the MCU is in deep sleep. As Attiny85 is rated from 2.7v-5.5v the 3.7v LiPo's 4.1v output would be well within the required voltage range.

A DC Motor is an inductor - so when the motor is turned off, the stored energy in the motor flows back as reverse current. It can be powerful enough to damage the MCU, so a diode connected in reverse is needed. Due to lack of components I improvised by the use of a common LED connected in reverse.

Circuit Diagram

The Program

The MCU is programmed to wake up every second via a watchdog timer interrupt. On wake, it checks if it needs to turn on or turn off the output, performs it and goes back to sleep. This means the MCU is asleep even when the motor is running. The ON/OFF state is maintained with the count of wake up cycles rather than milliseconds - this works as each sleep cycle is 1 second.

Digispark's Attiny85's fuses are set at 16Mhz but the input is not exactly stable due the absense of voltage regulatr, this can lead to drift in timekeeping of few minutes per day.

#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>

#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)
#define adc_enable()  (ADCSRA |=  (1<<ADEN)) // re-enable ADC

#define MPIN 1

unsigned int lpCntr=0;
unsigned int isOn=0;
const unsigned int onInterval = 2; // 2 sleep cycles
const unsigned int offInterval = 60 * 60; //(60 * 60 * 6) - onInterval; //round it off to 6 hours
const unsigned int repInterval = onInterval + offInterval;

void setup() {
  for(int i=0; i<6; i++) {
    pinMode(i, INPUT);
    digitalWrite(i, LOW);

  wdt_reset();          //watchdog reset
  wdt_enable(WDTO_1S);  //1s watchdog timer
  WDTCR |= _BV(WDIE);   //Interrupts watchdog enable
  sei();                //enable interrupts

void loop() {

  // Loop counter reset
  if( lpCntr >= repInterval ) {
    lpCntr = lpCntr % repInterval;

  // Loop counter began, so write high
  if( lpCntr == 0 ) {
    pinMode(MPIN, OUTPUT);
    digitalWrite(MPIN, HIGH);
  if( isOn == 1 && lpCntr >= onInterval ) {
    // Reset the output to LOW if we are done
    pinMode(MPIN, OUTPUT);
    digitalWrite(MPIN, LOW);



ISR (WDT_vect) {

Split mp3's using silence detection

Am listening to audio for practicing dutch comprehension, which essentially consists of a collection of short sentences on repeat. However this audio is available as a single track and for the purpose of shadowing, I wanted individual mp3's.

Enter mp3splt

Install it using brew

brew install mp3splt

Auto detect silence and split

mp3splt -s -d output_folder audio.mp3

This detects the average silence level and uses it to split.


  • -s - Split with auto detection
  • -d - Output directory

Split at specified silence volume

mp3splt -s -p th=-40 audio.mp3


  • -s - Split with parameters specified using -p
  • -p - Input parameters for -s split action
  • th - Silence threshold in dB

Split and remove silence

mp3splt -s -p rm audio.mp3


  • rm - Used in conjunction with -s and -p. Indicates silence is to be removed from the output.

FFMPEG: Combine videos and re-encode

Over the past few weeks, I've taken to recording my Squash games using my Gopro to understand areas of improvement. The video is recorded at 1080p and 60fps, however Gopro splits the video into several large sized mp4 files.

I wanted to combine them together into a single file and re-encoded to reduce the file size significantly and ffmpeg came to rescue.

Combine Files

First order is to combine the files. ffmpeg accepts input text file with each line consisting of the object type ( file  in this case) and the file name. Alternatively it also accepts http and a url as a line item as well.

$ ls *.MP4 | perl -ne 'print "file $_"' > input.txt
$ cat input.txt 
file GOPR4466.MP4
file GP014466.MP4


To reduce file size one can do several things. The easiest is to set the crf flag which indicates "Constant Rate Factor" or the quality of encoding with values ranging from 0 to 51.  0 indicates lossless encoding and 51 the opposite. The default value is 23

$ ffmpeg -f concat -i input.txt -c:v libx264 -crf 28 output.txt


$ ls *.MP4 | perl -ne 'print "file $_"' | ffmpeg -safe 0 -protocol_whitelist "file,pipe" -crf 28 -f concat -i - output.mp4

Books in 2018

Similar to 2016 and 2017, I spent a lot of time reading books. Original goal was to read at least 25, but I managed to read only 24. However, I attribute it to spending a lot time reading genres that were outside my comfort zone, such as philosophy and biographies.

Here is a small collage I built with a python script, of all the titles I managed to read.


1. A Thousand Splendid Suns

Hosseini, Khaled

This was by far my favourite in the entire year. The story was beautiful, heart wrenching & soul crushing tragedy. The collateral damage from the wars fought in the name of proving oneself or beliefs better than others, seemed not very far from reality at all.

The book was as evocative as this other book "The Ministry of Utmost Happiness" by Arundhati Roy. They certainly seemed to exist in the same realistic universe.

2. The Moon Is a Harsh Mistress

Heinlein, Robert A.

I ended the year with a quick blaze through the book. And it read like an action movie which you know is terrible but you watch anyway because its fun.

3. Harry Potter and the Cursed Child: Parts One and Two (Harry Potter, #8)

Tiffany, John

Just 6 years ago, I read the Harry Potter for the first time. It was incredibly enjoyable, nostalgia inducing journey to revisit the universe again, despite the book not entirely living up to the hype of the original series.

4. Space Team (Space Team, #1)

Hutchison, Barry J.

5. Use of Weapons

Banks, Iain M.

6. Stories of Your Life and Others

Chiang, Ted

The change of title of the book to "The Arrival", after a short story became a movie, deceived me into purchasing this. I was throughly confused while I went through the first short about the tower of babylon as I wondered how it related to space and aliens.

7. Killing Floor (Jack Reacher, #1)

Child, Lee

8. Artemis

Weir, Andy


1. Adulthood Is a Myth (Sarah's Scribbles, #1)

Andersen, Sarah

2. Hyperbole and a Half: Unfortunate Situations, Flawed Coping Mechanisms, Mayhem, and Other Things That Happened

Brosh, Allie


1. Mr. Nice

Marks, Howard

2. Alibaba: The House That Jack Ma Built

Clark, Duncan

3. Believe Me: A Memoir of Love, Death, and Jazz Chickens

Izzard, Eddie

4. The Spy Who Came in from the Cold

le Carré, John

5. Kitchen Confidential: Adventures in the Culinary Underbelly

Bourdain, Anthony


1. Zen and the Art of Motorcycle Maintenance: An Inquiry Into Values

Pirsig, Robert M.

2. How to Break Up with Your Phone: The 30-Day Plan to Take Back Your Life

Price, Catherine

3. How to Walk (Mindfulness Essentials, #4)

Nhất Hạnh, Thích

4. The Hidden Pleasures of Life: A New Way of Remembering the Past and Imagining the Future

Zeldin, Theodore


1. A Burglar's Guide to the City

Manaugh, Geoff

2. You Are Not So Smart:

Why You Have Too Many Friends on Facebook, Why Your Memory Is Mostly Fiction, and 46 Other Ways You're Deluding Yourself
McRaney, David

Gladwell, Malcolm

4. Good to Great: Why Some Companies Make the Leap... and Others Don't

Collins, James C.

5. How to Talk to Anyone: 92 Little Tricks for Big Success in Relationships

Lowndes, Leil

Python Deployments Wishlist

Am currently faced with a baffling realisation of the reality that there is no one sane way to deploy python applications.

It's utterly annoying that I cannot just tar a virtual env and use it.
Performing pip install on every deploy is plain ridiculous. Downloading from the internet on every code change with separate virtualenv is a nogo. No RPMs, nope, no way am writing another spec file.


  • Deployment tooling that allows me to go from zero to production with a new application with no setup.
  • No-downtime between deployments (has to work with a single instance)
  • Philosophy of implementations should make sense whether deploying to one or a 100 servers.
  • Controlled activation of the new version of software i.e. traffic shifting.
  • Stable re-producible environment setup everytime (perhaps with ansible).
  • Cli that lets you bootstrap, build, deploy and control activation of software (nginx or via LB).

Am starting to hack a prototype with fabric, python and Ansible, which is already proving to be challenging but looks doable.