Wednesday, 20 May 2015

Constant current LED driver


LEDs have become ubiquitous these days you can find them in different roles like being used as indicators, home and office lightning solutions, in music synced lightening systems at clubs, signboards  etc. Today i will share about a constant current driving circuitry to make some LEDs glow with DC power sources.

Why do we need a driver circuit?

The first thing that might come to your mind is why do we need a driver circuit when you can just simply connect a coin cell battery to make an LED glow and  for higher voltage sources you can easily drop the voltage to desired value by using a resistor.
The use of a dedicated circuit is necessary because using the above mentioned method won’t provide a consistent and robust solution. The current through the LED is sensitive to even small changes in voltage across the LED and the temperature of LED so using the above mentioned way may provide different LED performance in different environmental conditions. The inefficiency using a resistor to drop the voltage would even be magnified while driving a high wattage LED.

Constant current LED circuit built around IRFZ44

The circuit below shows a reliable way of lighting an LED. This circuit allows us to decide a particular value of current that will flow through the LED by adjusting the value of R2 resistor.Depending upon how much current is allowed to pass through the LED the intensity of LED is adjusted.



How does the Circuit works and deciding the values of  current setting resistance?

when the value of current flowing through the LED to the R2 becomes high enough to provide a drop of 0.7 V across the base emitter junction of the transistor the diode gets turned on and the extra current goes to ground through the diode. This feedback mechanism leads to a constant current flowing through the LED.

Deciding the value of  R2
Value of current through the LED = 0.5/R2
value of power dissipated across =0.25/R2
R1 hould be a high value quater watt resistance say 100k.

Benefits of using this circuit
  • consistent LED performance over large range of supply voltage
  • low dropout ie the output voltage can be just 0.6 volt higher than the input voltage
  • cheap circuit
Important Points

  • Because the transistor T1 is thermal sensitive the current set point is also thermal sensitive so choosing a transistor with low thermal senstivity will give more accurate results like 2N5088BU
  • Care should be taken that the power dissipated by Q1 is within the range specified in data sheet power = voltage across Q1 x current through the LED
  • For maximum efficiency the LED should be configured such that the voltage is near the supply voltage.









Monday, 18 May 2015

The Journey of Electronic Products from idea to customer's hand


It require interdisciplinary expertise to bring an idea from concept to life. There is a need to bring people with background as diverse intellectual background like manufacturing,design,core electronics, management   together and work together. To survive in today's competitive market you have to give a feature rich product to your customer and that too at lowest possible price. In today's era of globalisation the markets are now open for everyone and while this leads to opportunity to serve more customers it also poses the difficulty of surviving the competitive market. One of the strategy that the companies adopt is to accomplish different parts like say the software from firms in India and for manufacturing needs get the job done in china and this way the price of the final product comes down.
Below is a block diagram representation of Product design cycle:


The process starts with an IDEA that may be a completely new product idea or an improvement or enhancement to the existing idea. After this a comprehensive research is carried out to determine the feasibility of the idea and decisions like which existing technology is to be used out of the pool of technologies is made. Sometimes a product is practically feasibly by one technology and is not with another or out of the two technology one provides same performance but cheaper final product so every care should be taken during this phase because this is going to be the basis of product performance.
Once the research phase is over and you come out with a circuit that you are going to use to implement the feature  the prototyping is done,you take into account the erogonomics of the products and refine the look and feel of the product and then multiple design reviews are done to make sure everything is working as it should be,once the performance of product is satisfactory here, the next step is to analyse the manufacturing capabilities and things like what processes needs to be outsources what can be one in-house are decided,then documentation is created these includes the documents supplied to the user as user guides and the directions and information to be provided to the customer support people. 
Agency compliance ensure that the company followed all the rules and regulation like the environmental regulations and safety measures are taken. Agency compliance is another major step and sometimes it pose to be a hurdle and cause of delay of product release  one very recent example that i came across is the delay in the release of  official touch screen for raspberry pi due to the compliance.  There are FCC agency compliance for America and CE for the European countries and you need to have a compliance certificate to sell your product in these countries. 

After all this you bring the product to market, and right marketing of the product is very important these days. If you look around yourself you will easily find many examples of some innovative and out of the box marketing strategies that the companies are adopting.  There is great craze among people for some products like a new iphone launch and samsung's galaxyS4 . People stand in queue for whole night to get hold of the first phone. Samsung   introduced the concept of virtual queue when it launched the S4 where the customers were turned into marketers. Rather than physically standing in queue to get the phone an on-line queue was made and the more you tweet and comment about the product the more you will move ahead in the queue. 

