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 https://www.arduino.cc/en/Tutorial/ShiftOut 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 http://playground.arduino.cc/Code/Keypad 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] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
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(){
  Serial.begin(9600);
}
  
void loop(){
  char key = keypad.getKey();
 
 if (key){ 
   if (key == '*'){
   memset(entryStr, 0, sizeof(entryStr));  
   i=0;
   key=0;
   Serial.println(""); 
   Serial.println("Canceled"); 
   
   } else if (key != '#'){
     entryStr[i]= key;
     i++;
     Serial.print(key);
     }
   else {
   Serial.println(""); 
   i=0;
   key=0;
   
   String fileName = entryStr;
   memset(entryStr, 0, sizeof(entryStr));
   fileName = fileName + ".mp3";
   Serial.println(fileName);
   }  


 }
}

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 https://launchpad.net/mysql-arduino

Original Experiment

Example

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 - http://amzn.to/1EmP95b




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.





Code:

 // 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(){
 Serial.begin(9600); 
 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".
 Serial.println(mph);
  }
 }
 // this code will be executed every time the interrupt 0 (pin2) gets low.
 void rpm_fan(){
  half_revolutions++;
 }

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.

3W 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 (VirtualWire.zip) 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_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);
  vw_set_ptt_pin(transmit_en_pin);
  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);
  delay(1000);
  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()
{
    delay(1000);
    Serial.begin(9600); // Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_set_ptt_pin(transmit_en_pin);
    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.write(buf[i]);
     //Serial.print(' ');
 }
 Serial.println();
        digitalWrite(led_pin, LOW);
    }
}


Sunday, July 26, 2015

The Raspberry Pi and a Neo-6M GPS


Previously I have posted tutorials on how to interface a GPS to an Arduino, but this time I wanted to use a Raspberry Pi. Here is an easy and inexpensive Instructable I have posted, and expansion into other projects will follow.

http://www.instructables.com/id/Raspberry-Pi-the-Neo-6M-GPS/

The GPS module is less than $20


Thursday, July 9, 2015

Arduino ACS712 Current Sensor

The ACS712 is a very easy to use bi-directional current sensor. It comes in 5, 20, and 30 amp versions, and there's only one line of code that needs to be changed depending on which unit you have. This sensor outputs a small voltage that increases with current flowing through the sensor. It isolates the current being monitored from the Arduino, so there's no risk to the Arduino. Most breakout boards come with the needed resistors and caps already installed, so physical hookup consists of +5vdc, gnd, and analog out to one of the Arduino analog inputs. The polarity sensitive current sense pins connect in series with one of the power wires to the device being monitored (either production, or consumption).

In the picture above, looking at the lower right image, the left terminal is the more positive terminal, and the right terminal is the more negative terminal. If you reverse these, you will see negative current readings when you expect positive current readings.

Parts needed:
Arduino UNO
ACS712 5a (20a, or 30a options)

ACS712 Datasheet



Code:

/*
Measuring Current Using ACS712
*/
const int analogIn = A0;
int mVperAmp = 185; // use 185 for 5A Module, 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500; 
double Voltage = 0;
double Amps = 0;

void setup(){ 
 Serial.begin(9600);
}

void loop(){
 
 RawValue = analogRead(analogIn);
 Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
 Amps = ((Voltage - ACSoffset) / mVperAmp);
 
 
 Serial.print("Raw Value = " ); // shows pre-scaled value 
 Serial.print(RawValue); 
 Serial.print("\t mV = "); // shows the voltage measured 
 Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
 Serial.print("\t Amps = "); // shows the voltage measured 
 Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
 delay(2500); 
 
}

Additional reading:
http://henrysbench.capnfatz.com/henrys-bench/acs712-current-sensor-user-manual/

Thursday, July 2, 2015

Solar Powered Arduino Projects

Do you have a wireless project, but wonder how to keep it powered? Wonder no more, as we demonstrate a solar powered / charged Arduino solution.

Parts:

Arduino UNO
Adafruit Power Boost 500 Shield
Adafruit 2000 mAh LiPo battery
Adafruit RGB I2C LCD
Sunkingdom 5w PV panel

The solar panel keeps the Power Boost 500 LiPo charged and powering the Arduino and attached sensors. The Power Boost 500 shield manages the charging of the LiPo battery, and acts as a UPS, maintaining power during periods of sun, and no sun. It provides up to 1 amp of 5v power to your project, which is plenty for most remote sensor projects.

Code for this project (and more details on the Power Boost 500) can be found at http://arduinotronics.blogspot.com/2015/04/arduino-ups-battery-shield.html

Wireless WiFi Weather Server - http://arduinotronics.blogspot.com/2015/06/wifi-weather-web-server.html



Wednesday, June 10, 2015

Jameco Poll - Who are the electronic hobbyists of America?

Below is an excerpt of a poll run by Jameco Electronics

Who are we? Read the whole article and see if you are a match. I personally am in the greater than 35 years, as I started around 9 years of age.

Who are the electronic hobbyists of America?

Nerds or not, more than half of the Great American Electronic Hobbyists Census participants reported that their first experience with electronics involved taking something apart and nearly all reported having soldered before the age of 18. After their initial experience with the soldering iron, nearly half of all hobbyists continued on with their electronics education, making electronics both their avocation and vocation.

