L9110 Fan Motor Keyes Board

arduino fan2

The Sketch can be downloaded from my GitHub page here and includes the L9110 datasheet.

I came across this somewhat strange board advertised as a Fire Fighter with the claim that the fan was so strong it could be used to put out a flame! With a claim like that I just had to buy one, but I must confess that I have no idea what I will do with it.

The Motor Driver is an L9110 single motor driver that has two inputs INA and INB with two wire out that can drive a small DC motor. It seems to be designed to be used in toys and small robots. INA and INB are driven by logic signals, both inputs set to LOW and the motor is still, with INA HIGH and INB LOW the motor will turn one way and it will turn the other way when INA and INB are reversed.. Two other pins on this board are supplied with  5 volts (Vcc) and Gnd from the Arduino. INA and INB could be supplied with logic signals from any of the digital pins, but the motor speed would not be variable as it would run at full speed in either direction.

PWM can be used to drive the motor at variable speed in either direction and this is what the sketch here does. I found that the lowest stable speed was when the PWM was set to 80, up to the maximum of 255. Below 80 and the speed was a little erratic. I have used a KEYES momentary push button to demonstrate the motor. When the sketch first runs the motor is still. Press the button and the motor rotates, press it again and the motor stops for a brief moment then rotates in the opposite direction. On the third press the motor stops. The short delay when changing direction allows the motor to slow right down first.

The Circuit::l9110 arduino

Circuit diagram

The Sketch::

/*********************************************************
* Fan Driver using L9110 Motor Driver
*
* The L9110 Motor Diver is a simple driver designed for
* toys and robots. It has two inputs INA and INB
* and two outputs to drive a simple DC Motor.
*
* The direction of motor spin can be changed and the speed
* can be controlled using PWM
*
* The device described here is the Keyes Fan Board with
* 4 connections
*
* Connections:
*
* INA to Arduino PIN 5
* INB to Arduino PIN 6
* Vcc to Arduino 5 volts
* GND to Arduino GND
*
* Push Button:
* (the output went LOW on pressing on my unit)
* Gnd to Arduino Gnd
* Vcc to Arduino 5 volts
* S to Adduino PIN 7
*
*******************************************************/
const int INA = 6;
const int INB = 5;
const int pushButton = 7;
const int ledPin = 13; // onboard LED
int action = 0; // 0 = Stop, 1 = Forward, 2 = Reverse

byte speed = 80; // change this to alter speed 0 - 255 although 80 is the minimum for reliable operation

void setup()
{
pinMode(INA,OUTPUT);
pinMode(INB,OUTPUT);
pinMode(pushButton, INPUT);
pinMode(ledPin, OUTPUT); // onboard LED
Serial.begin(9600); // for debug
}

void loop()
{
if (digitalRead(pushButton) == LOW){ // see if button has been pressed
digitalWrite(ledPin, HIGH); // turn on LED
action = action + 1; // increment action
if(action > 2){
action = 0; // keep action in range
}
if (action > 0){
digitalWrite(ledPin, HIGH); // Turn OFF LED if motor stopped
stopFan();
delay(100); // short delay to make direction change easier for motor
}
else digitalWrite(ledPin, LOW); // turn onboard LED OFF
delay(800); // simple switch debounce
}

switch (action){
case 0:
Serial.println("Stop Fan:");
stopFan();
break;

case 1:
Serial.println("Fan Forwards:");
forward();
break;

case 2:
Serial.println("Fan Reverse:");
reverse();
break;
}
}

void reverse(){
analogWrite(INA,0);
analogWrite(INB,speed);
}
void forward(){
analogWrite(INA,speed);
analogWrite(INB,0);
}

void stopFan(){
digitalWrite(INA,LOW);
digitalWrite(INB,LOW);
}

Advertisements

Clap Switch Sound Sensor DIY Kit NeoPixel Ring Display

neopixel_clapswitch

The sketch for this project can be downloaded from my GitHub page here.

This project uses the Clap Switch described in my blog  here and shows how it can be used to step through the display modes in the Adafruit sketch included with the NeoPixel library. I am using a 16 LED NeoPixel ring in this project, if you are using a different number then the number of LEDs needs to be adjusted in the sketch. PIXEL_COUNT is the number of LEDs and PIXEL_PIN is the Arduino pin number connected to DI on the neoPixel ring (in this case Digital pin 5).

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

