Friday, March 31, 2017

Calculating Amp Hours and Watt Hours

In previous posts we have described how to make a volt/amp/watt meter to measure power consumption, or production (solar, wind, etc). I never fully explained the watt hour and amp hour calculation, so here is a sample sketch that assumes you are measuring voltage and current with the appropriate sensors.

I'm flushing the daily data every 24 hours, but keeping a running total. You could save this data to a sd card or publish it to a web server.

This is much easier to read on a LCD instead of the serial monitor.


float volts = 120; // get value from voltage sensor
float amps = 100; // get value from current sensor
float watts = volts * amps;
float kwh;
unsigned long totalET;
float dailykwh;
float totalkwh;

void setup() {


void loop() {
  uint32_t ts1 = millis();
  delay(1000); //reports at 1 second intervals
  uint32_t ts2 = millis();

  // print the time interval in seconds
  uint32_t ts3 = (ts2-ts1)/1000;
  totalET = totalET + ts3;
  Serial.print("Seconds: ");

  kwh = watts * ts3 / 3600000;
  dailykwh = dailykwh + kwh;

  Serial.print("Volts: ");
  Serial.println(volts, 4);
  Serial.print("Amps: ");
  Serial.println(amps, 4);
  Serial.print("Watts: ");
  Serial.println(watts, 4);

  //Serial.print("Current Ah: ");
  // numbers so small it's not relevant.
  //Serial.println(kwh/volts, 4);
  //Serial.print("Current KWh: ");
  // numbers so small it's not relevant.
  //Serial.println(kwh, 4);

  Serial.print("Daily Ah: ");
  Serial.println(dailykwh/volts, 4);
  Serial.print("Daily KWh: ");
  Serial.println(dailykwh, 4);
  totalkwh = totalkwh + dailykwh;
  Serial.print("Total KWh: "); //from reboot
  Serial.println(totalkwh, 4);
  if (totalET >= 86400){ //restart every 24 hours
  ts1 = 0;
  ts2 = 0;
  totalET = 0;
  dailykwh = 0;

Wednesday, March 29, 2017

Outlook lost it's search capability?

This is a bit off topic for this blog, but since Outlook is a common email client, I thought I'd pass along a little tip.

All of a sudden, Outlook started responding to searches with "No Results Found". Called Microsoft, and wonder of wonders, they sent out a bum patch. While they are attempting to fix, there is a work around. Revert back to a working build.

In Outlook, click File, Office Account, and set Update Options to Disabled.

Open a cmd prompt as administrator (right click on the command prompt icon and choose More, run as administrator).

In the cmd prompt, type (or copy / paste):

cd %programfiles%\Common Files\Microsoft Shared\ClickToRun

press Enter, then do the same with this command:

officec2rclient.exe /update user updatetoversion=16.0.7571.2109

This will run a lengthy update, but when finished, Outlook will have it's search back.

Set a calendar reminder to turn the updates back on in a month or so.

Wednesday, March 22, 2017

Arduino ESP8266 WiFi, on the Cheap!

If you are looking for Wifi for for your Arduino Project, look no further! For less than $9 you can add wifi capability to your Arduino Project, without loading down your Arduino with a bunch of network access code. We used a HiLetgo New Version NodeMCU LUA WiFi Internet ESP8266 Development Board for the access link. Now this board has a bunch of 3.3v I/O capability all on it's own, and is easily programmed using the Arduino IDE, but our goal is to use a Arduino NANO for I/O and just use the ESP8266 for the network link.

Installation was not straightforward, but not difficult either. The board uses a standard USB A-Male to Micro B cable used with most cell phones. Plug the cable into the ESP8266 and your computer. If you are on Windows, check your device manager to see what port has been connected. If you have a yellow exclamation mark on the device (Silicon Labs CP210x), right click it and choose Update Driver Software.

Now open a recent version of the Arduino IDE (1.6.4 or greater). Under File - Preferences, add to the Additional Boards Manager URLs field, and click OK.

Now go to Tools - Board - Boards Manager and scroll down to ESP8266. Select ESP8266 and click Install.

Now to use the board, Go to Tools - Board, and select the Adafruit HUZZAH ESP8266. Others may work better, but that's the one I started with.

Remember, this board uses 3.3v logic, so no 5v connections to the I/O pins.

The sample sketch I tried worked first time, and connected to the web server right away. See for code.

Use the D0-D10 and A0 pins printed on the board the same as the pins on an arduino (given the 3.3v caution). The pinouts are below:

For a cool "Breathing" effect of the onboard LED at pin "0" (D0, or GPIO16), see

Wednesday, March 8, 2017

Encryption fun, win an Arduino!

Here's a challenge for you all. I'm posting a picture, and a coded phrase. Figure it out, email me, and the first 5 winners get an Arduino Nano clone, and their names (or hacker names) listed as really smart (and geeky) folks!

59221 91430 8117 94007 21268 100714 58135 73658 29992 52388 103243 47570 29961 38689 74327 56189 45120 64972 81138 106187 18809 11348 10965 32969 70849 96470 6350 56264 69516

After the contest is over, I'll post the code, and some really interesting tips on passing virtually unbreakable messages.

Clue: it's a variation on a book cipher!

Next Clue: the numbers above are the positions of the characters in the "book".


The image is base64 encoded. That creates the book. Then go to position 59221 and write down the letter found, then position 91430 , and so on.

In the files below, I've built a php based set of utilities for choosing an image, saving it in an uploads folder, and creating the encoded ascii file. You then can input the string to be encoded, and it returns character positions from the "book".  I used a date/time seeded random function to choose one of the available results for each character submitted to reduce the possibility of repeat distribution hacking.

The decode file takes those position codes, and spits out the original phrase. No one has posted the phrase, but the contest is over. Hope you had fun!

Tuesday, February 14, 2017

KK4HFJ HF Station is up and running!

I finally made the move from 2m EmComm's to HF work. I'm still working 2m off the local repeaters, but it's nice to be able to reach around the world. I installed a Kenwood TS-430 HF rig, a AT-250 Antenna Tuner, a MFJ G5RV dipole, and a dell server power supply to keep it all fed and quiet. You can find me most evenings on 40m, usually around 7.18 Mhz.

KK4HFJ Monitoring .....

Friday, January 27, 2017

STEMTera - Arduino in a LEGO Breadboard

Sparkfun is coming out with a new breadboard that includes a Arduino in a LEGO compatible base. All the ATmega328P and ATmega16U2’s I/O pins are broken out and available. The breadboard has shield compatible pinouts (yes, the weird offset is there). A bit more than you would pay for a Arduino UNO, but the convenience of having a breadboard and complete access to all the pins makes up for it. This is a perfect teaching tool!

Tuesday, January 3, 2017

Model Railroad Crossing Lights

For the Charleston Area Model Railroad Club, We have combined our train detector circuit from the scale speedometer project with a LED Crossing Light to make it simple to indicate a train is coming to a crossing. The next step is to add a servo operated crossing bar, and bell sounds, but I'm getting ahead of myself.

The Circuit:
The detection circuit is the same as the scale speedometer. A TCRT5000 IR LED / Phototransistor pair, with two resistors, connected to an Arduino input (D8). You can lower the value of the Phototransistor pullup resistor to 10k-50k ohm (instead of 80k-100k ohm) to reduce it's sensitivity to ambient light. Increase the value of the IR LED resistor (68 Ohm) to reduce range. Never drop IR resistor below 68 Ohms.

The output is a off the shelf LED crossbuck with 2 red LED's and a common anode. I put a 300 ohm resistor on the common and connected to 5v, and connected the two cathodes directly to arduino outputs D11 and D12. Add a second LED Crossbuck (with resistor) to the same outputs for the other side of the crossing. See the video below the code.

The code checks to see if the phototransistor is lit (a 0 or LOW), and activates the lights (LOW is lit, HIGH is off)) as long as it is.

//int sensor1 = 1;

void setup() {
  pinMode(8, INPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);

  int sensor1 = digitalRead(8);
  if (sensor1 == LOW){
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);

Finished board for two track sensors and 2 crossing lights.

Monday, January 2, 2017

Model Railroad Turnout Control - Arduino MOSFET

One of the projects we are working on is Turnout Control. Most home layouts are using Atlas or Bachmann track with solenoid type turnouts like the one shown here. More professional layouts use slow moving motors like the Tortoise. Our goal is to make these turnouts controllable with an arduino, so that future projects using train detectors and DCC can allow more automation. So here is the beginning of our project. This one uses the above Bachmann turnout (arduino servo control article coming soon), a arduino nano, two IRL520 MOSFETS, two resistors, and two diodes. The schematic is as follows:

The diodes protect the MOSFET from inductive spikes when the solenoid coils fire. The two MOSFETS engage the solenoid coils to move the turnout. the two resistors keep the MOSFET from randomly conducting when there's no input signal, by pulling the gate to ground (off). This uses two digital outputs on the arduino called straight and turn. The next article will show the board layout and wiring of the arduino, turnout and power supply. For more projects based on MOSFETS, see