Shakeable Dynamo Part 4: Building the bridge rectifier

shakeable-dynamo-part4

[ad#Google links]

Shakeable Dynamo Part 1: Why bother?
Shakeable Dynamo Part 2: Building the initial dynamo
Shakeable Dynamo Part 3: How electromagnetic induction works

Lets start off by securing our coils on our alternator by removing the cardboard guides and then getting some clingfilm and wrapping a piece around your coils and then wrap a bit of tape around it to secure it all. Now we know it works, we don’t want to risk our coils moving or our connections breaking.

What’s a rectifier?

Diode

So what is a rectifier? A rectifier converts AC current to DC current, so we convert the current that changes direction to flowing in one direction. That means we’ll then get the full benefit of the electricity we’re creating rather than only half of it. Rectifiers use a series of diodes to achieve this. A diode (pictured left) is essentially a valve, it lets the flow of electricity through only one way, shown by the green arrow in my diagram, the silver band indicates the cathode  (-). By arranging a few of these together we can then convert our current by forcing current to flow one way.

How does a bridge rectifier work?

In the diagrams to the right, the flow of electricity is shown, red arrows for positive, black for negative. In the top diagram the current flows across the top diode from the alternator to the output, negative is flowing across the bottom from the green wire, back through the diode to the alternator. When the magnet changes direction and the current reverses, the bottom diagram shows that the flow is blocked and can only flow to the same positive output. So no matter which way the magnets move or whichever direction the current moves in the diodes always divert the flow to the same points.

How to build a bridge rectifier circuit

With that understood we can then plug in our hook up wire from our alternator into a breadboard to build the basic rectifier circuit which we can then check that it works and solder it to our leads. You can see in the series of photos below that we take the 2 leads from our alternator, connect them to the diodes as per the circuit diagram, then we attach another 2 leads to the 2 remaining ‘corners’ of our bridge rectifier – and remember these now are direct current and one lead will be positive and the other negative so it will matter which way you attach the LED or any other component.

Shakeable dynamo: Build a bridge rectifier

Cut and solder the diodes and leads together.

Shakeable dynamo: Solder the bridge rectifier

Then ‘wrap’ the circuit over the end of the tube.

Shakeable dynamo: Trim and wrap the rectifier around the end of the biro

And finally secure it into place with some electrical tape.

Shakeable dynamo: Tape over the connections

You can see that I’ve also soldered on an LED to the new DC power supply, also remember to mark out which wire is positive and which is negative. Here’s the final result again working…

Coming up – improving the alternator and charging a battery with it…

Shakeable Dynamo Part 3: How electromagnetic induction works

Atoms of a magnet

[ad#Google links]

Shakeable Dynamo Part 1: Why bother?
Shakeable Dynamo Part 2: Building the initial dynamo

Right, so we’ve built the initial alternator/ dynamo and it works, not amazingly, but it works and we need to make this is a little bit more robust and protect all those lovely windings as well, at the same time we also need to convert our alternating current (AC) and convert that to direct current (DC), so that we can use this to power a small circuit/ LED without it turning on and off all the time. First I should probably explain how this all works… (feel free to correct me if I am wrong in my assumptions)

How do magnets work?

Atoms of a magnetEvery magnet creates a magnetic field due to the arrangement of the atoms in the material, in very simple terms, the atoms are spun so that most of the electrons are on one side of the atom, creating a negative charge on one side, while the lack of electrons on the other side of the atom exposes the positive charge of the protons in the nuclei. In the very simplified diagram to the left, the  nuclei are blue and the electrons are orange and their arrangement produces the  different overall charges with more electrons flowing to one end of the magnet. This also explains why when you cut a magnet in half you will get 2 magnets, not a separate south and a north pole. This then creates the polarisation effect we see in magnets and this is also where naming conventions jump into confuse matters! So first of all magnets are referred to has having a ‘north’ and a ‘south’ pole due to this polarisation effect from the different atomic charges. This is because when suspended freely, the magnets ‘north end’ will spin to point to the Earths magnetic north, which if you think about it makes no sense, since magnets attract the opposite pole (North attracts South). What is really happening is the ‘north’ pole of a magnet has a negative charge due to the arrangments in the atoms and it’s attracted to the positive charge of the Earths magnetic north – so either the north end of our magnet is actually south or the Earths magnetic north is actually magnetic south.

How does electromagnetic induction work?

how electromagnetic induction works

Electromagnetic induction essentially is where a magnetic field or flux causes the flow of electrons in a conductive material. This is actually important to us in explaining what’s happening in our alternator, our north pole of the magnet is negatively charged, the south has a positive charge. This means that they will always try to attract an opposite charge, so when a magnet passes through or near an object with good electrical conductivity, the electrons in the conductor will be attracted to the south pole of our magnet, while the north pole  will repel the electrons. This creates a movement in the electrons, essentially creating a flow of current, some materials will have a better conductivity as the electrons are able to move more freely. You can see in my basic diagram above how the magnet will attract and repel the electrons (orange circles) in the wire thus creating the alternating flow of electrons or current – without getting too complicated alternating means the current flows in 2 different directions which produces a sine wave.

Now, what happens as our magnet passes through our coils is that the electrons are pushed and pulled creating our alternating current, so the current switches directions based up on whether the electrons in the coils are being attracted or repeled. This then means that at either end of our coil there is an intermittent electrical charge switching between positive and negative, so an LED attached to one end will only light up when the magnets push/ pull the electrons in one direction.

Whats the difference between alternating current (AC) and direct current (DC)?

We want to get all the power of the alternator and not just half of it so we need a way to create a constant flow of current/ charge/ electrons so that our LED will always light up no matter which way the magnets are moving. This is where our rectifier comes in, converting or AC to DC (Direct Current). Direct current is where the current flows in only one direction, classically this is described as going from positive to negative and in most electronics this is the model that is used, however, in physics it’s considered the other way around!

Now that’s all understood we can move on to building our rectifier for the generator

Shakeable Dynamo Part 4: Building the bridge rectifier

Shakeable Dynamo Part 2: Building the initial dynamo

shakeable-dynamo-part2

[ad#Google links]Shakeable Dynamo Part 1: Why bother?

Firstly, there is no such thing as ‘free energy‘ you have to always put something in to get something out. I call this free energy because it comes from your own movements rather than having to pay cash for a battery or the juice to charge it, I guess it’s better to call it ‘financially free energy’. Also when you look at this, some of you may point out that this isn’t a dynamo because it generates AC current, but I call it a dynamo because of the bridge rectifier built in to that converts this to DC.

Basically like all alternators and dynamos it works on the principle of converting mechanical energy into electrical energy by inducing current in a conducting medium, such as copper wire, using a magnetic field. Typically this is done by rotating a magnet inside coils of wire.

My alternator works in much the same way – we move a magnet through a coil of wire to induce a current, only we do this in a linear motion rather than circular. There are lots of crazy equations out there that state how much current you will get from a magnet of certain strength, a certain number of coils of wire of a certain thickness etc…

Mine is much much simpler – I first did a very small test to check that the principle worked, with only a few coils I got a current. Then I just kept winding until I got to a certain thickness and invariably got bored! My windings weren’t at all neat and were all over the place, so if my bodge job worked a more precise version will work better (probably).

So the main question arises – how much current can I get out of the smallest amount of wire and magnets. My aim was to build something to the thickness of an AA battery.

Ok, lets look at all the parts you’ll need, it’s actually not that many and for your magnets and wire – get it off ebay, you’ll get far more for far less than from buying them from a retailer.

What you need to build a simple dynamo / alternator

Parts

  • 1 biro or piece of tubing with a 6mm diameter cut to roughly 10cm in length, the magnets will need to slide freely down the tube
  • At least 3 neodymium (rare earth, super strong) circular magnets with a diameter of 6mm – you can buy a set of 50 for not very much – these are really strong so be careful
  • Magnet/ winding wire around a 32-42 AWG, thinner wire (42 AWG) means more coils
  • 4 ‘N’ series rectifier diodes – any will work fine for our low voltage most of the 1n series have the same voltage drop – I used 1n004’s
  • Some hookup wire – around 18-22 AWG (any wire will do really) for soldering the magnet wire to and building the circuit.
  • An LED (for testing)

Tools

  • Soldering iron & solder
  • Breadboard – useful to build the bridge rectifier and test the dynamo
  • Cutters & wire strippers
  • Also handy to have a multimeter to check the output and a couple of screwdrivers or sticks to help spool the wire

Other materials

  • Some clingfilm and electrical tape

So lets build it step by step with my photos, at the end of this you’ll have the basic dynamo, Step 4 at the bottom will show you how to build the rectifier and the theory behind that.

How to build the alternator

First check that your magnets slide easily through your tube, you may need a few connected together to stop them spinning inside or getting stuck.

Now get your tubing or pen and cut it to size, about 10cm in length

Shakeable dynamo: Cut the biro

Next we need to add some ‘guides’ so that we can keep our coils in place on the pen, I used a square of cardboard from a box taped on the ends

Shakeable dynamo: Add a guide for the coils

Now the fun part, winding the coils. First don’t bother taping down the end of the wire, instead make a small cut in one of the guides and use this to hold the wire in place as you wind – you need to be able to get to both ends of the wire later on! You’ll need to save about 5-10cm.

The easiest way to coil the wire would be do use a drill or something to spin the tube, taking wire off the reel, but this wire is so thin that if it gets snagged it will snap and you have to start all over again. Best to do it by hand and watch some TV as you do it, it doesn’t take that long just stick your tube over the a screw driver so you can spin it and stick the reel onto something like a drum stick.

With the reels stick on your lap, the reel between your legs, you can now hold the tube and spin it on the screwdriver to wind the coils and keep a fairly good tension. If you want to be precise then you can wind the coils accurately or like me just wind away in any fashion.

Shakeable dynamo: Spool the magnet wire on to the biro

I kept winding until my coils got to the thickness of an AA battery, so a diameter of about 12mm – took a while but after a while it gets easy, especially if you’re not fussed on how well it’s wound.

Next we take 2 pieces of our hookup wire, remove the casing on either end and then wrap one end of the copper magnet wire to one end of each wire, you’ll need several coils around this wire.

Shakeable dynamo: Wrap the ends of the magnet wire on to some thicker wire

Now get out that soldering iron and get it heated up, the heat of the solder on the ends of the wire will melt away the very thin varnish on the copper magnet wire while it also binds it to the hook up wire. Be careful as the thin wire will snap very easily and you’ll need to repeat this step.

Shakeable dynamo: Solder the wires

Before we go further you may want to check that the connections are good with a multimeter set to measure continuity. As long as there is some fluctuation in the initial reading all is good. You can see that I’ve temporarily secured my magnet wire to the guides. This is also a good time if you want to measure the current generated when your magnets pass through the tube / pen.

Shakeable dynamo: Test for continuity

And thats it, shake the magnets inside the tube to generate a current the basic alternator is built, you can hook that up to a breadboard to play with, if you add an LED and shake the generator you’ll see the LED light up, it’ll be quite dim and no matter how fast you shake the magnets, the LED doesn’t remain consistantly powered, this is because the current is alternating and an LED require direct current instead.

Once you’re happy and understand whats happening we can proceed to step 3 which improves up on the blinking LED and gives you a current you can actually use.

Shakeable Dynamo Part 3: How electromagnetic induction works
Shakeable Dynamo Part 4: Building the bridge rectifier

Shakeable Dynamo Part 1: Why bother?

brother-battery

[ad#Google links]

First of all I have to start by condemning Brother Industries for what ultimately motivated me to build this basic prototype, allow me to explain and I apologise for the rant, the good stuff follows…

I read an article on the BBC news website (Vibration packs aim to replace batteries for gadgets) about a new type of battery developed by Brother that would require no external power source to charge it, just vibration from shaking it a few times. The aim being to replace batteries in low power applications such as TV remotes etc… thus removing alot of these batteries from the environment and ultimately saving energy.

A really nice, clean and elegant solution which could really benefit not only the developed world but for people in the developing countries. What a great company Brother Industries is until you read at the bottom of the article “There are no plans to commercialise the batteries as yet, according to Brother.”

Wait… So you’ve invented, or rather figured a way to not only replace millions of batteries in the common household, cutting down on waste and pollution providing free energy. But also a way to provide cheap portable power sources to people who can’t afford batteries, giving us as near as you’ll get to an ‘ever lasting battery‘!

And instead of rushing this to market, you do what… Nothing! Absolutely nothing. What a shame and a waste, I can’t help but feel that people at Brother have an interest in Duracell etc… as they obviously wouldn’t appreciate a battery that you don’t need to replace. It’s that kind of mindset of greed and ignorance that ruins the planet for the rest of us.

So this is leading somewhere, I assure you! I thought, how hard can this be to build my own – wouldn’t it be great to build a set of batteries that I could use to power my remote, wait wouldn’t it be even cooler to use this to power my Arduino? or even better build an interactive TV remote that you used like a wand to change channel with no power source needed. When you start imagining the potential applications and how this could revolutionise electronics and interactivity, its even more of a shame on Brother for doing nothing with this. Imagine Nintendo using this in their Wii remotes for instance? Imagine this being used to build a simple water tester… etc.

Anyway, here’s the start of it I’m going to show you how to build a basic dynamo with a bridge rectifier that converts our AC current to DC, and the size of it is not much bigger than an AA battery – it’s my first attempt and it turned out pretty well. It generates enough electricity to power an LED – doesn’t sound like much but when I figure out a condensing and charging circuit that’s when the fun starts – for which I’m hoping that you fine people of the web will help me out! :)

Ready to learn a bit about electro-magnetism and inductance?

Shakeable Dynamo Part 2: Building the initial dynamo
Shakeable Dynamo Part 3: How electromagnetic induction works
Shakeable Dynamo Part 4: Building the bridge rectifier

Arduino Robot Arm – LarryArm v0.1

Arduino-robot-arm

[ad#Google links]

I have constructed a basic Arduino robot arm using 3 servos that cost me £15 in total plus a couple of hours in time to build and it’s very simple that I think anyone can replicate and build this. I already had the Arduino Duemilanove ATMEGA328, some foamboard, tools and glue. The robot arm has 3 joints and moves in the X and Y dimensions – not the Z (although I will build this in subsequent versions). I’ve included some very basic Arduino robot arm code along with robot arm design / blueprints and measurements for you to download and build (on any material).

So firstly, I had a look around for robot arm kits that could be brought rather than fabricating the parts myself – I found the prices to be extremely prohibitive. I then looked at getting a design fabricated but most of the designs I’ve seen rarely give you or decent assembly instructions. I also looked at servo brackets and constructor sets but again whilst the odd piece is OK trying to get the parts for a robot arm is too expensive.

Where does this leave me, apart from being too poor to afford a robot arm kit? Well I thought how hard can it be to design and build my own robot arm? Surely I can do it for less and if it works I can publish the results and schematics rather than just a video of it working. So follow my below steps.

The first problem of designing your robot arm is how do you mount the servos? Most kits tend to use some kind of bracket that the servo is mounted into, the armature then mounted to this bracket. For a simpleton like me this seems like a lot of effort, my workshop skills not being that great and neither is my patience, I didn’t want to go down this route. After much thought I hit upon a simple idea, rather than build a bracket, how about altering the servo casing its self. They’re made from ABS plastic, they’re cheap and tough enough that drilling a hole to create a mounting peg should be easy, the drawing below shows where I added the bolt at the bottom, although measurements only show the nut the bolt is about 8mm in length – all depends on how thick your material is you’re using for the arm.

As you can see from the photos below, I take the base of the servo off and drill a hole in about the same position as the servo shaft at the top, this then allows me to place the servo directly into the armature using a bolt through the base of the servo so that it can turn freely in the arm without needing a bracket.

Robot Arm Servo Modification

 

Take the servo base off

 

Drill the servo base

 

Modded servo for arm

Arduino Robot Arm Design

 

Once this problem is overcome, the rest is easy. You can use my robot arm design below, click on the image to download the PDF:

Just print this off and stick it to the material that you’re cutting then cut the shapes out, if you’re using something more rigid than foamboard you won’t need the cross supports I added. I’ve also included a measurement of my servo in the diagram and remember to alter the measurements for the thickness of your material if needed (My foamboard was 5mm thick).

[ad#Google Ad in content]

Robot Arm Assembly Instructions

 

Robot arm

 

Robot arm parts

 

Assembling

 

Nearly finished robot arm

And as you can see from above the main arm gets assembled using nothing more than hot glue and my cutting isn’t even that neat. Here are the assembly steps:

1) Download and print my design
2) Glue the printouts to your material you wish to use
3) Cut all parts out
4) In joints B and D you’ll need to make a hole for the servo bolt to sit in – my drawings have this area marked as well as a larger circle for positioning the top of the servo
5) Now we fx the parts together, you’ll need to put the servos into joints A and C first, I used ht glue to fix the servo wheel to the arm, but you can screw it instead for a stronger fixing
6) With joints A and C in place we attach the joints B and D
7) Finally we attach joint A to a base so that we can counter weight the arm