You need to download and install the Adafruit NeoPixel library from here, I have uploaded my modified version of the Adafruit buttoncycler sketch on my GitHub page here. The original Adafruit sketch used a push switch to change the display, I modified the sketch to use the output from the Clap Switch. With the sketch (clapSwitch_buttoncycler.ino) loaded the NeoPixel display should be OFF. Clap your hands and the LED on the clap switch should go OFF. The NeoPixel ring will start flashing in one of nine patterns, it will continue until you clap again. The ring will stop at the end of the current cycle (which in the case of some of the rainbow patterns may take a few seconds). Clap to start the display running again.

The Sketch::

The sketch is modified from the Adafruit buttoncycler sketch, the code to operate from a push button has been removed and new code to monitor the clap switch has been added. My original code had to be modified slightly as it required two Claps to switch the display ON or OFF. The modified code uses one Clap to start the display and one to stop. The variable trigger is flipped between TRUE and FALSE, with the red LED on the clap switch showing the state (ON = trigger TRUE). The value is checked at the start of the main loop, however, with some of the displays that run for some time, trigger will not be checked until the current display has finished. This will result in a delay before the display is stopped.

The clap switch output turns the on-board LED, on pin 13, ON and OFF to indicate when the variable trigger has been read.

Circuit::

clapswitch_neopixel

Please note that for illustration purposes the NeoPixel ring is shown as being powered by the Arduino. For normal use the NeoPixel ring should be supplied from an external stabilised 5 volt supply.

Clap Switch Sound Sensor DIY Kit

clap switch

This kit is available on eBay for less than £2 and I purchased mine from here. The PCB is of reasonable quality and screen printed with all the component values that make it easy to build this project. Several components need to be connected in one direction, the two electrolytic capacitors easy to align as the negative is shown shaded, the two small diodes have a black band on one end and both are aligned in the same direction. The symbol for a diode is printed on the PCB and the bar on the symbol represents the black band on the component. There are four transistors and they should be inserted on the board so that the flat on the transistor aligns with the flat printed on the board. The microphone position shows a + and a -, but no markings were printed on my microphone. However, the pins are offset and the microphone can only be fitted one way so that it fits inside the printed circle. The last component the needs fitting correctly is the LED, this has one leg longer than the other and, more importantly, a flat on one side. The LED is aligned so that it faces to the edge of the PCB, if it is fitted the wrong way round the completed board will not work.

All the remaining components can be fitted either way round, resistors need to have their their leads bent close to the body. There are two values of capacitor, 0.1mfd and 0.01mfd (marked as 104 and 103 respectively), fit the 103 first, then fit 104 capacitors to avoid fitting the 103 in the wrong place. The power socket should obviously be fitted with the open end facing the edge of the board. I soldered a two pin plug to the supplied power lead so that it could be plugged into the Arduino 5volt and Gnd.

Once everything is soldered you will probably find a small printed rectangle alongside the LED with two holes, mine was printed with Link. At first I thought I had a missing component or a small wire link was required, but checking the copper side of the PCB showed one of the solder pads was connected to the 5volt track and the other solder pad was on a copper track alongside the 5volt track. I suspected that this may be the output from the Clap Switch and decided to fit a two pin male header. However, the hole spacing was not exactly 0.1 inches and I had to very carefully enlarge the holes. Be very careful not to destroy the solder pads or push the off the board if you do this! The alternative is to simply solder two leads into these holes, it’s up to you.

The board is very compact and the solder pads vey close together so be careful not to short pads. I use a stiff brush and alcohol to clean all the flux etc from the board after soldering. Use a magnifying glass to check for dry joints and shorts. Once you are happy all is well you can connect to a 5 volt supply or use the 5volt and Gnd pins on an Arduino. The LED will light up (it did on mine, but this may be random). Clap your hands about 1 foot from the microphone and the LED will change state. Clap again and it will change state again.

I suspect, although I have not checked, that the circuit is a microphone pre amplifier with its output fed into a bistable flip flop similar to this one


Which is why the output remains in one state and need another trigger to switch to the other state. I used a multimeter connected to the two pins I had soldered alongside the LED, when the LED was lit it showed about 4.8volts and when the LED was off it showed just under 1 volt. The pin closest to the edge of the board is always 5 volts, so I ignored that on, the other pin will be equivalent to HIGH when the LED is not lit and LOW when lit.

I use the term Clap Switch Output pin to identify the pin circled in red below. The pin above this is connected to the 5volt PCB track and can be ignored. It is important that the Gnd of the Clap switch is connected to the Arduino Gnd, but if it is powered from the Arduino this will happen automatically.

