Tuesday, April 25, 2017

Display a TextBox only when a Radio Button is Checked

I was working on one of my websites this week, and needed the ability to allow the user to input some text only when a certain radio button is checked, and make the TextBox go away when another radio button is checked. All the TextBox's are hidden on page load, then activated when the "Other" radio button is checked. I also use placeholder="" to give the user some idea of what goes into the box.  After a few tries, I got it working and figured, if I needed this, others may as well, and to save you some time and angst, here is my code. Works well in HTML or PHP (just add echo' ... '; pieces).



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 http://arduino.esp8266.com/stable/package_esp8266com_index.json 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 https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide 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 https://arduining.com/2015/08/20/nodemcu-breathing-led-with-arduino-ide/

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 http://arduinotronics.blogspot.com/search?q=mosfet

Saturday, December 31, 2016

Arduino Cousins Rejoined in 1.8.0

The two forks of the Arduino IDE have been rejoined into one. No longer are there separate IDE's from Arduino.cc and Arduino.org. Boards from both companies and new additions from Adafruit are supported. This is great news for the Arduino Community. Requires Java 8 to run, but well worth the upgrade!

Arduino IDE 1.8.0 works out of the box with AVR boards, like the Uno, Mega, Yun, and Micro, among the most popular. Additionally, it supports the Leonardo Ethernet, Yun Mini, Industrial 101, and Uno WiFi.

The updated SAMD core will provide support for the M0 and M0 PRO, completing the product line that includes the Zero, MKR1000, and the newly-launched Primo and MKRZero.

Wednesday, December 28, 2016

The Pixel OS Controversy

There's been a lot of "news" about the Raspberry Pi Foundations new Pixel OS. Lets dig in and take a look at what the hubbub is all about.

First of all, contrary to much of the misinformation by the BBC, Guardian, and others, it's not an OS.

It's an alternative DE (Desktop Environment), much like gnome, LXDE, and others, that sits on top of a linux OS. That's it, nothing more.

As a DE, it's lightweight (needed for limited resource machines like the Raspberry Pi), and very pretty. It's fully available for the Raspberry Pi, or you You can download an image bundled with debian and try it in preview mode on a intel based pc. Preview mode? Yes, you cannot install it on your computer, as it's a "developmental beta", not an installable DE.

The good news? Eventually it will be a usable option not only on the Raspberry Pi, but other platforms like Intel based pc's. Eventually.

Monday, December 12, 2016

Arduino Model Railroad Animation

As part of my journey looking for new projects for the club layout, I just finished a book called Arduino Model Railroad Animation. It covers using servos to operate semaphores, water tank, cranes and other trackside accessories. This is a good practical guide to electro-mechanical automation using an Arduino as the brain. The authors (Paul and David Bradt) have a few other Arduino books as well that are equally good. We are working on a project using servos to actuate turnouts and microswitches.

Arduino Model Railroad Animation

Arduino Model Railroad Signals

Arduino Force, Pressure, Friction and Acceleration Science Fair Projects

Arduino Heat Transfer Science Fair Projects

Saturday, November 26, 2016

Arduino Model Railroad Scale Speedometer - Finished

We finally finished the Scale Speedometer Project, and are heading off to the Charleston Area Model Railroad Club to install it. We used the Adafruit I2C 7 Segment backpack, a Arduino Nano clone, and two IR transceivers, for  total project cost of around $20. The code below is fully functional, all you need to do is adjust your scale, and distance between the sensors. Make sure your sensors do not extend above the height of the rails, or couplers could catch on them. I used a dremel to route out the holes, and superglue to fix them in place, but superglue leaves a white residue, so you may want to try a different adhesive. Watch the video!

Arduino Nano Clone
7 Segment BackPack
IR sensors

Use the Adafruit Tutorial to assemble and connect your 7 segment backpack. Use the IR Sensor Tutorial to connect the IR sensors.

Update: Decreasing the resistance of the IR LED resistor (we finally used 100 Ohm) or increasing the resistance of the pullup resistor on the photo-transistor (we finally used 100k) can make the circuit more sensitive (up to 15mm depending on reflectance of car bottom), especially for larger scales with larger gaps. Do not burn out the IR LED with too low of a resistance (no less than 68 Ohm, 1/2w at 5v input).

#include  "Wire.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix = Adafruit_7segment();

//user variables
float distance = 24; //inches between sensors
int scale=87;

int sensor1 = 4;
int sensor2 = 5;
bool s1Covered;
bool s2Covered;
float start, finish, elapsed, miles, hours, mph, scaleMPH;

int started=0, finished=0;
int scale=87;

void setup() {
  // put your setup code here, to run once:
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);


void loop() {
  // put your main code here, to run repeatedly:
  //Serial.println("Ready ....");
    if (s1Covered==0 && started==0){

    if (s2Covered==0 && started==1){
  elapsed = finish-start; // millis

  elapsed = elapsed /1000; // seconds
  Serial.print("Seconds: ");
  miles = distance / 63360; // miles
  hours = elapsed / 3600; // hours
  mph = miles / hours;
  scaleMPH = mph * scale;
  Serial.print("Scale MPH: ");
  // print a floating point


Friday, November 18, 2016

Functional TRS-80 Model 1 on Windows 10?

Ok, what does this have to do with Arduino or Raspberry Pi? Well, I am working on a couple of Pi emulating antique computer projects, and said, let's try this! I could use some financial help with a few projects we are working on, so use the "Donate" button found on this page, and I'll send you a zip file with a working TRS-80 Model 1 emulator (ROM included). Just unzip and run an old friend ....

Tuesday, November 15, 2016

Arduino Scale Speedometer Part 3 - Port Expander

The three 7 segment LED's from part 2 require 24 i/o pins on the Arduino. We can use port expanders to limit that to 2 pins, the I2c connections. Each MCP23017 chip supports 16 i/o pins, so two chips will do, and still only use the two lines on the Arduino, as they are addressable. In our previous two MCP23017 posts we show how to connect and address the MCP23017 chips and provide a link to the datasheet.

1st Digit - Chip 1 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5

2nd Digit - Chip 1 Port B Connections:
GPB7 -> A7
GPB6 -> B6
GPB5 -> C4
GPB4 -> D2
GPB3 -> E1
GPB2 -> F9
GPB1 -> G10
GPB0 -> DP5

3rd Digit - Chip 2 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5

To send the speed determined in part 1 to the 3 digit display, we need to break up the number into 3 separate numbers, the hundreds, tens, and ones position. This is done with a simple calculation:


Then in a case statement you can send the correct code to each chip:

switch (var) {
    case 0:
      Wire.write(244); //11110100
    case 1:
      Wire.write(96); //01100000
    case 2:
      Wire.write(218); //11011010
    case 3:
      Wire.write(242); //11110010
    case 4:
      Wire.write(102); //01100110
    case 5:
      Wire.write(182); //10110110
    case 6:
      Wire.write(190); //10111110
    case 7:
      Wire.write(224); //11100000
    case 8:
      Wire.write(254); //11111110
    case 9:
      Wire.write(230); //11100110
    case DP:
      Wire.write(1); //00000001
      // if nothing else matches, do the default
      // default is optional

Now, if all this seems very complicated, and the 24 wires from the 3 digits to the two MCP23017 chips seems like spaghetti, you are right, and we have chosen to go a different path. The Adafruit I2C 4 digit display. More on that tomorrow .....