[ad#Google Ad in content]

Robot Arm Arduino Sketch and Circuit

 

Thats it. Now we just plug the servos into the Arduino board and control them with a simple sketch (below). For the circuit I used a breadboard to share the power supply to all the servos and the outside pin (normally white or orange) gets connected to a PWM pin on the Arduino board (9, 10 or 11 in this case)

The control of the servos and the circuit is no more complicated than my other Arduino servo projects

/*
LarryArm v0.1 Arduino Robot Arm test sketch to check servos and arm works.
*/

#include  

Servo shoulder;
Servo elbow;
Servo wrist;
int pos = 0;    

void setup()
{
  shoulder.attach(9);
  elbow.attach(10);
  wrist.attach(11);
} 

void loop()
{
  for(pos = 0; pos < 180; pos += 1)     {                                       shoulder.write(pos);       elbow.write(pos);     wrist.write(pos);     delay(15);            }    for(pos = 180; pos>=1; pos-=1)
  {
    shoulder.write(pos);
    elbow.write(pos);
    wrist.write(pos);
    delay(15);
  }
}

With that loaded in I got the following result, it worked but there were a couple of bugs. Turns out the servos are using more power than my USB port to te Arduino board can provide, so I’ll have to run the servos on a separate power supply. Also turns out that you get what you pay for, I brought the cheapest servos and they struggle to accurately write their position. For anyone wondering what that is on top of the arm its just the heaviest thing I could find near by to counter weight the robot arm.

Enjoy!

11 Arduino Blogs for July

In a bid to help other Arduino users find some inspiration and help I’ve written a brief round-up of the latest blogs I’ve seen/ read from the Arduino Forums feel free to send me links to your blogs for my next post.

In no particular order other than alphabetical, 11 sites that are worth looking at for inspiration for Arduino – I’ll try and showcase some of the projects from these sites over the coming months. You can also find these sites linked from my Arduino link directory

Arduino Antics

A blog about Arduino, and antics to master it!

Home of the very useful MAXDAC libary for digital to analog convertors and the Digital Potentiometer library, free to download and use.

 

Arvydas

Software development and electronics

Some basic Arduino stuff and robotics – check out the robot project and detailed work with LCD screens with sample code and and diagrams.

 

BLD-Live.dk

Saving the Enviroment… maybe

2 very cool projects on here, controlling the garage door opening mechanism with Arduino and even better than that RFID tagging your cat to track it when it passes through the cat flap.

 

Brandsby.dk

Home of HCC the Home Control Center

Detailed information for a Home Control Center that feeds data from various sensors around the home that can then send the information via TV, SMS or your PC.

 

Cowjam.net

Arduino Projects

more work with LCD screens, very neat project on there that displays web hits on a screen taken from the web server via the Arduino.

 

Electronics-lab.com

Arduino blog/ showcase

A good site for various projects from around the web,not just focused on Arduino but a fair amount of content to be found here.

 

Gioblu.com

Articles / guides / projects / e-commerce

Italian ecommerce site with projects and guides. Really nice project for working with a scooter using Arduino to read sensor information.

 

Random Hacks of Boredom

Title says it all. Hacking anything that has electricity running through it and even some things that dont.

Nice set of Arduino how-tos with the Wii nunchuck but the best one on there so far is the GPS bus shelter, check it out.

 

Scottsstuff.net

Robotics

I built a basic robot, but this takes it a new level using the XBEE to communicate from the robot to the Arduino. I will definitely steal this information :)

 

