Monday, October 5, 2015

Simple Seven Segment LED Displays

Seven Segment LED's are a common method of displaying data. With 8 datapins, they are also complicated to wire up, as each LED needs a Arduino pin and a resistor. With a library, we can simplify the wiring, and the data display. Typical displays look like the following:

To reduce the number of Arduino connections if we want to use multiple digits, we will connect all the a segments together, all the b segments together, all the c segments, and so on. We will have a data line for each common so we can light up each segment with different data.

So here goes, connect a 330 ohm resistor to Arduino pin 2. then connect the other end of that resistor to segment a on each module. Follow the chart for the other pins.

Arduino pin 2 -> 330 ohm resistor -> all segment a's
Arduino pin 3 -> 330 ohm resistor -> all segment b's
Arduino pin 4 -> 330 ohm resistor -> all segment c's
Arduino pin 5 -> 330 ohm resistor -> all segment d's
Arduino pin 6 -> 330 ohm resistor -> all segment e's
Arduino pin 7 -> 330 ohm resistor -> all segment f's
Arduino pin 8 -> 330 ohm resistor -> all segment g's
Arduino pin 9 -> 330 ohm resistor -> all segment p's (decimal Point)

1st module com to Arduino pin 10
2nd module com to Arduino pin 11

You will need to download and install the library from

Now the code:

#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

void setup() {
  byte numDigits = 2;   // number of modules
  byte digitPins[] = {10,11}; // where your common pins are connected
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; //where your segments pins are connected

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); //Use COMMON_CATHODE if your modules use gnd on the common, or COMMON_ANODE if they take positive on the common.

void loop() {
  int d1 = 12; // number you want displayed, usually from a sensor
  sevseg.setNumber(d1, 1); //display number, with optional decimal point (1 place)

  sevseg.refreshDisplay(); // Must run repeatedly

/// END ///

More info at

Thursday, October 1, 2015

Arduino WiFi Shield 101 - SSL for $50

Arduino WiFi Shield 101 is a powerful IoT shield with crypto-authentication that connects your Arduino or Genuino board to the internet wirelessly. Connecting it to a WiFi network is simple, no further configuration in addition to the SSID and the password are required. The WiFI library allows you to write sketches which connect to the internet using the shield.

The shield is based on the Atmel SmartConnect-WINC1500 module, compliant with the IEEE 802.11 b/g/n standard. The WINC1500 module provided is a network controller capable of both TCP and UDP protocols.  The main feature is an hardware encryption/decryption security protocol provided by the ATECC508A CryptoAuthentication chip that is an ultra secure method to provide key agreement for encryption/decryption, specifically designed for the IoT market.

The WiFi Shield 101 is the first Arduino product fully supporting SSL and all the communication between your board and a secured server. With the power of the Arduino Zero and the WiFi Shield 101 it is possible to make secure IoT applications simply and just using the Arduino Language.

Wednesday, September 30, 2015

Arduino Pocket Simon

Remember the old Pocket Simon game? A fun game of memorization, you press the button that corresponds with the light and sound,and each time you get it right, it adds another to the sequence. Here is our Arduino version. It consists of 4 LED's, 4 buttons, 4 resistors, a Piezo element (speaker), all on a protoshield. We also included a Adafruit LiPo shield for wireless / rechargeable operation.

Tutorial -

Igaging Micrometers and Calipers

I've added the Igaging SpeedMic and OriginCal to our list of Arduino connected measurement equipment. I made some improvements to our Mitutoyo Instructable to facilitate connection to the Igaging equipment. The Igaging SPC enabled gear is Mitutoyo compatible, using the same 52 bit data stream. It even uses a Mitutoyo SPC cable for connection (not the same cable as our Mitiyoyo Coolant protected Micrometer).

Igaging SpeedMic and OriginCal

Cable for Arduino

Discuss (Yahoo)
Discuss (Facebook)



int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)

int dat = 2; //mic Data line goes to pin 2

int clk = 3; //mic Clock line goes to pin 3

int i = 0; int j = 0; int k = 0;

byte mydata[14];

float num;

