Showing posts with label Circuits. Show all posts
Showing posts with label Circuits. Show all posts

Tuesday, September 18, 2012

0 Arduino Project 6 - Inputting Analog Values into Arduino and mapping them to control different functions.

Hi people! So now enough with those simple boring LED projects. From now on I will not be posting any LED tutorials - at least not the simple ones! As is evident from the title, today I'll be showing you how to recieve an analog input from sources like a Light Dependent Resistor(LDR) and an Infrared Sensor.
First, let's start with a LDR. Wire up the circuit according to the pic given below.



All done? Let's start with the coding part. Basically what we want to do, is to define an input for the LDR, begin a serial connection(because that's what is used for getting output from the arduino), then print the values to the screen! So we'll do just that now!

int ldrPin = 1;

void setup()
{
Serial.begin(9600);      // Specifying the baud rate.
}

void loop ()
{
Serial.println(analogRead(ldrPin));  // telling the serial connection to print the values read from the pin
delay(1000);                                   // delay of 1 second
}

Done! Now upload the code to the board and start the serial monitor. You'll now see some values coming in from the arduino. Now put your hand over the LDR and the values reduce. You've just built your ambient light sensor! To get more resolution in the values just lower the value of the resistor. You can add an opamp too, but that is more complicated and I wouldn't dwell on it now.
So we will now create a simple code to turn on an LED the moment, the value of the LDR drops below a certain level. Connect the LED to the arduino as you would normally without letting the presence of LDR affect it. A resistor should be connected in series to the arduino. Let's add the code now. Since we are not using the serial communication, I have not included the code for that.


int ldrPin = 1;
int ledPin = 9;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop ()
{
int val = analogRead(ldrPin);     

if (val < 850 ) digitalWrite(ledPin, High);  // the moment ambient light level falls below 850, our LED will be
                                                               // turned on
else digitalWrite(ledPin, LOW);
}

Test it out. But if you think this is nice, then surely you'll find the next one better. In this project, we use the map function to control the brightness of the LED as a function of amount of light reaching the LDR. We only need to make a few changes to the last program.


int ldrPin = 1;
int ledPin = 9;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop ()
{
int val = analogRead(ldrPin);
val = constrain(val, 700, 900);                        
int ledLevel = map(val, 700, 900, 255, 0) ;

analogWrite(ledPin, ledLevel);
}

Great! Notice that I have added two new functions. The first one is for the constraint of values from the LDR. What it does is that it sets the values below 700 to 700 and values greater than 900 to 900. I'll tell you why I did that. The next function is the map function. Basically it just takes the inputs in and gives the output according to the limits set by you. In the above case the limits of the input are 700 and 900. So the function will give output between 255 and 0. Since we need an inverse relation( the led should glow when light is low!) we specify 255 first, rather than 0. But what happens if the input value is less than 700? Well, that is exactly what the constrain function is used for. To prevent the arduino from returning garbage values, we have constrained the input.
Congrats !! You just made a nightlight! No longer do you have to be afraid of monsters under your bed or in your closet! Naturally, you can use other inputs like thermistors, range finders to give analog values.
So you think this was good?! No just wait till you see the next one!
To wrap up the post, I will make an emergency light system using an LDR and an IR range sensor as inputs. In this case, the LED turn on only if movement is detected. Just hook up the LDR like in the first project and then the IR module. The IR module has three wires, the signal(yellow), power(red) and ground(black). Plug the red wire in the +5V jack, black in GND, and yellow in any analog pin, say 4.
Let's see the code now.




// Define the pins
int irPin = 4;
int ldrPin = 1;
int ledPin = 9;

// Create Variables to keep track of distance
int prevDist = 0;
int currentDist = 0;

//Set the threshold for movment
int thresh = 100;

void setup()
{
pinMode (ledPin, OUTPUT);
}

void loop()
{
int ldrval = analogRead(ldrPin);
int currentDist = analogRead(irPin);

//Check for movement
if (currentDist == prevDist + thresh || currentDist == prevDist - thresh && ldrval < 850)
{
digitalWrite(ledPin, HIGH);
delay(10000);
}
else
{
digitalWrite(ledPin, LOW);
}
// Set the values to original
prevDist=0;
currentDist=0;
}

