Friday, May 22, 2015

Perfuino, the Arduino for Prototypers

Yes, it's another barebones Arduino, but the additional prototyping space makes it a unique and very handy board to have. The Atmega328 is socketed, so if you do something crazy, you are back in business for under $5. At a cost of $16, it's a affordable alternative to the commercial clones. It does not include a USB interface, so a FTDI cable for ICSP programmer will be necessary (headers at upper left). Only 3 days left on the kickstarter, so get in fast!

Tuesday, May 19, 2015

Ham Radio Shield for Arduino

Would you like a complete 2m / 1.25m / 70cm ham radio that connects like a shield to an Arduino? Can be used with a Raspberry Pi as well. Onboard Lipo charger / controller also powers your Arduino. Make your own TNC / Packet Radio, Repeater, Echo Link node, and more! 200mw, with an optional 10w amplifier. Coming soon! -

The HobbyPCB RS-UV3 radio module is a 144/220/450 MHz FM transceiver board. The RS-UV3 is a low cost transceiver solution for Packet Radio, repeaters, Echolink stations, base station and mobile applications. The RS-UV3 supports multiple interfaces including microphone/speaker, line level audio (soundcard), TTL serial control and Arduino Shield connections. The RS-UV3 has an built-in battery charger and provides conditioned power for the Arduino controller.

Monday, May 18, 2015

Measuring Voltage with an Arduino and an External AREF

The Arduino Uno has 6 analog inputs, designed for measuring a voltage. Other versions of the Arduino can have several more. Voltages are analog, meaning they can have a range of values, versus digital, which only has two, on or off. Whether you are reading a potentiometer, a TMP36 or LM35 temperature sensor, or even the voltage of a battery, these devices output an analog signal. Many devices are strictly in the analog world.

The Arduino is very good at measuring these voltages, as long as they are in the 0-5v range (UNO) or 0-3.3v range on some other models. The issue we run into is that although the 5v is assumed, sometimes it's not 5v. If you have your Arduino plugged into your computer USB, or have a lot of devices connected to your Arduino, that 5v can be as low as 4.8 volts.

Why does this matter? The Arduino analog to digital converter has 1024 steps so 5v / 1024 = 0.0048828125 per step. But if the voltage was 4.8 volts, then each step would equal 0.0046875. Doesn't seem like a big difference does it? With a sensor like the TMP36, that difference could equal several degrees of inaccuracy.

So how do we correct this? Well, powering your Arduino from a 9v source through the barrel connector is a big help, as the onboard voltage regulator will do a good job of enforcing that the INTERNAL reference is really 5v. For real precision, a EXTERNAL reference is best.

We are using a LM4040 precision voltage source from Adafruit, which takes a nominal 5v input, and delivers a precision voltage reference of 2.048 and 4.096 volts, regardless of your supply voltage to the Arduino. By connecting one of these outputs to your AREF pin, and specifying the AREF voltage (verify with your meter), you now can precisely measure a analog signal from 0 - AREF voltage.

If your signal is greater than the AREF voltage, you can use resistors to create a voltage divider to bring it back into range.


Here is a sample sketch showing how to use a EXTERNAL reference, like the Adafruit LM4040.

When using AREF, always specify analogReference(EXTERNAL); before doing an analog read, as you could short the internal reference, damaging the Arduino. I recommend you upload this sketch before connecting the AREF pin.

#define aref_voltage 4.096 

int ADCPin = 1; //using A1 input for this sketch
int ADCReading;