Solder in the Veins

Electronics and programming for all

Good source of information for programming and electronics from around the web, projects not always Arduino but the inspiration is there – like a power outage alert system.

 

Time with Arduino

Learn. Think. Make.

Keeping time with Arduino in style, really nice clocks and watches with information on Wiseduino. Definitely worth checking out the Wiseduino kits.

 

Arduino – Redefining the TV Remote

TVRemotes

We use them every day, but has no one got bored of pressing buttons on a stick, it’s far too much effort pressing buttons! Surely there are better ways to control a device? After doing some work with my Nikon camera using IR to control it, I wanted to do the same with other devices. Check out the video at the bottom of this post…

However, unlike the Nikon remote, my Samsung TV remote has many many buttons so each IR sequence sent from the remote will be different. This can be a problem when you want to decode the signals, which while not impossible I am lazy, so thankfully Ken Shirriff has built a library to do just that and while its built for TV remotes you can decode an IR signal to its raw pulses using it. Essentially the library senses IR and notes each pulse and gap between pulses, Kens library saves a lot of time and its well coded – I’ll cover the basics of it in a bit.

My idea is to capture the IR sequences and then using the Arduino send them by using different inputs other than buttons. My first idea is to use my SRF05 distance sensor (You can use any distance sensor) and the premise being that different distances from the sensor send different signals to the TV. So rather than pressing a button you just wave your hand above the sensor. Of course this is slightly limited but since I only have 5 channels (yep – only 5!) so it turned out to be quite feasible.