Thanks for reading my tutorial! Hope I left you brainier than before! I think I will do something on motors in my next post! Keep reading!
Godspeed! Cheers!

Saturday, June 2, 2012

1 How to Make Your Own PCB

Well you might be asking what is the use of making your own PCBs when you get readymade circuits in the market? The obvious answer would be to save a few bucks, but no, there is more. Making PCBs yourself lets you understand the internal workings of the circuit in a way that no teacher or self learner can match. And yes you can save as much as 50% of the cost! You make lots of stuff and attach it to some circuitry, then you won't take out the part till something breaks. You cant go out and keep on buying those expensive premade circuits every time you need one, it's just impractical. So what you do? You make PCBs at home at half the cost, all the while learning the working of that particular circuit and still having fun! And that's exactly what i'm gonna show you today.

Parts List

  • Copper Clad Fibre Glass board (Ask for PCB board). You will usually get this in your local electronics store.
  • An Abrasive Pack
  • Black Laser Printer ( Dont worry if you don't have it, you can print your PCB design on any paper and get it photocopied)
  • Glossy Magazine Paper, or press and peel paper
  • Acetone
  • An Iron Box
  • Etchant like FeCl3 solution or a mixture of Muriatic acid and Hydrogen Peroxide
  • Etchant Container - Any plastic or glass container. Do NOT use a metal container, the etchant will eat through it.
  • Rubber Gloves. You don't want to burn your hands, now do you?
  • Drill. Preferably a drill press, but a hand drill will do, though it will reduce the accuracy (you may end up drilling just out of the designated circle and render the whole PCB useless.
  • Micro Drill bits for drilling the micro holes.
  • Paper Napkins
Now that you have the parts laid out, we dwelve into the actual designing of the circuit. Before the copper board can be etched, we have to have a functioning design. There are many open-source programs that let you design the circuits, but the best I could find and the one I would recommend is the Eagle PCB designer from CADsoft. It can be found at the CADsoft Website and has versions for Windows, Linux, and Mac users. The functionality of the freeware version is only limited by the size it lets you design ( 4 X 3.2 inches )
an enormous number of useful circuits can be built using that size only.

The Procedure 

So now you have got the reference design? Good!
  • Start by printing a design on a glossy paper or a press and peel paper with a laser printer.
  • Put the paper on the board and set the position.
  • Put the centre part of the iron on the paper and hold still, strictly no rubbing.
  • After 5 mins, lift the iron and put another piece of paper between the iron and the paper on the board. Keep the iron on it, hold it from one corner and slowly move the iron all over the board.
  • Let the board cool for 10 minutes and then dip it in warm water, add some soap. Keep it in for 15 mins.
  • Take the board out lightly rub the board (do NOT scratch) to remove the paper completely.
  • You should have the design on the board. If there are any places where the toner did not transfer completely, manually fill them in with a permanent marker pen. But if there are any major defects, then you might have to repeat the whole process again. (You can scratch the toner off and reuse the copper clad board.
  • Now take the etchant you have and pour it in a container. ( If you have muriatic acid and hydrogen peroxide mix them in the ratio of 1:2). And be sure to wear your rubber gloves.
  • Dip the copper clad into the etchant and keep agitating it with a glass rod or a plastic use and throw spoon.
  • After 2-3 minutes, take the PCB out and see whether the copper without the toner has gone or not. If  not, then dip the PCB in for some more time.
  • After you are done with the etching, pour the etchant into a large bucket of water and pour the water into the drain. It is very important that you use a large bucket of water. Keep your face away while pouring and pour a thin stream of the etchant, not the whole container at once.
  • Now give your attention to the PCB. Soak a little acetone in the paper towel, and gently rub the PCB to remove the toner.
  • The PCB is now ready!
I will keep posting the schematics for a variety of useful circuits. For a starter take these sch and brd files for making the BJT H-bridge. You can find out the parts list from the schematic view and view the board design from brd file.

Thursday, May 31, 2012

0 Making An H-Bridge Motor Driver

Need of an H-bridge

When driving the motor in only one direction, we only need an on/off switch. But in most of robotics applications, we need to reverse the motion of the motor many a times. This is accomplished by what is called an a Half-Bridge or a push/pull driver.

Circuitry of the H-bridge

2 Switch Bridge

The simplest of the H-bridge uses two switches, which provide a path to either the positive terminal or the negative terminal, due to which the motor is able to turn in either directions. By using only one of the switches at a time, a short circuit is avoided. The other terminal of the motor is permanently connected to the GND.(Ground 0V). If both the terminals of the motor are connected to the positive or negative supply, we obtain a condition known as an Electric Brake.

4 Switch H-Bridge

For the motor to spin, the battery current must flow from the Positive supply, through the Motor,
and to the Ground supply to complete the circuit. To make this happen we must open one switch from each side of the bridge, one Low-side and an opposite High-side—that means we can either turn on S1 and S4 to go Forward, or we can turn on S2 and S3 to go in Reverse. The direction of the current flow through the motor terminals determines the direction that the motor spins. We can manipulate the flow of the current by closing the two corresponding switches together to give us directional control of the motor. If all four switches are open (disconnected), the motor is coasting, meaning there is no path for the current to travel.

Full Bridge Configurations

Shoot Through Configurations ( NOT okay!)

Implementation

The Simplest of all H-bridges


We can make a full H-bridge using 2 three-way (SPDT) switches, a DC motor, and a 9v battery. It can be placed into any acceptable H-bridge state: forward, reverse, electric brake (positive), electric brake (negative), or neutral. Each switch in the circuit has three positions, On/Off/On, and switches the center contact between the two outer contacts (or in this case, the positive and negative battery wires). This method shows the simplicity of a basic H-bridge circuit, but does not provide speed control (it is either on or off). Although this might be a rugged circuit, its use is limited, so it is usually only good for testing and educational purposes.

DPDT (Double pole double throw) Relay H-Bridge

Here we combine the two SPDT switches and use one DPDT Relay, so it can be controlled by the Arduino. Also we can use the Arduino or PICAXE to provide a simple PWM signal for speed control of the motor. The simplest way to do this is to add a Logic-level N-channel mosfet (or several in parallel) to control the entire circuit’s path to ground. By using a PWM signal on the Ground supply to the H-bridge (Relay), we can control the speed of the motor from 0– 100%, whereas the relay switches the motor’s direction. The relay acts as both the High-side and Lowside switches in the bridge, so there are actually two low-side switches in this configuration—the relay used to route the power terminals and the N-channel mosfet used to provide the PWM speed control. This provides complete 0–100% speed control and requires as few as four parts other than the relay: (2) logic level N-channel mosfets, (1) diode (for relay coil), and (1) small prototyping PCB (or you can make your own). Depending on the mosfet, you can expect to carry about 10 amperes at 24vdc with no heatsink or fan; I usually select power mosfets with the highest amperage rating (anything above 75 amps), higher voltage rating than I plan to use in the project (usually 30v–55v is good), and the lowest possible on-state resistance. We can build this circuit with (2) FQP50N06L N-channel mosfets. One mosfet is needed to provide PWM speed control, and the other mosfet is needed to interface the relay coil to the
Arduino for direction control.The relay mosfet can be controlled by any Arduino digital output pin, whereas the speed control mosfet should be controlled by an Arduino PWM output. Next we connect the mosfet Drain pin to the Relay as shown in Figure 3-14, and the mosfet Source pin to the main Ground supply. The prototyping PCB makes this easier to put together and you can add screw-terminals for easy wiring. The voltage and current limits of this circuit are dependent on the mosfet and relay ratings, giving this circuit potential despite using a mechanical relay switch.
The Code for this bridge will be given later.
And don't worry if you do not get this right away! Take your time. You can also build the circuit, and then understand its functioning. 

H-Bridge ICs

To build your own H-bridge, but leave the designing to a professional, you might be interested in an Hbridge
IC. An H-bridge IC is a complete H-bridge circuit that is contained on a tiny integrated circuit
chip. These are usually fitted into a circuit with very few extra components, typically only a few resistors
and a regulated power supply for the logic controls. When using an H-bridge IC, you can usually expect
shoot-through protection, thermal overload protection, and high frequency capabilities. Although these
H-bridge chips are far less likely to be destroyed by user error than a completely homemade design, they
also have much lower power ratings than a homemade H-bridge, typically under 3amps of continuous
current. There are several H-bridge IC chips that include all four switches and a method of controlling them
safely. The L293D is a Dual H-bridge IC that can handle up to 36 volts and 600 milliamp per motor. The
L298N is a larger version of the L293D that can handle up to 2amps (see Figure 3-16). There are a few ICs that can control up to 25amps, but they are expensive and hard to find. There are several H-bridge ICs
that work for some of the smaller projects i will post(hopefully), but the larger bots require a higher powered H-bridge capable of conducting 10amps or more.

Wednesday, May 30, 2012

0 Automatic Night Light

This circuit is one of the simplest to build considering the fact that it requires no microprocessors at all! It dims in the light and brightens in the dark.

Parts required :

  •  D1—1N400X diode
  •  P1—100 k ohm potentiometer
  •  R1—22 k ohm
  •  R2—470 ohm
  •  LDR—1 M- ohm dark
  •  Q1—NPN transistor 3904
  •  LEDs—5 mm round

Procedure :



  • Connect the parts together according to the schematic on a breadboard.
  • Set the circuit so that the LDR (Light Dependent Resistor) recieves a fairly good amount of light. 
  • Now turn the potentiometer so that the LEDs are barely off, take the circuit under a dim light and turn the pot again so that the LEDs are barely off.
  • Any further reduction in the light will turn your LEDs on.

Working :

The current from V+ has two paths to go to the lower potential. Naturally it will chose the easiest path, or the path of least resistance. When the circuit is under bright light, the LDR will have very low resistance, so all the current will pass through the LDR thereby preventing the LEDs from lighting up.(They have no current). As the light begins to dim, the resistance of the LDR keeps rising (Just like you getting angrier when you get no food!). And as the resistance rises the current must find an easier path. Just at the moment when the resistance through both the paths become equal, the current begins travelling through the transistor thereby lighting the LEDs (much to your joy)!

Your Automated Night Light is ready!

Tuesday, May 29, 2012

0 How to use a Solderless Bread Board

As the name implies, a solderless breadboard doesn’t require any soldering. Wires and components are simply pushed into holes on the board to connect them together. No mess; no fuss. You can us the holes, wires, and components over and over again.Technically, the holes in a breadboard are called tie points. When a wire is pushed into a hole, it makes contact with a solid metal strip underneath. When another wire is pushed into a hole on the same strip, the wires are connected. The metal strip acts as a connecting pipe that allows electricity to flow from one wire to the other.

Various Features are:

5-Position Group
5 Position Group
Centre Gap
Most of the holes on the breadboard are physically connected in groups of five. Any and all wires pushed into the five holes are electrically connected to each other.However, if you want to, you can connect 5-position groups together. Simply push each end of a single wire into a hole in each group. This wire is now connecting together the two metal strips underneath. Anything connected to one strip is now also connected to the other.
Centre Gap
There’s a gap in the center of the board. A wire in one 5-position group is not connected to a wire in a 5-position group across the gap.
25 Position Distribution Bus
The two horizontal rows of holes at the top and bottom of the breadboard are called distribution buses. Although they appear to be horizontal groups of five, they are actually connected underneath to a metal strip that is much longer, 25 holes.There’s a good reason why there are two rows of distribution buses at both the top and bottom of the board: Many parts in the circuit need nearby access to power. You can connect one of the bus rows to the positive end of the battery and the other bus row to the negative end of the battery. Now all the parts have convenient power access.





 

The Engineer's Spot! Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates