February 26, 2013

Arduino IR remote library

If you have an Arduino project where you need to handle remote control infrared signals you should have a look at IRremote library by Ken Shirriff. It recognizes many commonly used protocols and can also capture and send raw data for unknown protocols. Download it from his github page:
https://github.com/shirriff/Arduino-IRremote

I used the provided example named IRrecord to receiving and transmitting codes with my Panasonic TV remote. It was recognized as raw and it worked well to learn codes and send it to control my TV. A clever trick to see if you transmitter is working is to use your smart phone camera. Looking at the IR led in the camera viewer enables you to see the IR light.
Here is how to wire the sensor and the IR led, the button is is used to send the last captured code.


By opening the serial terminal the captured code can be viewed. It shows the length of the mark and space in the code.

February 20, 2013

Connecting Arduino to MK802 running Lubuntu


I had an idea of combining a MK802 running Linux with an Arduino UNO to get some I/O pins controllable from the MK802. This post describes how to do serial communication over the USB cable with a terminal application and with Python.

Boot Lubuntu and login then connect the USB cable from the Arduino to the MK802 and open a LXTerminal and type:

dmesg

It will print of lot of information but look at the end for lines similar to these:

[  217.500000] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[  217.510000] usbcore: registered new interface driver cdc_acm
[  217.510000] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

This means that you Arduino is mapped on the device name ttyACM0. To open a serial terminal to this device type:

screen /dev/ttyACM0

If screen is missing install it by typing:
sudo apt-get install screen

Below I have run screen with the example "Communication -> ASCII table" from the Arduino Software. I prepared the Arduino UNO with the code on a Windows computer before  I connected it to the MK802.


The serial communication can also be done with a Python script. Create a file named Arduino.py with the lines below it an run it with:
python Arduino.py

import serial
ser = serial.Serial('/dev/ttyACM0')
while 1:
  while ser.inWaiting() > 0:
    print ser.readline()
 
It should result in a something similar to the picture below.

February 15, 2013

Installing NewPing library for Arduino

Just for fun I decided to play with an ultrasonic sensor for distance measurement and an Arduino. The sensor that i used is the HY-SRF05. The included example for Arduino is written for the Parallax PING sensor. The HY-SRF05 is a bit different from the PING in the sense that it uses two pins for communication instead of one. This is not supported by the default example. But luckily there is a good alternative. The NewPing library has many features and support the HY-SRF05. It is available for download from here: http://code.google.com/p/arduino-new-ping/

The installation of an Arduino library is easy. Just unzip the library files in your Windows Documents folder in the folder Arduino\libraries\<LibName> as illustrated below.

 

The library integrates well in the Arduino Software and comes complete with examples.

The HY-SRF05 runs from 5 Volts so it is easy to use with the Arduino. The trigger pin is connected to pin 12 and echo pin to pin 11 on the Arduino. This is how it looks when it is running.
The accuracy of the sensor seems to be fairly good but I did not evaluated that throughly.

February 11, 2013

Inkscape - Editor for SVG files


Inkscape is a free and open source vector graphics editor. I have used it for editing of images for Fritzing parts with good results. You should not be fooled by the low version number. This is very capable software. If you looking for a free alternative to Adobe Illustrator this is a good candidate. Below is the SVG file for the Fritzing part for the JY-MCU Bluetooth module that I made. The SVG file is available for download from here.

February 6, 2013

Practical low cost SMD components kit


A couple of months ago I ordered an SMD components kit on ebay. I have used it for some time and I have to say I like it! It is small and has the most common values of the components. In the picture below you can see a size comparison with an Arduino UNO.


The kit is a book with resistors and capacitors in pockets with labels. It has 3025 of resistors in 63 values from 0Ω to 2MΩ and 700 capacitors in 17 values from 15pF to 1uF. The component size is 0805 (2.0x1.25mm).

Search on ebay for "Practical SMD resistor and capacitor components, assorted folder kit" The price is about $32. I am not associated with the seller of this item.

January 30, 2013

Fritzing - Veroboard and Breadboard design software


If you are looking for a free tool to create schematics and documentation for your prototypes, Fritzing may be right for you. It can also be used to created and manufacture PCBs from your design. Frtizing has three views that share and automatically update a netlist so that if a component or connection is made in one of the views it is also added in the other two. The views are called Breadboard, Schematic and PCB.


In the Breadboard view your design look and feel like physical objects. It has regular components like resistors, capacitors, inductors and ICs. It also has cables, Veroboard, Breadboard and blocks like an Arduino, sensors, servos, motors and many more.

The Schematic view is a traditional electronics schematics editor. As mentioned Fritzing has the most commonly used components and modules in the built in library but if your favorite part is missing it can easily be added. I added the JY-MCU Bluetooth module from my previous post by modifying an existing component within minutes.Download it here.

I felt that Fritzing is easy to use and learn. But it was not obvious to me how to cut the lines on a strip board. It turned out that it is quite simple, right click betweens the holes as illustrated with the arrow in the figure below.
I did not try the PCB design part at this time. Fritzing installer package are available for download from: http://fritzing.org

January 25, 2013

Bluetooth with Arduino

I recently purchased a low cost Bluetooth module with serial interface. I decided to hook it up to my Arduino.

Arduino UNO does only have one UART that is used for the USB serial terminal so it can't be used but there is a Software UART available that uses regular I/O-pins. For details see:
http://arduino.cc/en/Reference/SoftwareSerial

It works well at 9600 baud but when i tried 115200 the reception failed and received characters was corrupted. This worked in my previous test both with an FTDI cable and a Bus Priate.

The baud rate of the module can be changed by sending a AT command before connecting to the module to a Bluetooth device. The command is:

AT+BAUD<index>

Where <index> is an hexadecimal number from 1 to C. The rates are: 1:1200, 2:2400, 3:4800, 4:9600, 5:19200, 6:38400, 7:57600, 8:115200, 9:230400, A:460800, B:921600, C:138240

WARNING: Do NOT set it higher than your device is capable of since you will need to communicate at the new rate after sending this command. I used an FTDI cable for changing back the configuration. 

The board is marked "JY-MCU BT_BOARD v1.03". The supply voltage is stated to 3.6 - 6 V on the board. But the RX and TX terminals are 3.3 Volt logic. Therefore a voltage divider as shown in the figure below is need for the TX output on the Arduino when connecting it to RX on the module. The TX on the module can be connected directly to the RX on the Arduino. I have put the two resistors on a veroboard.The values are R1=10k and R2=20k.

Below is the Arduino code I used for the tests. It transmits received Bluetooth data to the USB terminal and vice versa.


#include <SoftwareSerial.h>
const int RxPin = 10;
const int TxPin = 11;

SoftwareSerial Bluetooth(RxPin, TxPin); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect.
  }
  Serial.println("Init done!");
  // set the data rate for the SoftwareSerial port
  Bluetooth.begin(9600);
}

void loop() // run over and over
{
  int data;

  if ((data = Bluetooth.read()) != -1)
   Serial.write(data);


  if ((data = Serial.read()) != -1)
   Bluetooth.write(data);
}