There are drawbacks to this of course – the main one being that you can only define so many actions in the sensors dectection range. But there is plenty of range to do the basics, power, sound and channel and by constantly measuring distances we can even say the direction of movement, up to down and vice versa, can have an effect on what signal to send. For example moving your hand closer to the sensor will change the channel down.

So first of all you may want to read some of my other tutorials/projects concerning IR and the SRF-05 and Sharp IR (it should also work well).
Arduino Nikon IR Intervalometer Camera Remote
SRF-05
– contains handy wiring diagram!
Arduino and Sharp GP2Y0A02 Infrared distance sensor

(Other Arduino projects and tutorials)

OK, next take a look at Ken Shirrifs IR library and guide here:
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

Arduino TV Remote Components

Arduino
Breadboard
IR Diode
3pin (NPN) Phototransistor/ IR receiver (
Radio Shack 276-640 IR receiver, Panasonic PNA4602, Vishay TSOP4838 – or just get one out an old mouse)
SRF-05 (or any distance measuring device e.g. Sharp IR GP2Y0A02)
Jumper wires

Oh and stating the obvious but you’ll also need a T.V with working remote to steal the signals from – course you can use other remotes (stereos etc..)

The circuits themselves are very very easy to build, an IR LED to pin 3, a IR receiver to pin 11 and the SRF-05 I’ve plugged into pins 2 and 4. I have all of them in one breadboard and it works very well (see below).

