Thursday, July 20, 2017

Infra Red Sensor Boards are Here!

The IR Sensor boards finally arrived! We are busy soldering components, writing new Arduino sketches to show off the capabilities of these boards, and preparing for full blown production. New videos are in the works, for when we get back from vacation. Each board supports up to 6 sensors (Reflex or Transmissive), and are ideal for block detection, crossing light / gate sensors, scale speedometers, and more.

The main difference between reflex couplers and transmissive sensors is in the relative position of the transmitter and detector with respect to each other. In the case of the transmissive sensor, the receiver is opposite the transmitter in the same optical axis, giving a direct light coupling between the two. In the case of the reflex sensor, the detector is positioned next to the transmitter, avoiding a direct light coupling.

Using a 6' piece of cat-5 cable, we connected the blue to the Anode of the IR LED, and blue/white to the Cathode. We connected green to the Collector of the photo transistor, and green/white to the Emitter.

I suggest a bit of hot glue once you solder and heat shrink the leads to the TCRT5000 IR pair.

On the board end, blue goes to LED+, green to PT+, and the blue/white and green/white to GND.

See our level crossing application, and our scale speedometer project.

Sunday, July 2, 2017

Posting ESP8266 weather data to server

Last week we connected a ICStation BME280 temperature / humidity / barometric pressure sensor to a a ICStation NodeMCU ESP8266. We displayed the collected data (along with Dew Point and Heat Index calculations) in the serial monitor.

This week we modified the sketch to post those variables to a linux server (could be your own local Raspberry Pi) running MySQL and PHP. We have it set to take a reading every 30 seconds, and post the data to a php page that inserts the data into the MySQL database. The index page displays a table of that data. The time and date stamp has been modified to display the data in the timezone of the location of the sensor. We are working on live gauges and graphs to display this data in real time.''

See the live data at

All code can be downloaded from

Thanks to Nuno Santos and his tutorial at for some fine tuning of my code.

Friday, June 30, 2017

Median vs. Average, Arduino Calculations

If we want to average a set of numbers, we add them together, then divide by the number in the set.

150 + 200 + 0 = 350 / 3 = 116 Average

I'm using int and dropping the fractional parts. Use float if you need them.

But if we want the Median, which is the center, or middle number, we have to sort and compare each number to the others to get a list from high to low, and grab the center number. In this case, the Median is 150.

I've written a sketch that calculates both so you can compare your own numbers, and make it a much larger list:

int a[] = {150,200,0};
int n = 3;

a[] is your set of values

n is the number of values in the set

More info on Mean, Median & Average -

Thursday, June 29, 2017

6 Channel Infra Red Transceiver Sensor Board