A hobby that most likely started during the teenage years (or earlier) has continued to pique interest. The average hobbyist has 35 years of electronics under their belt and an additional 25% have been working with electronics for 50 or more years. It was interesting that almost half of the participants received some sort of formal training in electronics, but also that just as many were self-taught.
When it comes to a reading preference amongst our participants, 42% prefer reading a technical publication over other types of publications, while 27% choose to read news. When we asked our hobbyists which other hobbies they enjoy, it was clear that electronics knowledge and skills play a role in more than just their electronics hobby; 10% reported that music was their second most favorite hobby, 9% told us they prefer woodworking second to electronics (which may or may not correlate to 83% reporting they’ve used an ax or saw within the past year) and 6.4% of participants named computing as their second favorite hobby.

It was somewhat astonishing to learn that the majority of participants (practically 98%) were male despite the fact that 19% of those graduating with bachelor degrees in engineering are women. This may have a correlation with time restrictions between work and family life; we discovered that the average age of our participating hobbyist is 56.

Monday, June 8, 2015

The Arduino Powered Lighthouse

I was helping a friend build a 3' lighthouse, and he felt it could use some "animation". I suggested a Arduino controlled beacon. We didn't want to go to the hassle of building a motorized unit, so I designed a simulated rotating beacon. I picked a 3 watt white LED, but since the Arduino can't control that much current by itself, I used a IRL520 MOSFET. A MOSFET requires a 10k resistor from the gate to ground to turn it off when it's not active. I connected it to a PWM pin, so I could control the brightness of the LED.

Warning! A 3w LED can pull about 700ma of current at 3.3v, so even though we are only PWM'ing at 50% (except for that 50ms 100% pulse), you should have a separate 1a 3.3v supply.

The sketch below fades the LED in and out, and gives a super bright flash between the ramp up and ramp down, simulating the affect of being in the direct line of the bulb on a rotating beacon,

Enjoy!




int cycle=30;
int strobe=cycle*10; // calculate strobe delay
int maxFade=100; // maximum brightness before strobe
int ledPin = 11;    // MOSFET connected to digital pin 11

void setup() {
  // nothing happens in setup
}

void loop() {
  // fade in from min to max in increments of 2 points:
  for (int fadeValue = 0 ; fadeValue <= maxFade; fadeValue += 2) {
    // sets the value (range from 0 to maxFade):
    analogWrite(ledPin, fadeValue);
    // wait for "cycle" milliseconds to see the dimming effect
    delay(cycle);
  }
analogWrite(ledPin, 255); // simulate a rotating beacon catching your eye
delay(strobe); // hold full brightness for strobe delay
analogWrite(ledPin, maxFade);
  // fade out from maxFade to min in increments of 2 points:
  for (int fadeValue = maxFade ; fadeValue >= 0; fadeValue -= 2) {
    // sets the value (range from 0 to maxFade):
    analogWrite(ledPin, fadeValue);
    // wait for "cycle" milliseconds to see the dimming effect
    delay(cycle);
  }
}



Saturday, June 6, 2015

Arduino Hx711 Digital Scale

After finding a broken scale in the trash at work, I decided to remove the load cell and build a digital scale with an Arduino. The output of the load cell is too minute for an Arduino to read on it's own, so I picked up a <$5 amplifier module online to convert the reading into a signal the Arduino can read. The Hx711 module is a 24 bit ADC, which offers high resolution and amplification. It's also designed for scale / load cell applications, so talking to it requires a minimum of code.

Connections are fairly simple. You will need a 4 wire load cell, and those typically have Green, White, Red, and Black wires.

Connect as follows:
Red: E +
White: A +
Green: A -
Black: E -

B- & B+ could be used for another load cell, but we are not using these.

On the other side of the module:

GND: Arduino GND
DT: Arduino A2 (can change this in code)
SCK: Arduino A3 (can change this in code)
VCC: Arduino +5

Library:

You will need to download the library files (the library files at dfrobot will not install properly using the add library function, these will).

Per the instructions at dfrobot, you may have to adjust a value in the Hx711.h file in the library to zero your scale. Mine did not need that.

Code:

/* sample for digital weight scale of hx711
 * library design: Weihong Guan (@aguegu)
 * library host on
 *https://github.com/aguegu/ardulibs/tree/3cdb78f3727d9682f7fd22156604fc1e4edd75d1/hx711
 */

// Hx711.DOUT - pin #A2
// Hx711.SCK - pin #A3

#include <Hx711.h>
Hx711 scale(A2, A3);

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print(scale.getGram(), 1);
  Serial.println(" g");
  delay(200);
}





Thursday, June 4, 2015

Arduino Westminster Chimes Door Bell

I was repairing a Heath Zenith SL-6180 wireless doorbell, in the process, figured out how to manually trigger the bells without using the remote. I then thought, why not have an arduino trigger the bells based on motion sense, floor pad sensor, or pushbutton. The door bell I'm using plays a very nice version of Westminster Chimes. Open it up, find the transistor labeled Q5 on the board and attach a wire to the base (center pin) to an arduino output. Connect a wire from battery negative to Arduino negative. When you want the chimes to ring, pulse the pin you have connected to Q5 - digitalWrite(pin, HIGH);

Other applications could be a audio notification when you get an email, a tweet, or completion of a task.