Using Kens Arduino TV Remote Library

If you download the library and then unzip it to your Arduino/Libaries directory (older versions, I think its Arduino/hardware/libaries). The library assumes that your phototransistor/ IR receiver is on digital pin 11 and your IR diode is on digital pin 3. Typically you want a IR receiver with a 38Khz range – they seem to work best for me.

How to get our TV infrared/ remote codes

First of all use Ken’s IRrecvDump example (should be in your examples menu) load this into your Arduino and begin to capture your remotes codes. My Samsung wasn’t recognised so I used the Raw codes – there’s plenty of documentation on Ken’s site for this – it’s really simple, even I could figure it out. You need to note how many pulses etc.. it decodes in the raw signal which helpfully is outputted e.g. Raw (68):

Now we process the codes slightly and put them in an array for each one now that we have our codes and the information we need to use them – since mine are in the raw format I need to clean them up slightly ready to be put in my code – just adding commas etc…

Now we can test the remote codes to make sure you can control your TV

Now using the IRsendDemo example, altering it my case to send the raw signal, we can test the codes to make sure that we can control the T.V – just use the basic sketch to send the codes which I edited slightly just to use an array for the raw code. You can check out the library files themselves to see the functions.

/*
 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include 

IRsend irsend;

// just added my own array for the raw signal
unsigned int powerOn[68] = {4450,4500,550,1700,500,1750,500,1750,500,600,550,600,500,600,550,600,500,600,550,1700,550,1700,550,1700,500,600,550,600,500,600,550,600,500,650,500,600,550,1700,500,650,500,600,550,600,500,600,550,600,500,600,550,1700,550,600,500,1700,550,1700,550,1700,550,1700,500,1750,500,1750,500};

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

void loop() {

      // altered the code just to send/test my raw code
      irsend.sendRaw(powerOn,68,38);
      delay(100);

}

Add the distance sensor

This is actually the hardest bit and it’s not that hard really I just used my previous work and adapted it and wrote a few statements concerning the detected distance. You just have to spend some time debugging and getting your values right to ensure that your commands are only sent at the right time and that it doesn’t get confused. My code is still a little buggy if you’re not used to how to move your hand but it does work well once you’re used to it.

[ad#Google Ad in content]

/*
    http://luckylarry.co.uk
    Larrys alternative TV remote - oops no buttons!
    Sends signals to TV based upon sensor readings

    Makes use of Kens Shirriffs IRremote library
    An IR LED must be connected to Arduino PWM pin 3.
    Version 0.1 July, 2009
    Copyright 2009 Ken Shirriff
    http://arcfn.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .
*/

#include
IRsend irsend;

const int numReadings = 5;   // set a variable for the number of readings to take
int index = 0;                // the index of the current reading
int total = 0;                // the total of all readings
int average = 0;              // the average
int oldAverage = 0;           // the old average
int echoPin = 2;              // the SRF05's echo pin
int initPin = 4;              // the SRF05's init pin
unsigned long pulseTime = 0;  // variable for reading the pulse
unsigned long distance = 0;   // variable for storing distance