void setup(){




void loop(){

  ADCReading = analogRead(ADCPin);  
  Serial.print("ADC reading = ");
  Serial.print(ADCReading);     // the raw analog reading
  // converting that reading to voltage, which is based off the reference voltage
  float voltage = ADCReading * aref_voltage;
  voltage /= 1024.0; 
  // print out the voltage
  Serial.print(" - ");
  Serial.print(voltage); Serial.println(" volts");



Monday, May 11, 2015

Reading a Current Shunt with an Arduino

Current shunts are very popular with the Ham Radio, boating, electric vehicle and solar / wind off grid folks, as they allow them to monitor solar and wind power production, power consumption of devices, and the estimated amp hours left in the battery bank, sort of like a "gas gauge" for your batteries.

See our complete Off Grid Power Monitoring System at

Previous ADS1115 Arduino / Raspberry Pi post!

Unlike the solid state hall effect types, current shunts drop a small voltage across a calibrated resistor, indicating the amps being passed through the shunt. This allows shunts to report massive amounts of current, in excess of a 1000 amps, depending on the design of the shunt.

Common shunts are rated at 50mv, 75mv, and 100mv output at maximum current (do not exceed 66% of name plate current). The Arduino has a few issues with these shunts. Since the maximum output is just 100 millivolts compared to the Arduino's range of 0-5v, it's like trying to read a 5 inch ruler from 10 miles away (worse with the 50mv and 75mv versions). The second issue is the Arduino has a 10 bit analog to digital converter (ADC), so a 100amp / 100mv shunt would have a 4.88 mv per step resolution, or about 5 amps per step (a total of 1024 steps).

We can solve this with a higher bit ADC with an onboard amplifier. We chose a 16 bit ADC that has over 64000 steps (+/- 32768), and up to 16x amplification. This matches a 100mv shunt very well.

The ADC we chose is the adafruit ADS1115. It has 4 single ended channels, or two differential channels. We chose to use differential mode, to eliminate electrical interference (the third issue) in the monitoring circuit, giving us very stable results. This means we can use two shunts per ADS1115. The ADS1115 can have 4 different user selectable I2C addresses, so with only 2 data lines (SCL & SDA), you can monitor up to 8 shunts.


Connections are very simple. Adafruit gives a very comprehensive tutorial on connecting and using this sensor for a variety of different purposes, and you can read about it (and download the library) at For our purposes, this is what we needed:

VDD - Arduino +5v
GND to Arduino GND
SCL to Arduino A5
SDA to Arduino A4
ADDR to Arduino GND (one of 4 possible address combinations, see adafruit tutorial for the the others)
A0 to Current Shunt
A1 to Current Shunt


Although we are using a 100a / 100mv shunt, if you are using a 75mv or 50mv shunt, we added two additional lines in the code you can uncomment depending on which shunt you are using.

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */

void setup(void)
  ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV

void loop(void)
  int16_t results;
  results = ads.readADC_Differential_0_1();  
  Serial.print("Amps: "); 
  float amps = ((float)results * 256.0) / 32768.0;
  //amps = amps * 1.333; //uncomment for 75mv shunt
  //amps = amps * 2; //uncomment for 50mv shunt


Saturday, May 9, 2015

The New Bosch BME280 (Temp, Humidity, BMP)

Bosch has a new, very accurate all in one sensor chip that does Temperature, Humidity, and Barometric Pressure readings. It's called the BME280. Embedded Adventures has put that chip on a handy breakout board with signal conditioning (MOD-1022) and priced it fairly at $17. It's a 3v I2C unit, so to use it with a Arduino UNO, you will need a bi-directional level shifter, which they also have as the MOD-1003S for an additional $10.

This is the most accurate unit I have found, and is very easy to use. The library and sample code are available on the MOD-1022 page above, and the MOD-1003S level shifter requires no code to use.

There are only 4 wires to connect from the MOD-1022 to the MOD-1003S (VDD -> +3.3v, SCL -> B2), SDA -> B1, Gnd), and 4 wires from the MOD-1003S to the Arduino (+5v, SCL(B2 ->A5), SDA(B1->A4), Gnd). Download and install the library, and upload the example sketch included with the library, and you are on your way (in metric). For US measurements, you will have to convert Celsius to Fahrenheit, and hPa to InHg.

The example sketch communicates with serial defaulting to 115200, so make sure your serial monitor is set accordingly.

See schematic after the code.



Copyright (c) 2015, Embedded Adventures
All rights reserved.

Contact us at source [at]

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

- Neither the name of Embedded Adventures nor the names of its contributors
  may be used to endorse or promote products derived from this software
  without specific prior written permission.


// BME280 MOD-1022 weather multi-sensor Arduino demo
// Written originally by Embedded Adventures

#include <BME280_MOD-1022.h>

#include <Wire.h>

// Arduino needs this to pring pretty numbers

void printFormattedFloat(float x, uint8_t precision) {
char buffer[10];

  dtostrf(x, 7, precision, buffer);


// print out the measurements

void printCompensatedMeasurements(void) {

float temp, humidity,  pressure, pressureMoreAccurate;
double tempMostAccurate, humidityMostAccurate, pressureMostAccurate;
char buffer[80];

  temp      = BME280.getTemperature();
  humidity  = BME280.getHumidity();
  pressure  = BME280.getPressure();
  pressureMoreAccurate = BME280.getPressureMoreAccurate();  // t_fine already calculated from getTemperaure() above
  tempMostAccurate     = BME280.getTemperatureMostAccurate();
  humidityMostAccurate = BME280.getHumidityMostAccurate();
  pressureMostAccurate = BME280.getPressureMostAccurate();
  Serial.println("                Good  Better    Best");
  Serial.print("Temperature  ");
  printFormattedFloat(temp, 2);
  Serial.print("         ");
  printFormattedFloat(tempMostAccurate, 2);
  Serial.print("Humidity     ");
  printFormattedFloat(humidity, 2);
  Serial.print("         ");
  printFormattedFloat(humidityMostAccurate, 2);

  Serial.print("Pressure     ");
  printFormattedFloat(pressure, 2);
  Serial.print(" ");
  printFormattedFloat(pressureMoreAccurate, 2);
  Serial.print(" ");
  printFormattedFloat(pressureMostAccurate, 2);

// setup wire and serial

void setup()

// main loop

void loop()

  uint8_t chipID;
  Serial.println("Welcome to the BME280 MOD-1022 weather multi-sensor test sketch!");
  Serial.println("Embedded Adventures (");
  chipID = BME280.readChipId();
  // find the chip ID out just for fun
  Serial.print("ChipID = 0x");
  Serial.print(chipID, HEX);
  // need to read the NVM compensation parameters
  // Need to turn on 1x oversampling, default is os_skipped, which means it doesn't measure anything
  BME280.writeOversamplingPressure(os1x);  // 1x over sampling (ie, just one sample)
  // example of a forced sample.  After taking the measurement the chip goes back to sleep
  while (BME280.isMeasuring()) {
  // read out the data - must do this before calling the getxxxxx routines
  Serial.println(BME280.getTemperature());  // must get temp first
  Serial.println(BME280.getPressureMoreAccurate());  // use int64 calculcations
  Serial.println(BME280.getTemperatureMostAccurate());  // use double calculations
  Serial.println(BME280.getHumidityMostAccurate()); // use double calculations
  Serial.println(BME280.getPressureMostAccurate()); // use double calculations
  // Example for "indoor navigation"
  // We'll switch into normal mode for regular automatic samples
  BME280.writeStandbyTime(tsb_0p5ms);        // tsb = 0.5ms
  BME280.writeFilterCoefficient(fc_16);      // IIR Filter coefficient 16
  BME280.writeOversamplingPressure(os16x);    // pressure x16
  BME280.writeOversamplingTemperature(os2x);  // temperature x2
  BME280.writeOversamplingHumidity(os1x);     // humidity x1
  while (1) {
    while (BME280.isMeasuring()) {

    // read out the data - must do this before calling the getxxxxx routines
    delay(5000); // do this every 5 seconds

Monday, May 4, 2015

Remote Control Mood Lamp

I love RGB LED's. One little module can produce a wide spectrum of colors just by varying the signal on the red, green and blue pins. I also love my TV remote, as I am a bit of a couch potato. What if I could change the mood of the room, with my TV remote?

I took an arduino, connected a RGB LED module that has the three dropping resistors on board, and connected a InfraRed (IR) receiver out of an old VCR. Radio shack sells these for about 80 cents. You could use three separate LED's and 220 Ohm resistors, but the effect would not be the same. You could also get a RGB LED, and add the three resistors to it.

I went a step further, and connected a LED to the output of the receiver chip so I would get a visual confirmation that the receiver saw a signal from the remote. That part isn't necessary, so I left it off the schematic. If you want to implement, connect a 220 ohm resistor to the IR module signal pin. Connect the other end of the resistor to the short leg of an LED (color is your choice). Connect the long end of the LED to Arduino +5. The receiver outputs a LOW when it sees a IR signal.

I cut a small hole in a ping pong ball and placed it over the RGB LED (tape holds the module in place) to diffuse the light and make the whole ball glow with color.

I'm not detecting actual codes, just an IR signal, so this project will work with any remote you have laying around, and any button on the remote. It just cycles to the next color.

All 3 LED pins are connected to PWM pins, so you can add additional case statements, and change the pwm values with analogWrite to the pins, to create new and additional colors.


int ledcolor = 0;
int red = 9; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 11; //this sets the blue led pin

void setup() {
  // put your setup code here, to run once:
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);

void loop() {
  if (ledcolor > 6){
  // put your main code here, to run repeatedly:
bool triggered = digitalRead(12);
if (triggered == LOW){

switch (ledcolor) {
case 0: //if ledcolor equals 0 then the led will turn red
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
analogWrite(red, 204);

case 1: //if ledcolor equals 1 then the led will turn green
digitalWrite(red, LOW);
digitalWrite(green, HIGH);

case 2: //if ledcolor equals 2 then the led will turn blue
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);

case 3: //if ledcolor equals 3 then the led will turn yellow
digitalWrite(blue, LOW);
analogWrite(red, 160);
digitalWrite(green, HIGH);

case 4: //if ledcolor equals 4 then the led will turn cyan
digitalWrite(red, LOW);
digitalWrite(green, LOW);
analogWrite(red, 168);
digitalWrite(blue, HIGH);

case 5: //if ledcolor equals 5 then the led will turn magenta
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);

case 6: //if ledcolor equals 6 then the led will turn white
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
analogWrite(red, 100);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);


Saturday, April 25, 2015

Arduino UPS / Battery Shield

We just picked up a LIPO shield from Adafruit, which allows us to battery power our projects.

The shield contains a optional 2Ah LIPO battery, and recharges from a mini usb cable (same as a Kindle).

You can power your project from the shield on battery power, or plug in the cable, and it charges the battery and acts like a online UPS, powering your project. LED's show power on, charging, charged, and low battery status, and you can monitor battery voltage on one of your analog pins.

All we had to install was the extended headers, and the optional power switch (finally, you can power off the arduino). Stack the shield, plug in the battery and a usb cable for charging when necessary, and you are set to go.

Take it solar with

We used a Ada Fruit RGB I2C LCD Shield
Make sure you download the Adafruit Libraries for the LCD.

// set up the voltage monitor
// select the input pin for the battery voltage. 
//Make sure you solder the correct pad on the bottom 
//of the power boost shield.
int sensorPin = A2;    
// variable to store the value coming from the battery
int sensorValue = 0;  

//measure your AREF pin and replace our 
//measured value of 4.77v
float stepVolt = 4.77/1024.0; 

// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

void setup() {
  // Debugging output
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  lcd.print("Battery Voltage");

void loop() {
 sensorValue = analogRead(sensorPin); 

Wednesday, April 22, 2015

Earth Day - Have your lights turn off when you leave the room!

We wanted to save energy, and create convenience, by adding motion sensors to our lighting circuits. Maybe you want some notification of an intruder. Both can be done with a PIR Motion sensor.  When I walk into a room, the lights come on automatically, and when I leave, shut off after a short period of time. You can choose how long that time delay is in the code. No more fumbling for a light switch in the dark with my arms full of groceries!

Monday, April 20, 2015

Solar & Wind Data Logger Video

This data logger monitors a solar or wind off -grid power system. A current shunt and voltage divider monitors the voltage and current of the system. This data is displayed on the LCD and written to the SD card along with time / date stamping from the real time clock module. A Screw prototyping shield enables easy access to pins for connecting additional sensors like temperature, humidity, barometric pressure, wind speed and direction and rain gauges. Additional information including the web based charting and graphing module is available at

Saturday, April 11, 2015

Arduino LM35 Temperature Sensor

One of the least expensive and simplest ways to measure temperature is with a LM35. This is another component found in our SainSmart kit. This transistor looking device has 3 pins, 5v, Signal out, and Gnd. The signal is an analog voltage that connects directly to a Arduino analog input. In this example we will use A0.

Now the LM35 outputs 0-1v for it's range of -55C to 150C. Since the Arduino defaults to a 5v reference for analog to digital conversion, we are losing 80% of the sensors range, so we are switching to the internal reference which is 1.1v. This is a better match for this sensor. We are also doing a Celsius to Fahrenheit conversion in the code.

With the pins down, and the flat face of the sensor facing you, the pins, from left to right are:

V- S - G

Where V connects to +5, S connects to A0, and G connects to ground. The data sheet can be found at

The code looks like this:

float tempC;
float tempF;
int reading;
int tempPin = 0;

void setup() {
  // put your setup code here, to run once:
  analogReference(INTERNAL); //changing from a 5v reference to a 1.1v reference

void loop() {
  // put your main code here, to run repeatedly:
  reading = analogRead(tempPin);
  tempC = reading / 9.31;
  tempF=tempC * 9/5 + 32;

Arduino Relay Control

Previously I have blogged about using relays with an Arduino, and SainSmart relays specifically. A while back I received a 4 relay, and a 8 relay board, and both of them used negative logic, i.e. a LOW activated them, and a HIGH deactivated them. Yesterday I received a single relay module as part of a kit, and found that this module uses positive logic, i.e. a High activates it, and a LOW deactivates it.

Being a 5v relay, it's able to be driven directly from the arduino power. If you have a lot of additional hardware, you may want to consider a separate 5v supply, and common ground.

We are printing the relay state to the serial monitor, but the LED on the relay board also signifies whether it's active or not.

Only 3 pins are used, 5v ("V"), Gnd ("G"), and a data pin. We are using pin 7 in this example, and connects to the relay "S" (signal) pin.

Here is my test code:

void setup() {
  // put your setup code here, to run once:
pinMode(7, OUTPUT); //don't forget to declare the pin as output!

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(7, HIGH);
digitalWrite(7, LOW);


Tuesday, April 7, 2015

Adafruit RGB I2C LCD Keypad Shield

This project is a bit more complicated than some we have done recently. Adafruit makes a very nice LCD Keypad Shield, that unlike most of the others, has a 2 wire I2C interface (covers the lcd and the keypad), and a multi-color RGB backlight. This frees up 7 I/O pins over the typical LCD Keypad Shield. It comes in a kit, and all the components need to be soldered on the board. Fortunately Adafruit provides a very comprehensive tutorial that is easy to understand.

Monday, April 6, 2015

Adafruit RTC / SD Data Logger

Many of our projects require logging the sensor data to a sd card, and some of those projects require a time / date stamp. We used to use discrete modules to do this, but Adafruit has a very nice Proto shield with a real time clock and a sd module on board. As you can see, this takes a regular size sd card, or a micro sd in a conversion carrier. At under $20, this is a cost effective replacement for discrete RTC and SD modules, and a proto shield. It does not come with extended headers, so it either has to be the top shield in a stack, or get a pack of extended headers and solder those on instead of the normal headers included (but not installed). We have several projects coming up using this shield, so stay tuned.

Will the Real Arduino, Please Stand Up?

For years we have been receiving these wonderful blue Arduino boards with printed on the back.

Imagine my surprise, when this time, it's a green (teal) board and says ARDUINO.ORG on the back. Not only that, but it comes up with warning's it's an UNCERTIFIED board when you use it.

Yes, it's a knock-down drag-out fight between two founders of Arduino, one in charge of manufacturing, the other in charge of software development, and both trying to keep the community in their pocket by claiming they are the real Arduino. Who wins? I don't know, but the real losers could be the hundreds of thousands of enthusiasts using these products. Stop fighting, kids, or I'm calling the Super Nanny!

Proto Screw Shields - Continued

Last week I built a Proto Screw Shield from Sparkfun. Although it's a very nice piece, and easily assembled, I received one from Adafruit today that I believe to be a bit better. First of all, It's REV 3 compliant, which the Sparkfun piece was not. Second, it also came with the pass through extended headers for the traditional ICSP block. Construction time and ease was essentially identical. Sparkfun still has the better shipping rates, so if you order from Adafruit, you better have a large order. I get charged $15 S&H for a $3 transistor or $100 worth of boards.