Finally after the product is sold you need to give good customer service so that you make sure the customer is happy with your product. 






Creative Commons Licence
The Journey of Electronic Products from idea to customer's hand by Deepankar Maithani is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Saturday, 9 May 2015

Arduino Tips & Tricks

Interfacing Gas Sensors with Arduino

Gas sensors commonly available in the market are the MQ series gas sensors. Different sensors in this series have different target gases for detection.But they all have more or less same structure and parts.Every gas sensor has a  heating coil and a surface with coating of some compound which is sensitive to the presence of a target gas.
Below is the picture depicting the structure of  MQ-2 which is a combustible gas sensor.


 These sensors require a 5V supply to power the heating coil .Since there is no electronic circuit inside them they can also be powered up using the AC.  These sensors can draw current upto 130 to 150 mA so these shouldnot be powerd using the Arduino. In case of the MQ-2 the sensitive material used in detection is Tinoxide. Mq2 is sensitive to LPG propane and Hydrogen.Below is a table with different gas sensors and their target gas.


CONNECTIONS WITH ARDUINO

As always now we will interface the sensor with the arduino Uno. The picture below shows the pins and how to connect it.
The polarity is not important in this sensor connect any one of the H pin to ground and the other one to the VCC. 
The MQ-2 sensor is not breadboard friendly,also it is difficult to solder wire directly on pins,I have designed a board on eagle to ease this out. I have also incorporated a LM35 temperature sensor.If you want to read out it interfacing you can read my previous post here



You can find the design files and gerbers on my github repository here Board,Gerbers. As always free to use and remix

SOURCE CODE:
float temp;
int gas;
int tempPin = A0;
int gasPin=A1;

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

void loop()
{
  temp = analogRead(tempPin);
  gas=analogRead(gasPin);
  temp = temp * 0.48828;
  Serial.print("Temperature=")
  Serial.print(temp);
  Serial.print(',');
  Serial.print("Gas Sensor output")// 
  Serial.print(gas);// Stable readings comeout after 2 3 minutes
  delay(1000);
}

CALIBRATION:

The real challenge in dealing with the Gas sensors is the calibration,if you just want to use the gas sensor to know between high concentration of gas and low concentration  and then do something based on this ,for this much whatever we have seen so far is sufficient enough. But when you precisely want to know that what ppm of gas is there it is very important to correctly calibrate the sensor. For MQ2 it is recommended to expose the sensor to know value of target gas say 1000ppm and then observe the output and then with this data an algorithm is made to calculate the exact concentration of gas. But the problem is how to create an environment with known value of a gas. This would require a Lab with all the necessary equipments.
There are other factors that may also impact the sensor reading like humidity and temperature. Also there is a concept of burn in time which says that the sensor should be made to run for  of 18 to 24 hours after which it starts giving reliable readings. 

Quick Tip: In case you make the ADC to work with external reference or internal reference of 1.1 you might need to reduce the value of load resistance.Thats why i have kept a potentiometer in my hardware design so that it can be tweaked as needed.




Wednesday, 6 May 2015

Arduino Tips & Tricks

Understanding Sensing & Interfacing Temperature Sensor with Arduino.

Sensors are very important part of electronic systems. A sensor is a transducer whose purpose is to sense /detect some  some characteristics of its surroundings and provide a suitable corresponding output in the form of  electrical signal.
Example: Blood Sugar Detection Machine
There is a commonly available blood glucose measurement machine which is used by the patients. For measuring the blood sugar first you  prick the skin and put it on the strip that comes with the machine,there is a protein on  the strip which when  comes in contact with the blood sugar produces electrons and hence a voltage is created which is then read by the machine,the machine is pre calibrated to give a corresponding reading. 
Different sensors may have different ways of sensing a same characteristic. In a general  in any sensing device we make use of change in inductance,capacitance or resistance to get the desired output,however the technology used in the sensor affects some important features of a sensor like response time,accuracy,repeatability,lifetime. Power consumption is another important factor that needs to be taken care of while selecting a sensor,because lesser power consumption will give more up time.
ADC
When we talk about the sensors the next thing without which we cannot live are the ADC. These convert the analog voltage into digital voltage. There are many types of ADC available  like Counter type ADC,Parallel comparator type ADC(this is the fastest ),Successive approximation type ADC, Dual slope integrated type ADC. Each one of above have its pros and cons. The atmega328P on the arduino have a 10bit sussesive approximation type ADC. I am not going to go into the details of how it works,you can go here  if you want to read more.