// setup my arrays for each signal I want to send
unsigned int powerOn[68] = {4450,4500,550,1700,500,1750,500,1750,500,600,550,600,500,600,550,600,500,600,550,1700,550,1700,550,1700,500,600,550,600,500,600,550,600,500,650,500,600,550,1700,500,650,500,600,550,600,500,600,550,600,500,600,550,1700,550,600,500,1700,550,1700,550,1700,550,1700,500,1750,500,1750,500};
unsigned int soundUp[68] = {4450,4500,550,1700,550,1700,500,1750,500,600,550,600,500,600,550,600,500,600,550,1700,550,1700,550,1700,500,650,500,600,550,600,500,600,550,600,500,1750,500,1700,550,1700,550,600,500,600,550,600,500,600,550,600,500,600,550,600,550,600,500,1700,550,1700,550,1700,550,1700,500,1750,500};
unsigned int soundDown[68] = {4400,4550,500,1750,500,1700,550,1700,550,600,500,600,550,600,500,600,550,600,500,1750,500,1750,500,1700,550,600,500,650,500,600,550,600,500,600,550,1700,550,1700,500,600,550,1700,550,600,500,600,550,600,500,600,550,600,500,600,550,1700,550,600,500,1750,500,1750,500,1700,550,1700,550};
unsigned int channelUp[68] = {4400,4550,500,1700,550,1700,550,1700,550,600,500,600,550,600,500,600,550,600,500,1750,500,1700,550,1700,550,600,500,600,550,600,500,650,500,600,550,600,500,1700,550,600,550,600,500,1700,550,600,500,650,500,600,550,1700,500,600,550,1700,550,1700,550,600,500,1700,550,1700,550,1700,550};
unsigned int channelDown[68] = {4450,4500,500,1750,500,1750,500,1700,550,600,500,650,500,600,550,600,500,600,550,1700,500,1750,500,1750,500,600,550,600,500,600,550,600,500,600,550,600,500,650,500,600,550,600,500,1700,550,600,500,650,500,600,500,1750,500,1750,500,1750,500,1700,550,600,500,1750,500,1750,500,1700,550};