void setup() {


pinMode(req, OUTPUT);

pinMode(clk, INPUT_PULLUP);

pinMode(dat, INPUT_PULLUP);

digitalWrite(req,LOW); // set request at LOW


void loop() { // get data from mic

digitalWrite(req, HIGH); // generate set request

for(i = 0; i < 13; i++ ) {

k = 0;

for (j = 0; j < 4; j++) {

while( digitalRead(clk) == LOW) {// hold until clock is high


while( digitalRead(clk) == HIGH) {// hold until clock is low


bitWrite(k, j, (digitalRead(dat) & 0x1)); // read data bits, and reverse order )


// extract data

mydata[i] = k;

// sign = mydata[4];

// decimal = mydata[11];

// units = mydata[12];


// assemble measurement from bytes

char buf[7];

for(int lp=0;lp<6;lp++)



num=atol(buf); //assembled measurement, no decimal place added

Serial.println(num/1000, 3); //add decimal


Wednesday, September 16, 2015

Student Arrested for Building a Homemade Clock

Update - Ahmed Clock Hoax!

"When 14-year-old Ahmed Mohamed arrived at school on Monday morning with a digital clock he’d built from scratch, he was keen to show his teachers the fruit of his labors. Instead, he was pulled out of class and arrested for attempting to build a bomb."

Or so we were told. The truth is something else entirely.

Ahmed's father is a Muslim activist and put his son up to this. Ahmed took a off the shelf AC clock, removed the case, and stuck it in this pencil case. This was done deliberately to get the school authorities to jump, so he could get fame and fortune, and desensitize America of "see something suspicious, report it" ...

For real clock projects, See: (DS1307) (NTP) (GPS)

Saturday, September 12, 2015

Infra Red Contactless Temperature Sensor

We have a Contactless Thermometer at work. Just aim the little red dot at what ever you want to read, and the temperature displays on the LCD screen. I must be related to Rube Goldberg somewhere in my family tree, because my philosophy is why buy when you can build, even though I have to buy some parts. It's more satisfying when you construct something yourself, and know how it works.

This could be used in a security system, to detect a IR heat source, like fire, or people / animal presence.

I ordered a $10 TMP006 IR Sensor from Adafruit. Found out later they have a TMP007 which is supposed to be a little better. Anyway, the TMP006 uses 4 wires to connect, +5v, Gnd, SCL (pin A5), and SDA (pin A4).

The tutorial on the Adafruit site misses a step, and adds a GITHUB error. To begin, you will need to download two libraries from GITHUB. and

As usual, GITHUB adds a -master to the download, so you can't use the Arduino IDE import library menu option. You need to download both zip files, extract them,and then rename the folders by removing the -master. Then you need to copy both folders into your libraries folder. Now you can run the example sketch found on your Examples - Adafruit_TMP006 menu.

As the default is Celsius, and I prefer Fahrenheit, I have added a Celsius to Fahrenheit conversion line in two places.

Now I just have to add red LED "laser" pointer for aiming.

  This is an example for the TMP006 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit TMP006 Breakout 

  These displays use I2C to communicate, 2 pins are required to  
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TMP006.h"

// Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
// Gnd -> Gnd
// SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
// otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
// SDA connects to the I2C data pin. On newer boards this is labeled with SDA
// otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2

Adafruit_TMP006 tmp006;
//Adafruit_TMP006 tmp006(0x41);  // start with a diferent i2c address!

void setup() { 
  Serial.println("Adafruit TMP006 example");

  // you can also use tmp006.begin(TMP006_CFG_1SAMPLE) or 2SAMPLE/4SAMPLE/8SAMPLE to have
  // lower precision, higher rate sampling. default is TMP006_CFG_16SAMPLE which takes
  // 4 seconds per reading (16 samples)
  if (! tmp006.begin()) {
    Serial.println("No sensor found");
    while (1);

  Serial.println("Send s to enter sleep mode, or w to wake up.  Measurements are not updated while asleep!");

void loop() {
  // Check for sleep/wake command.
  while (Serial.available() > 0) {
    char c =;
    if (c == 'w') {
      Serial.println("Waking up!");
    else if (c == 's') {
      Serial.println("Going to sleep!");

  // Grab temperature measurements and print them.
  float objt = tmp006.readObjTempC();
  objt = (objt * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  Serial.print("Object Temperature: "); Serial.print(objt); Serial.println("*F");
  float diet = tmp006.readDieTempC();
  diet = (diet * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*F");
  delay(4000); // 4 seconds per reading for 16 samples per reading

Saturday, September 5, 2015

Shift Registers - Unlimited Inputs With Only 3 Data Lines?

Last week we demonstrated how to use an output shift register (74HC595) to control 8 LED's with only 3 data lines. Since shift registers can be daisy chained, the number of LED's can be virtually unlimited. This week we wanted to show how to use an input shift register, the CD4021. 8 push button switches can be polled and used to input data or control devices, with only 3 data lines, And as with the output shift register, multiple chips can be daisy chained with no additional i/o lines needed. See the video below!


Pin 3 of the CD4021 goes to Arduino Pin 9
Pin 9 of the CD4021 goes to Arduino Pin 8
Pin 10 of the CD4021 goes to Arduino Pin 7

Pins 1, 4-6, & 13-5 of the CD4021 go to push button switches and Gnd. The other side of each switch goes to +5v.

Data sheet:

//  Name    : shiftIn Example 1.1                              //
//  Author  : Carlyn Maw                                        //
//  Date    : 25 Jan, 2007                                      //
//  Version : 1.0                                               //
//  Notes   : Code for using a CD4021B Shift Register     //
//          :                                                   //

//define where your pins are
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

//Define variables to hold the data 
//for shift register.
//starting with a non-zero numbers can help
byte switchVar1 = 72;  //01001000

void setup() {
  //start serial

  //define pin modes
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);


void loop() {

  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  //set it to 1 to collect parallel data, wait
  //set it to 0 to transmit data serially  

  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first 
  switchVar1 = shiftIn(dataPin, clockPin);

  //Print out the results.
  //leading 0's at the top of the byte 
  //(7, 6, 5, etc) will be dropped before 
  //the first pin that has a high input
  Serial.println(switchVar1, BIN);

//white space
//delay so all these print satements can keep up. 


//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
  for (i=7; i>=0; i--)
    digitalWrite(myClockPin, 0);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      //set the bit to 0 no matter what
      myDataIn = myDataIn | (1 << i);
    else {
      //turn it off -- only necessary for debuging
     //print statement since myDataIn starts as 0
      pinState = 0;

    //Debuging print statements
    //Serial.print("     ");
    //Serial.println (dataIn, BIN);

    digitalWrite(myClockPin, 1);

  //debuging print statements whitespace
  //Serial.println(myDataIn, BIN);
  return myDataIn;

More Info:

Video (still processing, try back in an hour):

Thursday, August 27, 2015

Arduino Controlled Spectrum Analyzer for Ham Radio

As a Ham, of course I want to be able to examine frequencies, and the strength of the signal on that frequency. So imagine my excitement when I found the following Arduino solution!

The Specan is actually a very simple but robustly built receiver. it is, in essence, a double conversion superhet receiver with 112 Mhz and 12 Mhz Intermediate frequencies. The first mixer uses an Si570 as the local oscillator. The second oscillator is a crystal controlled at 100 MHz; built with a common microprocessor crystal of 20 MHz. Unlike most radio receivers, the second IF has two filters : a narrow band crystal filter with 1 Khz bandwidth and a wide band LC filter with 300 Khz bandwidth. The detector converts the tuned signals into a log scale. The detector output is a decibel measure of the incoming signal.
The Specan is controlled with an Arduino board. The Arduino controls the Si570, handles the front panel, talks to the computer over the USB port, reads the detector and switches the filters. In a very simple usage, the Specan can be tuned around like a regular radio. Instead of listening to the signals, you read their strength on the LCD display.
You can switch between wide and narrow filters : using the wide filters to hunt for signals and then use the narrow filter to locate and measure them with greater precision. This in itself is quite a useful function. It is possible to measure intercepts, gains and harmonics without using a computer.
Under a PC's control, the Specan can be made to step through any sequence of frequencies and plot them on the computer screen. The Specan understands a handful of text commands sent over the USB port of the Arduino.
The Specan also accomplishes a long standing personal goal - to make the homelab at VU2ESE entirely homebrew. The Specan can easily replace our aging TEK 465 scope and do even more.
This Specan can be built for far less than hundred dollars. Though it needs quite a few evenings of work. Construction is straightforward.You won't need any special tools. Modules of the Specan are used to align the rest of it! The Specan serves as its own set of test and alignment gear!

Monday, August 24, 2015

What good are Shift Registers?

Everyone eventually runs into the problem of running out of I/O pins on the Arduino, and the Raspberry Pi. A shift register is a chip that can give you 8 or more additional I/O ports, while only using 3 ports on the microcontroller. There are input and output shift registers, and today I'm showing an example of an output shift register,the 74HC595.

I've taken an Adafruit protoboard, and soldered in a 74HC595, 8 LED's, and 8 220 ohm resistors.

The tutorial I followed is found at and documents the construction,and gives three example sketches.

Have fun!

Sunday, August 23, 2015

Using a 3x4 Keypad

Ever want to use a 3x4 Keypad? These keypads from Adafruit can be used for numeric data entry or for access control for a security system. Our example allows you to input a multiple digit entry with a "enter key" (#) and a "cancel key" (*). In our example, we will assemble a file name for submission to a sd card, but you can drop that off if you don't need that.

I plugged the keypad cable into a male extended length header, and plugged in directly into pins 2-8 on the arduino.

Download the library file at and install into your library folder.

The following sketch will allow a key sequence of  at least 6 digits. You can enlarge the string if you need more digits. It displays each digit as entered in the serial monitor,and allows you to press * to cancel and start over if you make a mistake.

Thanks to Mike McRoberts and Mark Stanley for their help!

Also see our RFId and Fingerprint scanner tutorials!

#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the kpd

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char entryStr[8]; 
int i=0;

void setup(){
void loop(){
  char key = keypad.getKey();
 if (key){ 
   if (key == '*'){
   memset(entryStr, 0, sizeof(entryStr));  
   } else if (key != '#'){
     entryStr[i]= key;
   else {
   String fileName = entryStr;
   memset(entryStr, 0, sizeof(entryStr));
   fileName = fileName + ".mp3";


Tuesday, August 18, 2015

Arduino / MySQL Connector Improvements

There have been some exciting improvements in the Arduino direct to MySQL communications. As a recap, this library allows a Arduino Ethernet or WiFi shield enabled Arduino to directly make SQL INSERT, DELETE, UPDATE, and SELECT queries, no intermediary code or web server. The big news is the documentation has been greatly improved. Get the Updated Library and Documentation at

Original Experiment


Beginning Sensor Networks with Arduino and Raspberry Pi

Wednesday, August 12, 2015

My Favorite eReader - Kindle Paperwhite

Why am I talking about eReaders on a microcontroller site? Well, 5 years ago I had a house fire, and lost my 3000+ title library. I lived in an RV for a couple of years after, and did not have room for a lot of books. That's when I got my first Kindle. I've been through several generations of Kindles now, and my newest is the 300 PPI Paperwhite ($119)

This one is very different. The first thing you notice is the backlit screen, no more need for cases with built in lights, or external lighting. The next thing I noticed was the improved readability. A new font (bookery) that is much easier on the eyes. The 6" screen means it's easy to hold in one hand, and change pages by swiping my finger forward or back.

So, how does this tie in with Microcontrollers?

The complete collection is searchable, so all my Arduino, Raspberry Pi, Python, PHP, MySQL, etc. content is available at a few finger presses. Makes it easy to find what I need to make any new project.

There are other improvements, but these are the ones that stand out for me.

I did get a nice case for it. The Coredy Kickstand Case Cover ($14) protects my Kindle well, has a built in stand and stylus, and automatically turns on my Kindle when I open it. Highly recommended.

Solar charge your kindle / tablet / cell phone -

Monday, August 10, 2015

Measuring Wind Speed with an Arduino / Anemometer

A while back, we got a set of weather sensors from Sparkfun. It includes a Anemometer (speed), Wind Vane (direction), and a Rain Gauge.

I used a hand held wind speed device to calibrate my Arduino code.

I'm using pinMode(2, INPUT_PULLUP); so no pull up or pull down resistor is needed.

I used a prototype dual 6 pin phone jack from IC Breakout to connect the weather sensors to the Arduino.

For this sketch, I connected the two wires from the anemometer to pins 2 (interrupt 0) and ground.


 // diameter of anemometer
 float diameter = 2.75; //inches from center pin to middle of cup
 float mph;
 // read RPM
 int half_revolutions = 0;
 int rpm = 0;
 unsigned long lastmillis = 0;
 void setup(){
 pinMode(2, INPUT_PULLUP); 
 attachInterrupt(0, rpm_fan, FALLING);
 void loop(){
 if (millis() - lastmillis == 1000){ //Update every one second, this will be equal to reading frequency (Hz).
 detachInterrupt(0);//Disable interrupt when calculating
 rpm = half_revolutions * 30; // Convert frequency to RPM, note: 60 works for one interruption per full rotation. For two interrupts per full rotation use half_revolutions * 30.
 Serial.print("RPM =\t"); //print the word "RPM" and tab.
 Serial.print(rpm); // print the rpm value.
 Serial.print("\t Hz=\t"); //print the word "Hz".
 Serial.print(half_revolutions/2); //print revolutions per second or Hz. And print new line or enter. divide by 2 if 2 interrupts per revolution
 half_revolutions = 0; // Restart the RPM counter
 lastmillis = millis(); // Update lastmillis
 attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
 mph = diameter / 12 * 3.14 * rpm * 60 / 5280;
 mph = mph * 3.5; // calibration factor for anemometer accuracy, adjust as necessary
 Serial.print("\t MPH=\t"); //print the word "MPH".
 // this code will be executed every time the interrupt 0 (pin2) gets low.
 void rpm_fan(){

Friday, July 31, 2015

USB Rechargeable Mega Bright 3w Flashlight

Want a DIY painfully bright rechargeable flashlight? Look no more, as here is one bad darkness kicker! I took a Nokia cellphone battery,combined it with a USB LiPo charger, a switch, and a few resistors, with a massive 700ma, 3.3v White LED.

USB LiPo Charger
BL-5C Nokia Battery
(4) 1.5 Ohm 1/2w Resistors
Optional 10w Resistor (would handle up to 5 LED's)
Proto Board

The ever handy LED Calculator suggested a 2w Resistor, so I put (4) 1/2w resistors in parallel. If you need more light, you can add another LED, with another 2w of resistors. Just parallel the first set. You could even have a high / low switch, that only brings the second set on in the high position.

Thursday, July 30, 2015

433 MHz Wireless Arduino

Today I took a $3 433 MHz transmitter / receiver pair, and sent a string of characters 20' from one Arduino to another. This could be useful for weather sensors, security alarms or remote control, etc.

There are only 3 wires to connect on each unit, 5v, Gnd, and Data (spelled ATAD on the smaller board, which is the transmitter).  Add a 13cm wire to transmitter ANT connection for greater range.

You will need two Arduino boards, 6 jumpers, and 2 solderless breadboards for this project.

A 4 AA battery pack or a 9v for the transmitter Arduino will make it wireless, the receiver will be plugged into your computer. Alternatively, the Transmitter could be plugged into another computer or a USB charger for power. We are using our LiPo battery shield.

Download and install the Virtual Wire ( library (we have slightly customized the sketches found at this site, so try ours found below first, they are much more satisfactory).

Connect the smaller transmitter board to one Arduino, using +5v, Gnd, and "ATAD" to Arduino pin 11.
Connect the larger receiver board to the second Arduino, using +5v (VCC), GND, and either of the 2 DATA pins to Arduino pin 11.

When the code below is uploaded to the appropriate Arduino, you should see the following in the RX Arduino serial monitor:

Try your own modifications to send numeric data like int's and floats.

Upload the following sketch to the TX Arduino:

#include <VirtualWire.h>

const int led_pin = 13;
const int transmit_pin = 11;
const int receive_pin = 2;
const int transmit_en_pin = 3;

void setup()
  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);  // Bits per sec

byte count = 1;

void loop()
  char msg[7] = {'h','e','l','l','o',' ','#'};

  msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msg, 7);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  count = count + 1;

Upload the following sketch to the RX Arduino

#include <VirtualWire.h>

const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;

void setup()
    Serial.begin(9600); // Debugging only

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);  // Bits per sec

    vw_rx_start();       // Start the receiver PLL running

void loop()
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
 int i;

        digitalWrite(led_pin, HIGH); // Flash a light to show received good message
 // Message with a good checksum received, print it.
 Serial.print("Got: ");
 for (i = 0; i < buflen -2; i++)
     //Serial.print(buf[i], HEX);
     //Serial.print(' ');
        digitalWrite(led_pin, LOW);