CALIBRATION
This is the next buzz word you will here while dealing with the sensors,right calibration of sensor is very important for accurate measurement,different sensors  may require different ways for calibration,some sensors also come precalibrated.
 As a hobbiest it might not be super critical thing and we can do away with it at times  but on more important areas and in serious implementations like in bio medical instrumentation (like the example above)it is very important to have right calibration. 

HANDS ON 
Interfacing LM35
LM35 has a measurement range of -55*c to 150 *c. It is commonly available sensor that you can find for a price range between 35 to 45 INR. Below is a picture with its pin description.


STEP 1:
Connect the sensor to arduino as below.


STEP 2:
writing the software:
we have to read the analog value at the pin A5 of the arduino and the multiply it with a magic number
int val;
int tempPin = A5;
float reading,temperature
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  val = analogRead(tempPin);
  reading= (val*4.88)
  temperature= reading/10;
  Serial.print("TEMPRATURE = ");
  Serial.print(temperature);
  delay(1000);

}
The magic is in these two lines below but where did these lines come from? Lets understand
  reading= (val*4.88)
  temperature= reading/10;
The ADC on the arduino gets a 5v as reference if you dont change it 
First thing we have done here is we have calculated the step size
Stepsize= Vref/2^n     n=no of bits  here we have a 10bit ADC on arduino.
stepsize= 5/1024 =0.0048828 = 4.88mV

from data sheet of LM35 we know for every 1 degree C rise there is increase of 10mv in the output.

temperature= (analogRead(A0)*4.88mV.)/10mv

If you want to increase the accuracy you can  decrease the Vref. Hope you enjoyed the post and gained something out of it.

HARDWARE SECURITY


For any electronic system to be secure it not only need to  have secure software but also need to be secure at the  Hardware level and Hardware security is an emerging issue.lets understand the difference between a secure and insecure system with the help of an example
Lets say we have to implement a 3 input encoder that assigns a 2-bit code to each of the three different input combinations. Here X,Y,Z are the inputs to the system and a and b are the outputs

If we look at the table we have used only 3 combinations of  X Y Z but there are 2^3 = 8 combinations possible with these inputs. But here the rest of the inputs are don't care .
If you will solve this system using K-map you will find following logical expression