void setup() {
  // make the init pin an output:
  pinMode(initPin, OUTPUT);
  // make the echo pin an input:
  pinMode(echoPin, INPUT);
  // initialize the serial port:
  Serial.begin(9600);
}

 void loop() {

    // loop for a number of readings on the SRF-05 to get an average to smooth the results. Much like all my other examples
    for (index = 0; index<=numReadings;index++) {
      digitalWrite(initPin, LOW);
      delayMicroseconds(50);
      digitalWrite(initPin, HIGH);
      delayMicroseconds(50);
      digitalWrite(initPin, LOW);
      pulseTime = pulseIn(echoPin, HIGH);
      distance = pulseTime/58;
      total = total + distance;
      delay(10);
   }
    // store the previous reading
    oldAverage = average;
    // store the current reading
    average = total/numReadings;
    // debug to check for spikes in the sensor etc..
    Serial.println(average);

    // now the fun part...
    // if my distance is less than 5...
    if (average <= 5) {
      Serial.println("Power Off");
      // use Kens IR library to send my signal (array, number of items in array, Khz)
      irsend.sendRaw(powerOn,68,38);
      // these delays depend on how long it take my device to recognise the signal sent and to act - I don't want to send signals that aren't getting read etc..
      delay(5000);
      // otherwise if my hand is higher
    } else {
      // check to see if my hand is in the registered space above the sensor
      if (average <=20 && average >=10 && oldAverage >=10) {
        // the below statement is our sensitive the readings are so if the current and previous readings are different with a tolerance of +/- 1 we can look at the direction of movement
        if ((average != oldAverage)
        && (average+1 != oldAverage)
        && (average-1 != oldAverage)) {
          // if the current reading is higher than the previous, then my hand is moving upwards
          if (average > oldAverage) {
            Serial.println("Channel Up");
            irsend.sendRaw(channelUp,68,38);
            delay(2000);
          } else {
            // otherwise if it is below then my hand is moving downwards
            if (average < oldAverage && oldAverage <=20) {               Serial.println("Channel Down");               irsend.sendRaw(channelDown,68,38);               delay(2000);                        }                  }          // otherwise my hand must be stationary so check where it is.         } else {           // if my hand is stationary between 10 and 15 cms away from the sensor           if (average >= 10 && average <=15) {             Serial.println("Sound down");             irsend.sendRaw(soundDown,68,38);           } else {             // if my hand is a bit higher up...             if (average >= 16 && average <=20) {               Serial.println("Sound up");               irsend.sendRaw(soundUp,68,38);             }           }         }         }     }        // clear our index and total for the next reading just in case     if (index >= numReadings)  {
      index = 0;
      total = 0;
    }
}

[ad#Google Ad in content]

Oracle: Delete all rows from all tables etc…

Quick method to do multiple actions across multiple tables.

Simply spool a script with your commands in for each table – this way you can avoid dropping your tables or user and still keep all your schema structure.

So for instance to delete all data from all tables you could do the following:

set heading off;
set feedback off;
spool C:my_file_name.sql
select 'delete from ' || tname ||';' from tab where tabtype = 'TABLE';
spool off;

This will produce an SQL file with a series of delete commands for each table and then you can just run this script which will delete all rows in all tables. The || is the shortcut for the concatenation function in Oracle and this basically works the same as a select script using Dual.

Tab like user_tables refers to a system table that describes the users tables in the schema. Tab has only a few columns and I’ve used this because it has the type of table as a column (just in case). You can see this for yourself by doing:

select * from tab;

And if you do:

select * from user_tables;

You’ll see the difference, user_tables contains alot more data about each table.

You can change the SQL command to ‘truncate table’ or whatever else you want – even drop all tables by querying user_tables instead of tab:

set heading off;
set feedback off;
spool C:my_file_name.sql
select 'drop table ' || table_name || 'cascade constraints;' from user_tables;
spool off;

Using this method you can do the same action across multiple tables and save it for later use.

Oracle: Update From equivalent

update statement

Quick note on how to update data in a series of joined tables using a subquery in the UPDATE statement in Oracle, kind of like the UPDATE FROM in SqlServer.

First of all check out the above diagram, I’ve stolen it from this link: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/update_statement.htm which also gives you more information on the UPDATE statement.

So what this says is that we can update on a table alias/subquery , which could contain our data set made from a  series of joins such as the code snippet below:

update (select
            tb5.stock_level
                                from
                                    schema1.table1 tb1,
                                    schema1.table2 tb2,
                                    schema1.table3 tb3,
                                    schema1.table4 tb4,
            schema2.table1 tb5
                                where
                                    tb1.id = tb2.id AND
                                    tb2.prod_id = tb3.prod_id AND
                                    tb3.sku_id = tb4.sku_id AND
                                    tb4.sku_id NOT IN (SELECT sku_id FROM schema1.table6) AND
            tb5.ref_id = tb4.sku_id AND
                                    tb1.country_iso_code = 'GB') mySubQuery
set mySubQuery.stock_level = 0

[ad#Google Ad in content]
Basically the same layout as doing subqueries with a SELECT statement, however, there are a few things to note. First of all if you use a SELECT DISTINCT in your subquery you’ll get an Oracle error ORA-01732 mentioning something about data manipulation not being legal for your table view. Next you may find that you get another error  ORA-01779 which is something about modifying a column which maps to a non key-preserved table.

While the above syntax is legal and you can get around the latter error, providing your constraints and foreign keys are declared on your database correctly, a better way to achieve updating records in a joined subquery is to use the WHERE IN clause on your UPDATE statement as below:

UPDATE schema2.table1
SET    schema2.table1.stock_level = 0
WHERE  schema2.table1.ref_id IN (select
            tb4.sku_id
                                from
                                    schema1.table1 tb1,
                                    schema1.table2 tb2,
                                    schema1.table3 tb3,
                                    schema1.table4 tb4,
            schema2.table1 tb5
                                where
                                    tb1.id = tb2.id AND
                                    tb2.prod_id = tb3.prod_id AND
                                    tb3.sku_id = tb4.sku_id AND
                                    tb4.sku_id NOT IN (SELECT sku_id FROM schema1.table6) AND
            tb5.ref_id = tb4.sku_id AND
                                    tb1.country_iso_code = 'GB')

Seems just as quick and works (0.14 seconds for 2000 updates out of a 50000+ across separate schemas). Also handy if you dont have access to fix the database constraints etc… (Or if you don’t know how).

Easy way to make Photo Canvas Box Frames

box frames

I like the idea of having canvas photo prints on the wall but I also have enough of an ego to think that I can take a photo good enough to warrant printing my own canvas. Also I think it’s a bit more personal too when it’s your own photo/ art.

I take alot of photos and never do anything with them, I always think about framing but to get the benefits you need to print big or do a series of panels, which is what I’ll be showing how to do along with a bit of printer/ photoshop advice. Just so you know Photoshop CS3 has some excellent tools for stitching photos together to make panoramas.

There are alot of shops that will print and box frame your photos on canvas for you and you can get canvas framing kits to help, so no worries if you don’t have a capable printer, it will probably just cost a bit more. I genuinely think anything over A3 you’ll want to pay to get printed anyway – because I doubt you’ll want to spend £1,000+ on an A2+ printer just to print one picture.

However, I am lucky enough to have worked for Epson so I own a Stylus Photo R1900. It’s fairly cheap I guess for what it can do but it’s limited to A3, so its just on the edge of the realm of large format printers. But doing your own framing is only cheap if you already have the printer – I doubt any decent shop will charge you more than £25 per A3 canvas print so don’t buy a printer specifically to do one print!

The right printer, media and ink

Whether using Epson printers or not to print canvas you need a decent printer and it’s all about the type of inks used, your average inkjet ink won’t stick to canvas and you need a printer that can also deal with thicker media and roll feeds. The R1900 can do that and it’s the cheapest one that you can get from Epson (around £400) – also look for the R1800, R2400 and R2880 as good ones to try. I would recommend the R800 but the smallest canvas roll you can get is A3 (13inches/ 330mm wide), there is a cheaper A3 one, the 1400 but don’t bother as its inks  (Claria) will just flake off canvas. Not sure about whats out there from Canon, HP etc… but I guess what I’m saying is check what your printer can do any decent manufacturer or shop should do you a test sample regardless.

Ok so you got the printer, now remember that I have worked for Epson, so please take what  I say as slightly biased and with a pinch of salt: Get the genuine Epson ink and media! (or the equivalent for your printer). You will honestly see the difference, in the case of the Epson stuff all the media is coated specifically for the inks and printer, so cheaper non-Epson paper/ canvas won’t work as well and you’ll see prints fade, smudge, chip off and blur – same for HP, Canon etc… If you use refills on these inkjets you’ll see the same kind of thing but you’ll also jam up your print heads – its the biggest cause of issues with the photo printers – that and continous ink feed systems. So if you use the shitty materials for this then expect the shitty results that’ll follow!

For the R1900 you’re talking about £95 for a full set of inks and £35-40 for the canvas roll. The £140 media outlay might seem high but this will let you do around 12 A3 panels, so works out about £10 per A3 panel with plenty of ink to spare to do other stuff, if like me you do A4 panels then I’ll easily get 20 on a roll – either way using this stuff is going to get you good results, even on auto settings. My only gripe with the R1900 is that it cains the inks so you have to be sure not to waste any prints – if I could, I would have the R2400/R2880.

Anyway so you get the idea: good printer, good media, good ink. Or just get your canvas printed by someone else – I’ll do it for you if you pay for the ink, media and postage!

Making the frames

Now you can spend some money and buy the wood, glue, tools etc… to make your own frames but you can get frames for around £2-3 for A4, maybe less (any good sources please let me know). Take a trip to your local wilkos, poundland etc… and find some existing box canvas prints (or cheap wooden photo frames). Check the dimensions to make sure your canvas will adequately cover the entire frame, the sides and some of the back for the best results, if you’re using a roll feed on the printer then the frame can be as long as you want just as long as the canvas can cover the frames width. I took a piece of canvas with me and a tape measure to ensure I got the best frames and odd looks from fellow consumers and store staff.

Pull out the canvas and staples

That’s it! Your frames are built – just strip off the existing canvas using some needle nose pliers and pull out the staples and you’ve got your frame ready in far less time and effort as constructing one yourself. Don’t worry about damaging the old canvas, chances are if you were cheap like me the picture on there was crap anyway.

3 A4 Frames for £9

Setting up to print your canvas
Whether or not you’re printing your canvas these instructions still apply. We need to create a template to help us print, crop and frame the canvas – please scroll down to the framing section to get an idea.

First measure up the width and height of the frame from edge to edge, now measure how thick  the frame is and finally measure the width of the wood used to make the frame.

For example my frame is 30 cm x 20cm, my frame thickness is 2cm and the width of each piece is 3cm. So my material needs to be at the very most 30cm x 40cm to get the best results. If you want to try and use as much canvas as possible for your print then just ensure that it covers the sides of the frame and around 1cm on the back to give you something to staple into and tension.

My printed area is going to be the area of the frame (30 x 20 cm) plus the sides, so that’s 34 x 24 cm.

For folding the canvas and getting a nice fit you’ll need to cut the corners off so make sure to add lines to your template. If you scroll down you’ll see why/ how this is done.

I used Photoshop CS3 to do my print templates but you should be able to  follow the steps and do this in any basic application that lets you draw a few guides and lines over a photo. I guess if you’ve got a decent photo printer then you’re using Photoshop – CS3 and onwards has a much better print interface.

Create a new document, from the measurements of the frame and make sure its at a minimum of 300 dpi resolution and use RGB colour.

Next show your rulers (CTRL + R) make sure you’re setup for mm or cm (Edit, menu then Preferences to change).

Drag guides to mark the sides of the frame.

Draw lines for cutting the corners off.

Create a white frame around the outside in a new layer – to save wasting ink on the material being stapled to the frame.

Now you can put your photo in this document for printing and it will be perfectly positioned for you. This works also if you’re doing multiple panels. I won’t go into colour correction here, I’ll assume that you’ve done all this.

Printing…

First to save wasting paper do a very small test print to make sure your print heads are aligned and nothing funky is happening in your images.

OK so we’re ready to print. You’ll need to first load the canvas roll typically at the back of the printer – this can be a pain to do as the printer won’t feed the roll unless its absolutely straight. To remedy this before clipping the canvas roll on the printer feed it first into the printer and press the roll button on your printer. It’s hit and miss but eventually it will take it, you just need to feed the paper in straight.

Now clip the roll on to the back of the printer and you’re ready to go. When printing you just need to set a few basic things, the media type (Watercolour paper – radiant white), to use the roll instead of sheet and to set the paper size to user defined (size of your document).

I always tick photo enhance and best photo options, also using the gloss optimiser. I leave the printer drivers to render the best colour conversion it can, generally few colours in my prints are out of the gamut. To get better results spend time playing with these setting but be prepared to waste some ink.

Click print and thats it. Once you’re done, press the roll feed button on the printer to feed the canvas out so you can cut it – the R1900 can attempt to cut the canvas but it’s  too thick. Once you’ve cut it (It only needs to be roughly straight) then press the roll feed button again to retract the leftover canvas ready for the next time – for doing panels I printed all of them and then cut the roll after the last print to save canvas.

3 panels printed

Framing your canvas

OK, you’ll need a staple gun with 6-10mm staples to do this. Its pretty easy to do and takes about 5-10 minutes per frame.

Cut off the corners

Remember the corner lines I added in my template first cut these off.

Mark the sides of the frame.

Now mark and measure in the depth of your frame on each side of your canvas, so on mine, I mark the edge at 2cm and at 22cm for example – you need these marks to make sure you get your frame in the right place.

Fold the canvas.

With the canvas face down fold back along the edge of the picture.

Staple the canvas to the frame

You should be able to line up the edges of your canvas with the frame, put in a staple to secure.

Pull the canvas tight, and staple the opposite side.

Fold the top

Tuck the corners in at the top and staple down, repeat at the bottom making sure to pull the canvas tight.

Finished stapling the frame

Finish off by stapling all sides down – can be as messy as you like, no one will see.

You should be left with a nice end result! :) Please feel free to ask if you need a hand or something explained – or if you want me to print your photos!

First box frame attempt