I did try using the output from the Clap Switch to trigger an interrupt on the Arduino pin 2 and this worked well in a quiet room, however the results were erratic with background noise. There is no rush to read the state of the switch, simply read the state at a convenient point in your sketch. The sketch below shows how this can be done, it reads the voltage on pin A0 and sets the variable trigger to False if it is above 2 volts and True if it is below 2 volts. The onboard LED on pin 13 is the lit if  trigger is True.

/***********************************************************
Clap Switch Simple Control
by
Chris Rouse
May 2016

Connections:

Vcc to Arduino 5 volts
Gnd to Arduino Gnd
Output to Arduino Analog pin 0

***********************************************************/
const byte ledPin = 13;
boolean trigger = false; // used to show clap output ON
int triggerLevel = 100; // change this if background noise is high
int outputReading; // voltage output from Clap Switch

/*********************************************************/
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn LED OFF
}
/*********************************************************/
void loop() {
checkSwitch(); // see if the switch has been triggered
if(trigger){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
//

// put the rest of your program here

//
}
/*********************************************************/
void checkSwitch() {
outputReading = analogRead(14);
if(outputReading > triggerLevel){
trigger = false;
}
else{
trigger = true;
}
}
/*********************************************************/

Arduino Crash Sensor

crash sensor

This sensor is simply a micro switch. When the small lever is pushed in an on board LED lights and the output goes LOW. The following sketch lights the LED on the Arduino when the lever is pressed.

// Crash sensor
int ledPin = 13;
int inPin = 8;
int earthPin = 6;
int vccPin = 7;
int valueCrash = 1;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT_PULLUP);
pinMode(earthPin, OUTPUT);
pinMode(vccPin, OUTPUT);
digitalWrite(earthPin, LOW); // provide 0 volts for Gnd
digitalWrite(vccPin, HIGH); // provide +5 volts for Vcc

}

void loop() {
valueCrash = digitalRead(inPin); // read the state of the crash sensor
digitalWrite(ledPin, !valueCrash); // light LED if switch closed
}

 

 

5×4 20 Key Matrix Keyboard Electronic Lock

20 key keypad

The code for this project can be found on my GitHub page here.

See also the post describing the simple program to read this keypad here.

This project illustrates the use of the 20 key matrix keyboard shown in an earlier blog here. These keyboards can be obtained on eBay, often for £1 but don’t lend themselves to being used for calculators. However, they make an ideal data entry pad for something like an electronic lock.

I have chosen not to include any electronics such as relays or servo motors as these can easily be added to suit the individual needs. There are two locks, each with their own password, selected by pressing either F1 or F2. The password is a four digit number, although it can be increased by changing the variable maxNumber. Other non digit keys (except for the arrow keys) have various functions. Ent is used to lock the current Lock. Esc will abort code entry in the case that a wrong digit was entered (this could be useful if the number of incorrect code entries is limited before no further entries were allowed). # will show the current state of both locks and finally * will lock both locks at once, regardless of their current state.

The output is sent to the Serial Monitor and the on board LED is lit if the current Lock is closed.

The circuit:

The connection diagram is shown below, the keyboard uses nine digital pins and pin 13 is used to show the status of the current lock. This leaves two digital pins and the four Analog pins to operate relays, servo motors etc. Connection data is provided in the sketch.

5 x4 Matrix 20 Key Membrane Keyboard

The code for this project can be downloaded from my GitHub page here.

See also the post using this keypad as an electronic lock here.

I saw these membrane keyboards on sale on eBay for around £1, for example this one here. They are only a milimetre or so thick and although they will not be much use for a calculator they could be used for a keypad entry system.

I have already produced a sketch to read a 4×4 matrix keyboard and decided to modify that to read this four column by five rows keyboard. I made a few changes and the code returns a numeric code from 0 to 19 that represents each key in addition it returns a string with the name of the non numeric keys and finally an integer representing the numeric keys.

The sketch scans the rows checking each column to determine which, if any, key has been pressed. To use the sketch open it in the Arduino IDE and you will find a blank section in the centre, add your code here. If no key has been pressed then the variable keyString will be an empty string and the integer keyValue will greater than 20. The keypad is scanned continuously, but it does not take long and it’s unlikely that you would use the keypad in a situation that takes too much time to respond to key presses. The connection diagram is shown below and an example of this key pad being used for data entry in a two lock electronic lock can be found here.

Unlike keyboards made using individual keys this keyboard does not seem to need any key debounce code. Connection information is provided in the sketch.

 Arduino Amusment Arcade Game.

arcade_project

The code, graphics and sound files can be downloaded from my GitHub page here.

