Friday, October 31, 2014

Getting your PCB done from A to Z

PCB or printed circuit board is a major step up from the veroboard for DIY hackers. I learnt about PCBs or PCB printing during my final year project as I realised that dangling wires, ugly solders points and loose parts would be a pain. So I produced a lot of sub par PCBs before finally getting to really good ones. In this post, I want to have you skip this steep learning curve and jump right to a good work. That explains why this week's post is so long.
Okay, let's first compare veros and PCBs. Figure 2 shows a veroboard which housed a microcontroller, a 5V regulator and a few pin outs. Figure 1 is exactly the same circuit, but on a PCB. The gap in terms of quality and neatness is blatant.


                                                      Figure 1: PCB version Print Layer


Figure 2: Vero version 

Okay, so in this post I want to have you build your own PCB. Now, I've been thinking hard on what circuit to work with. I looked at the 555 flasher, 555 timer and I realised it would be great to work with a much more useful circuit(no disrespect to the living legend that is the 555). So, my very first post was about regulating a 3s lipo(about 12V) to 5V without having to bother about heat sinking issues. Well, this is the circuit that we'll be laying down on PCB. I think it is a extremely useful circuit that will come in handy. If you want a neat design to shift a 3s Lipo or even Car battery voltage to 5V,we've got a deal.
So where to start in any PCB project, make sure you get your circuit diagram right. Figure 3 gives the circuit diagram for our regulator.

Figure 3: Circuit diagram

Now, I've tested this circuit and it works. Everytime you come up with your circuit diagram, make sure you just test it on the good old breadboard(fig 3a). I know its a pain and you are probably in a hurry but it's important that the circuit works before going to PCB printing. 


Figure 3a: Bingo 1 - The LED is on

Here's a video demo of the circuit at work:

      

Bingo 2 - We have 5V


Okay. For this circuit, we'll be need the following components:

1. MC34063 - Switching regulator
Now I've not seen this in mauritius but I've got quite a pile of them lying around. Just get in touch and I'll get you one.


Figure 3: The switching regulator

2. A 180uH inductor. Actaully, you could even use a 200uH. I've done the maths and it does not differ much. Now, be careful with this one. At a local electronics store, I ended up with a capacitance! So here how it should look like.



Figure 4: The inductor

3. A 0.33 ohm resistor. Figure 5 shows how it looks like. Well, there are variants ;)


Figure 5: The 0.33 ohm resistor

4. Capacitors.
   - One non polarized 470pF cap
   - One polarized 47uF cap
   - One polarized 100uF cap

5. Resistors(1/2W to be safe)
  - One 1kohm resistor
  - One 3kohm resistor 

6. One fast switching schottky diode 1N5819. Now, here I got the 1N5822. It's huge! But it does the job :)

7. Two 2 port screw terminal, shown in Figure 6.


Figure 6: 2 port screw terminal

8. 8 pin IC socket

Okay, now that we've got the parts, its time for PCB design. So it's time to transpose our circuit to PCB. How do we do that? A software. Now, I've been using Pad2Pad. It's a fantastic little CAD program that offers a powerful interface and great simplicity. You'll pick it up in no time!
(Disclaimer: Pad2pad belongs to its respective owner. Snapshots used are not meant as copyright infringement and are used only for educational purposes)
So, once you have the software installed, time to move to design. Now, open up pad2pad.
Figure 7 shows the startscreen. Just click 'OK'.



Figure 7: Pad2Pad startscreen

Next, you'll be ending up with a black screen with grids as shown in figure 8.



Figure 8: Screen 2

Now, for this project(and most porjects actually!), we'll be using only two tools. The pad tool and the trace tool. They are shown in figure 9. The rectangle profile(blue) represents the limits of our PCB.  Don't worry about that for now. We'll tweak it later.


Figure 9: The tools

Before moving to design, we need to tweak the thickness of the pads and the thickness of the lines. The pads are where you'll be drilling holes for your components. The lines are actually connections. So, set the pads diameter to 1.91mm. Click on the pad tab. Then move to the top right. You'll find something like 1.00mm. Scroll down and select 1.91mm. 


Figure 10: Setting Pad diameter

Similarly your are going to change trace width to 0.64mm. This is shown in Figure 11.


Figure 11: Setting trace width

Okay, simple stuff first. Try to replicate figure 12. You are going to breeze through this. Simple drag drop stuff.


Figure 12: Getting started

Pretty easy! Next up, our voltage regulation circuit. It's given in figure 13. You'll notice the holes are different.We are using the padded hole option. Why? Drilling would be less tedious.


Figure 13: The final layout

Now, this may look daunting, but you'll get it right! Okay, once you've done this, you have to print it. ALWAYS make sure to select MIRROR when you print(Fig 14). Otherwise, you'd be getting a circuit that is reflected.

Figure 14: Printing it right

Finally, you'll be ending up with something like this.


Figure 15: Print out

As you see, its inverted or reflected. Now, the next thing to do is to get the PCB printed. Now, I'm scared of chemicals. I was horrible at chemistry experiments. So, I stay away from those stuff. What you can do if you have the same issues is to take your printed sheet to local electronics store that do PCB printing.
When you get there, there is only one thing to say - "This is the solder side". That will do the trick. It will probably take a day or two. Around Rs 75 is what I paid. From what I observed, it's based on the size on the PCB.
Now, you'll notice I did not inscribe the components on the PCB. I didn't because it does not look good on the finished PCB.
So, fast forward a few days later and you have got your PCB. Figure 16 shows mine. The borders may not look perfect but please be careful if you attempt to cut it. The dust is hazardous.