a=x'yz' +xy'z'=(x(XOR)y)z'
b=x'y'z+xy'z'=(x(XOR)y'

But if you will analyse the  table closely there is another possible expression which is as following

a=z'  b=y'

Now lets compare these two versions ,on the first sight you might feel that the second implementation i.e a=z' and b=y' is a better implementation . Since it will require lesser number of gates which in turn means lesser propagation delay and hence faster system,lesser hardware so cheaper system,lesser space consumption. So it will be a fantastic reduction Isn't it?

But if you would really broaden your perspective and if you will look from the perspective of security this lower implementation is more vulnerable and it is more easy for a potnential intruder to find a back door.

Lets look at the problem
Here we have defined 3 input combinations. for 1,0,0 as input the output is 1,1. But there is another input combination 0,0,0 which we have not defined the system for,but can give the same output . So this is a potential backdoor.
Secondly if we give 011 or 111 is input the system gives 00 as output and  if this output is fed into another part of the system which doesn't expect this input there may arise undesirable things. Such type of attack is called a fault injection attack.

So with this small example we can understand that there is a trade off between the performance and security. Most of the time while making the system secure we have to add some extra overhead.

On the software side there is  more awareness about the vulnerabilities and techniques to fix them.With the software you may run software to test for virus and trojan horse.But on the hardware layer the first thing which is the detection of a vulnerability is very difficult once the final hardware is in your hand. . A complete trust can be only obtained if you have control over the whole development life cycle and again having control over the complete design cycle is very difficult job.
Vulnerabilities may arise in the hardware from the microchip supply chain.Someone can place a back door during the fabrication. Often the fabrication is done off shore in the areas where it can happen cheaply but it makes it difficult to control the design process. The IP and CAD design tools that are used to implement the hardware must be from a trusted source Improper implementation of logic like we saw in the above example is another cause of vulnurability.







Thursday, 23 April 2015

HARDWARE SECURITY


For any electronic system to be secure it not only need to  have secure software but also need to be secure at the  Hardware level and Hardware security is an emerging issue.lets understand the difference between a secure and insecure system with the help of an example
Lets say we have to implement a 3 input encoder that assigns a 2-bit code to each of the three different input combinations. Here X,Y,Z are the inputs to the system and a and b are the outputs

If we look at the table we have used only 3 combinations of  X Y Z but there are 2^3 = 8 combinations possible with these inputs. But here the rest of the inputs are don't care .
If you will solve this system using K-map you will find following logical expression

a=x'yz' +xy'z'=(x(XOR)y)z'
b=x'y'z+xy'z'=(x(XOR)y'

But if you will analyse the  table closely there is another possible expression which is as following

a=z'  b=y'

Now lets compare these two versions ,on the first sight you might feel that the second implementation i.e a=z' and b=y' is a better implementation . Since it will require lesser number of gates which in turn means lesser propagation delay and hence faster system,lesser hardware so cheaper system,lesser space consumption. So it will be a fantastic reduction Isn't it?

But if you would really broaden your perspective and if you will look from the perspective of security this lower implementation is more vulnerable and it is more easy for a potnential intruder to find a back door.

Lets look at the problem
Here we have defined 3 input combinations. for 1,0,0 as input the output is 1,1. But there is another input combination 0,0,0 which we have not defined the system for,but can give the same output . So this is a potential backdoor.
Secondly if we give 011 or 111 is input the system gives 00 as output and  if this output is fed into another part of the system which doesn't expect this input there may arise undesirable things. Such type of attack is called a fault injection attack.

So with this small example we can understand that there is a trade off between the performance and security. Most of the time while making the system secure we have to add some extra overhead.

On the software side there is  more awareness about the vulnerabilities and techniques to fix them.With the software you may run software to test for virus and trojan horse.But on the hardware layer the first thing which is the detection of a vulnerability is very difficult once the final hardware is in your hand. . A complete trust can be only obtained if you have control over the whole development life cycle and again having control over the complete design cycle is very difficult job.
Vulnerabilities may arise in the hardware from the microchip supply chain.Someone can place a back door during the fabrication. Often the fabrication is done off shore in the areas where it can happen cheaply but it makes it difficult to control the design process. The IP and CAD design tools that are used to implement the hardware must be from a trusted source Improper implementation of logic like we saw in the above example is another cause of vulnurability.








Friday, 3 April 2015

Arduino Tips & Tricks

Part1: Using buttons in a Reliable way.


Buttons are an integral part of any system. Although now we are more into touch panels and touch screens but still they are there in slightly older systems and may be their count will drop down considerably but they will remain part of newer systems too. So it is good to understand them.

There are two key issues that arise while dealing with buttons.
1. Switch debounce. This is a issue that arise when you press a switch to open it or close it. Spurious signals or sometimes termed as spikes arise when contacts are made or broken. This results in false detection of state.
2. Non usage of pull-ups or pull downs. This  also leads to a state which is un-deterministic.

So these are the problems that I am going to discuss and the measures you should take to eradicate these issues.If you couldn't understand some pieces of what i wrote just don’t worry keep reading and you will get it after you read the examples below.

Example 1:
In this example we will read the state of pin 5 on arduino and will toggle the state of LED on pin 13 according to the state of pin 5. The circuit diagram is as below.


 Here as you see a button is connected to pin 5 and there is a resistor of 20k. This resistor is technically called a pull down resistor. When the button is pressed circuit is completed and  there is a voltage drop across the 20k resistor and this voltage drop should be more than 2.5V. If it is so the state of pin 5 will be read as HIGH by the controller otherwise the state will be read as LOW and you can use this information to switch on or off any LED or anything else. If we donot use the 20k resistor then when the button is not pressed the state of pin 5 will be undeterministic  but as there is a resistance here which pulls down the state of pin 5 to ground when button is not pressed so the indeterministic state is avoided. 

Below is a code that turns the LED on and off based on the state of pin 5
const int ledPin = 13; // choose the pin for the LED     ///#D80E49
const int inputPin = 5; // choose the input pin (for a pushbutton)
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(ledPin, HIGH); // turn LED on if switch is pressed
}
else
{
digitalWrite(ledPin, LOW); // turn LED off
}
}

Here you saw the that a pulldown resistor( or a pullup resistor which is connected to Vcc instead of gnd) is very necessary. Run the above code without this resistor and you can yourself see the difference it creates. 


USING INTERNAL PULL UPS

There are internal pull up resistors available inside the the microcontroller on any arduino board. They can be activated if you want to and in that case you will not have to add an external resistor. To activate it you have to make the state of pin set as input to HIGH in the setup function of arduino.


CODE:
Look at the line  6.
const int ledPin = 13; // output pin for the LED
const int inputPin = 5; // input pin for the switch
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
digitalWrite(inputPin,HIGH); // turn on internal pull-up on the inputPin
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(ledPin, HIGH); // turn LED OFF
}
else
{
digitalWrite(ledPin, LOW); // turn LED ON
}
}
so that solves for this time .