I was in an old fashioned Penny Amusement Arcade recently and one of the machines caught my attention. Most of the games were original 1940’s and 1959’s machines modified to take modern coins, but this one machine looked as though it had been built recently. It was housed in a large polished wooden case about five feet high by about eighteen inches wide. It had a two line by forty character  LCD display and a large number of discrete LEDs. A voice spoke the phrases displayed on the display.

montage

Showing the original machine on the left and a selection of screens from this project

This was a machine designed to find your perfect partner in life! I put my coin into the slot and was told to place my fingers on the sensor. After a few more displayed and spoken phrases the main display came to life, this consisted of six vertical rows of ten LEDs. These represented personality, brain, looks, shape, wealth and height. Each column was lit to a random height to represent the characteristics of your perfect match.

This seemed like a perfect project for an Arduino and colour TFT display and I took some pictures of the machine to remind me of what it did when I got home. I spent several evenings designing the screens for the display in Photoshop. The display is 320×240 pixels and I decided that a landscape format would be the best to use. From previous experiments with the display I knew that a good way to use graphics was to load a full size graphic then to load smaller graphics on top.

The first problem I encountered was that the TFT display used almost all the Arduino pins, except 0, 1 and A5, and I was unable to get it to work with a Mega. The recommendation for using this screen with an Arduino Mega is to modify the library to use software SPI , but it just would not work. I needed to add a touch switch and the WTD588D so it was obvious that something else was needed. Software interrupt would allow the remaining pin, A5, to be used leaving pins 0 and pin 1.

A second Arduino could be used to control the voice chip through commands sent over the serial pins (0 and 1). The final version used two Arduino Nano boards and the WTD588D voice board. The sketch used the Adafruit library for the ILI9341 and part of an example sketch, that loaded BMP image files. This produced a large volume of debug data sent out over the Serial port, very useful for keeping an eye on what was going on, but produced chaos when fed into the Arduino Nano controlling the voice chip. The answer was fairly simple, voice commands were prefixed with a # character. This character does not appear in any of the debug data output, the Nano controlling the voice chip reads all the data coming into the Serial port and just ignores everything until it finds the # character. Data that follows this control character is treated as a voice command by the WTD588D

The circuit:

All three boards fitted onto a piece of solderless board, with the TFT display wired onto the solderless board. The parts required are:

  • Arduino Nano x 2 see eBay
  • WTD588D -U32M voice board see eBay
  • Single capacitance touch switch see eBay
  • Breadboard PSU (optional) see eBay
  • Breadboard 830 points see eBay
  • Jumper wires (male to male and female to male) see eBay

The best thing to do is to upload the programs to each of the three boards before mounting them on the breadboard, all three are fitted with a mini USB socket. (Check your breadboard, the power rails running across the top and bottom may have a break and will require a jumper wire to connect them).

The code is all available on my GitHub page and has the WTD588D project files and the WAV files needed, as well as the two sketches. Arduino_Arcade_Main.ino contains the main code. This needs several libraries – the library for the ILI9341 TFT display shield can be downloaded from the Adafruit site here and the graphics library Adafruit_GFX can be downloaded from here. The software interrupt library called PinChangeInt can be downloaded from here ( I found that SoftwareSerial would not work with this library). For the WTD588D driver Arduino Nano the sketch is Arduino_Arcade_Voice.ino, the library, and instructions for uploading the sound files to the WTD588D can be found on my blog here.

circuit diagram

The Gnd pins on all the modules must be connected together. The Arduino controlling the Speech module supplies the 5 volts for it. The main Arduino supplies 5 volts for the touch switch and the display. Originally I powered all modules from a single stabilised 5 volt supply, connecting it to the Arduino’s 5 volt output. A number of articles seemed to show that it was possible, but I eventually killed one of the Arduino’s so went for the option of supplying power to the two Arduino’s through their USB connectors.

The software:

The folder of graphics files should be transferred to an SD Card (the bmp files must be in the root of the SD Card, don’t load a folder to the SD Card). The voice project should be uploaded to the WTD588D as described above. The Arduino that is used to control the WTD588D should have the sketch Arduino_Arcade_Voice.ino uploaded. The main Arduino that controls the TTF Screen should have the sketch Arduino_Arcade_Main.ino uploaded. Upload all the code before wiring the project up. Connect a speaker to pins 9 and 10 of the WTD588D and apply power to both Arduino’s through the USB port, after a short delay the screen should display the opening graphics and speak the associated phrases. The introduction will loop continuously until the touch switch is touched. In the Arcade machine, this serves to attract customers. Once touched the next part of the programme will start providing the random results.