Figure 16: The PCB

Time for some soldering! Now, there is a very old feud between me and soldering irons. I've had 4 or 5 of the cheap ones and they kept overheating. Finally, I found the one. Never failed me. Behold the Stanley(Figure 17). If you have no background in soldering, I'm planning to have a complete soldering tutorial in 2 weeks(Friday 14 November).



Figure 17: "The" Stanley
Okay, when you look at that PCB, it's pretty difficult to know what goes where since there are no labels. Here are the labels. 


Figure 18: Labels

This is how the PCB would look it were transparent.
Finally, your populated PCB should look like that. 


Figure 19: Populated PCB

I replaced some of the resistors which were not available. You may have to enlarge some of the drilled holes. That's it.
Next week, how to control your arduino from your phone via bluetooth!

Friday, October 24, 2014

On temperature sensors

Temperature sensors! We've all at some point played with one of those. Be it that water temperature sensing application or the thermostat in a car. There are several types of sensors and going through all those data sheets would reveal that there are disparities between them. In this post, I'll try to present some sensors based on stuff I've seen.

1. The Analog sensor or thermostat or thermistor
Okay, this is the one. I'm pretty sure all DIY hackers have seen this one. A thermistor is basically a resistor whose resistance varies with temperature. Just like the LDR's resistance varies with light incident on it. So what does it look like?
Figure 1 shows basic thermistors. Those two are identical except for their temperature ratings. When you ask for a thermistor at the electronic shop, this is what you'll most likely end up with.


Figure 1: The basic thermistor

Sometimes, you'll be working on a project where you'll be measuring the temperature of a liquid(maybe water). The water proof thermistor is what you might be using. It is shown in figure 2.


Figure 2: Waterproof thermistor(right)

So is it any good? I think that if 
1) You need a simple temp sensing solution. This is for you.
2) You have tons of analog ports on your microcontroller. This is for you.
3) You are not bothered with a great deal of accuracy. This is for you.
4) You are looking for a very cheap solution(Less than Rs 50 in mauritius). This is for you.

So, simplicity and low cost are the key words here. So how to make that work? This is a variable resistor and so to get something coherent out of it, we fall back to our good old voltage divider circuit. Figure 3 gives a brief recap.



Figure 3: Voltage divider recap(Quality is top class, I know :p)

So, A gives a basic voltage divider circuit. To keep it simple, if you have a closed circuit with a DC source and two resistors, the voltage is going to be divided at some points. For instance, at Vo, the voltage is given by equation B. Now, suppose you take R1 and replace it with a variable resistance(for instance, the thermistor) - if temperature changes, Vo will change. That's it for the maths.
C gives how you should set the circuit up if you are using a microcontroller. Usually, if your thermistor is rated 10k, R should be 10k. And then it's quite easy to convert the analog data to some coherent temperature value. If you really dig up stuff, you are gonna be facing terms like NTC, PTC. But if you don't really want to bother yourself with the maths, here you go. If you're using the UNO(or Pro or Mega), 1024 is the highest analog reading you are ever going to read. So, lets call the analog reading you are getting TEMPRAW. Also, lets say Rt is thermistor resistance and R is the value of the fixed resistor. Figure 4 gives the relevant equations.


Figure 5: Thermistor equations

So that's it, a very simple means of getting temperature data. Next up, the analog temperature sensor.

2. TMP36 -Analog temperature sensor
Okay, I have a bit of a personal history with the TMP 36. I never managed to get a working one - I think it's just bad luck :/ . So, how does it look like? It's very similar to a transistor and it's extremely easy to use. And if you are looking for a quick upgrade in terms of accuracy over the thermistor, you have a deal. This beautiful piece of electronics offers an accuracy of 0.1 degrees celcius. Figure 6 gives you info on pinouts and how to set it up. 


Figure 6: Art ain't in me

Now that you have Vo fed to your analog pin, the conversion step is much easier than for a thermistor. The TMP36 has a sensitivity of 20mV/degrees C. This implies that for every degree celcius change, you are getting 20mV. Now, you'll be reading stuff from 0 to 1023. To get voltage from this value, you'll have take this value, multiply it by 5000(assuming you are using 5V) and divide it by 1024. To get a degrees C reading, take the voltage, substract 500 and divide by 10.
Next up, a personal favorite, the DS18B20.

3. Digital temperature sensor, DS18B20

I came across the DS18B20 because I had run out of analog pins for a project. It is a wonderful sensor in terms of functionality.It saves you the precious analog pins and that makes it stand out. The downside of this sensor is the sheer complexity of getting a reading out of it. So complex it is that people have produced libraries for it. So if you want this sensor, the onewire.h library is essential.
Another issue you might be facing is conversion time. The resolution of this thing is adjustable from 9 bit to 12 bits. At 12 bits, conversion time is 750ms. 750ms! In real time applications, you are going to get in trouble with this. I set it up for 9 bits and this reduces conversion time to just 93.7ms. A more acceptable value. So I did not find software to do that. I tweaked the existing code a little bit and it just worked. You might want to dig in the datasheet for that one.

Next week - PCB printing in Mauritius!