Calling all Model Railroaders (ok, it's not just for Model Railroading)! Remember our Scale Speedometer and Crossing Light project? We used IR transceivers in the track to detect a train passing overhead. Perfect for block detection and other projects. We are releasing a 6 channel IR sensor board (fully populated) for use with Arduino, Raspberry Pi, PIC and other microcontrollers. Comes with all components, including the 6 IR transceivers wired to 6' cords. All connections are screw terminals for ease of use. Each phototransistor has a potentiometer for adjusting sensitivity. Operates at 5v or 3.3v (select which version). Comes with sample code for Arduino.

$10 Pre-release Discount! 

Price goes back to $55 when the initial production run is exhausted, so order early!

Voltage Options

Sunday, June 25, 2017

Transistor Sizing Calculation

Two common ways of using a transistor is as an analog amplifier, or a digital switch. We are most interested in the digital switch mode of a transistor in our projects.

Many times, an Arduino, or other microcontroller, is not able to drive a load directly. We commonly will use a transistor to drive the load, and trigger it with a microcontroller's output pin.

For MOSFET examples, see our companion article.

Lets use an example. Say we have a 20v dc motor, that requires 500ma of current at load.

The Arduino UNO can output 5v, at 40ma or less. Let's use a 2N2222 transistor. From the spec sheet, we see it can handle 600ma continuously, so current requirements are met. We also see it can handle around 30vdc, so the voltage requirements are met. Looks like a good match.

Being a NPN transistor, the load attaches between the collector and the positive supply, the emitter connects to a common ground with the Arduino.

To prevent the transistor from pulling too much current from the Arduino, we need a resistor between the Arduino output pin, and the base of the transistor. The resistor must be sized to limit current to no more than 40ma, and to make sure the transistor "opens" fully under load. The more current drawn by the load, the more current is needed by the base.

Download spreadsheet with following calculations:

The 2N2222 has a DC gain of about 30, so the current of the load (500 ma) divided by the gain (30) means we need a base current of around 16ma.

If we assume a Arduino HIGH being around 4.5v, and the diode voltage of the transistor is 0.7v, we get a base voltage of 3.8v. The maximum size of the resistor to maintain a 500ma load will be 228 Ohms. We found this by taking the needed base current of 16ma and dividing by the base voltage of 3.8v (and multiplying by 1000). If you go higher, the transistor may not fully open, and the motor won't perform properly. We could go as low at 100 Ohms without exceeding the max current of the Arduino pin (3.8v / 100 Ohms = 38ma), but there's no need to draw the excess current, so keep the resistor value near the max of 228 Ohms to reduce Arduino power consumption, and leave capacity on other pins. The total current supply capability of the UNO is 200ma (per ground) across all the pins.

Saturday, June 24, 2017

ESP8266 BME280 Weather Station

One of our favorite new toys is the ESP8266 WiFi module. A very powerful microcontroller in it's own right, it's easily programmed with the Arduino IDE, and uses the same code we have come to know and love.

Now pushing data to web server!

So lets start:

We received a NodeMCU ESP8266 microcontroller and a BME280 Temperature / Humidity / Barometric Pressure module from IC Station.

Both the ESP8266 and the BME280 are 3.3v devices, so no level shifting required. The BME280 is an I2C device, so I connect SCL to D1 on the ESP8266, and SDA to D2. VCC goes to 3V3 and GND to GND. That's it for wiring.

I need to add the ESP8266 to the Arduino IDE, so head over to for a quick tutorial.

You will need two libraries from Adafruit, both the BME280 and the Sensor libraries -

I used their example sketch, but modified the metric outputs to American, and added calculations for Dew Point and Heat Index.

Once the board is installed, you are ready to upload the modified sketch:

The output of the serial monitor should look like this:

Our next step with this is to push the data to our new IOT web / database server, with live charts, gauges, and database storage. Stay tuned!

Check out all our videos on Youtube!

Friday, June 2, 2017

Logic Level MOSFETs, IRL or IRF?

If you need to switch a dc load, a MOSFET is a very useful component. Typically carrying much more current than a standard transistor, and better performance characteristics, like a high impedance gate that draws very little current. BJT's are current driven devices, MOSFETs are voltage driven devices.

Not all MOSFETs are the same, and too many Arduino sites show the IRF series MOSFET. The IRF series require 10v (VGS = 10.0 V) at the gate to fully open at anywhere near rated loads, so we use the IRL series. Any logic level N-Channel MOSFET (VGS = 5.0 V) will work, and look for the lowest RDS(on) (Ω) resistance you can practically find, to limit heat buildup. Connect your DC load between + and the Drain (D) of the MOSFET. Connect the MOSFET Source (S) to ground, or negative terminal of your voltage source. We add two resistors, a 10k Ohm from the MOSFET Gate (G) to ground to ensure turnoff when Gate signal is removed, and a 125 Ohm resistor between the Arduino output and the MOSFET Gate (G). This protects the Arduino pin from too much current draw. The value is determined by the voltage of the Arduino pin (5v) divided by the max current we want to allow (40ma). The IRL540 shown has a built in snubber diode that prevents motor flyback from damaging the MOSFET or Arduino. The Arduino sends a HIGH signal to turn on the MOSFET, a LOW to turn it off, and can also use PWM (analogWrite on an appropriate pin) to control motor speed, lamp brightness, etc.

Thursday, May 25, 2017

"Clear All" Checkbox Script

Ever need to have a "clear all" check box, and have any of the other check boxes clear the clear all? Well, we needed that, and came up with a solution for your coding pleasure. It's in PHP, but can be done in HTML as well. It uses a bit of javascript in either to make the magic happen.


Wednesday, May 3, 2017

Convert a UPC-A to a GTIN-14

More and more I'm having to use GTIN barcodes instead of the old UPC-A bar codes. I needed a way to automatically grab the UPC-A bar code number from our database, strip the check digit, and generate a new GTIN-14 bar code on the fly, with a newly recalculated check digit. This is done in PHP, so take a whack at it and have fun! I'm still investigating how to produce bearer bars.

The trick to generating a check digit is list the 12 digit UPC-A with two zeros as a prefix, and starting with the first position on the left, mark the numbers as the Odd and Even positions, leaving off the last digit (check digit).

00  6631    2102    3756

Add all the Odd positions together :19
Add all the Even positions together: 17

Multiply the Odd total by 3: 19*3=57

add the Odd and Even totals together: 57+17=74

If a multiple of 10, check digit is 0. In our example case it's not, so if not a multiple of 10, Subtract from the next higher multiple of 10: 80-74 = 6

6 is the check digit. Now add a 01 prefix in front and you have a GTIN-14 compatible bar code.

01 0066312102375 6


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 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 .....