Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

1/18/2015

7 segment display Arduino

Leave a Comment
The aim of this article demonstrate how the Arduino can run on 7-segment display. We used a SA56-11GWA which is a single display with common anode, it means that the anode is common to all digits, and to the point.
A display consists of 8 LEDs, 7 form the figure and 1 point decimal.A conversion between decimal and what we intend to show the binary information that you receive is called the BCD (Binary Coded Decimal).

In terms of hardware, each LED work individually, so each of the segments has to lead a limiting resistor, in this case, each digit has an operating voltage of 2.2V and consumes 20mA. If the voltage is 5volts, we need the resistor fall 5-2.2 = 3.8V, by Ohm's Law we can calculate, R = V res / I led R = 3.8 / 0.020 = 190 Ω +/- 20% (let's use a resistor with 220Ω). This applies to this display SA56-11GWA used as an example, other values ​​may be different, it is useful to calculate the required resistance value.
DecimalThe321
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
The first thing we have to do is convert our decimal number to binary, we will use examples only 0-9 this first phase
 decToBcd byte (byte val)
 {
   return ((val / 10 * 8) + (val% 10));
 }
This makes our decimal value to binary, for example, assuming that have numbers with more than two digits, 27 will be 0010 0111 (2 - 7 BCD). If we have only one figure 2 for example, will have 0010.
This allows us to act on an IC decoder (4511) and the use of only four BCD outputs Arduino, so can convert a result of a count value, or for any input digit.
 / *
 Example of a counter from 0 to 9 that adds each 
 Since there is an entry in A0
  
 author: Arturo Guadalupi 
  * /
 
 // Declaration of pins used in the 4511 entries
 The const int = 2;
 const int b = 3;
 const int c = 4;
 const int D = 5;
 
 void setup () {
   pinMode (A0, INPUT);
   pinMode (A, OUTPUT);  // LSB
   pinMode (B, OUTPUT);
   pinMode (C, OUTPUT);
   pinMode (D, OUTPUT);  // MSB
 
 }
 
 int count = 0;  // Used for the variable number
 
 void loop () {
   if (digitalRead (A0) == LOW) // if the button is pressed on the A0 input
     {
     count ++;
     delay (200);  // The delay prevents multiple counts
     if (count == 10) // 0-9 counter
       count = 0;
     to_BCD ();  // Convert to binary
     }
    
   if (count == 10)
     count = 0;
   
 }
 
 to_BCD void ()
 {
     if (count == 0) // write 0000
     {
       digitalWrite (A, LOW);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 1) // write 0001
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 2) // write 0010
     {
       digitalWrite (A, LOW);
       digitalWrite (B, HIGH);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 3) // write 0011
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, HIGH);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 4) // write 0100
     {
       digitalWrite (A, LOW);
       digitalWrite (B, LOW);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 5) // write 0101
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, LOW);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 6) // write 0110
     {
       digitalWrite (A, LOW);
       digitalWrite (B, HIGH);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 7) // write 0111
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, HIGH);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 8) // write 1000
     {
       digitalWrite (A, LOW);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, HIGH);
     }
     
     if (count == 9) // write 1001
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, HIGH);
     }
 } 

Convert decimal to binary (8bit)


7 segment display Arduino
It is possible to directly transfer the binary value for the exits, here is an example of cyclic counter zero to nine
 ledpins int [] = {4,5,6,7,8,9,10,11};
 byte digits [] = {B11111100, B01100000, B11011010, B11110010, B01100110, B10110110,
 B10111110, B11100000, B11111110, B11110110};

 void setup ()
 {
   for (int i = 0; i <8; i ++)
   {
     pinMode (ledpins [i] OUTPUT);
     digitalWrite (ledpins [i], HIGH);
   } 
 }


 void loop ()
 {
   for (int i = 0; i <10; i ++)
   {
     displayDigit (i);
     delay (1000);
     AllOff ();
     delay (500);
   }   
 }

 displayDigit void (int digit)
 {
   for (int i = 0; i <8; i ++)
   {
     digitalWrite (ledpins [i] ,! bitRead (digits [Scan], 7-i));
   } 
 }

 void AllOff ()
 {
   for (int i = 0; i <8; i ++)
   {
     digitalWrite (ledpins [i], HIGH);
   }  
 }
In this case not used the BCD outputs but a direct binary code in 8 bits (one for each connected LED)
We used a level 1 (HIGH) when the segment lights and 0 (LOW) when deleted. The last digit is always a 0 represents the decimal point that is not being used.

The AllOff () procedure off all digits reversing the common pin.

displayDigit () connects the right thread for each digit. The function bitread reads the bits of the binary number, starting with the rightmost bit.That's why the 7-i is used. When using the digitalWrite () statement, we can write 1 when we want to HIGH and LOW 0 when we want. This is the opposite of how our binary numbers are working. The operator! inverts the value. via electronica-pt.com
Read More...

11/15/2014

Auto ranging ohmmeter using arduino

Leave a Comment
This article is about a simple auto ranging ohmmeter using arduino. The measured resistance is displayed using a 16×2 LCD display. The circuit is sufficiently accurate and uses minimum number of external components possible. Before going into the details of this project, lets have a look at the basic resistance measurement method.

Resistance measurement.

Auto ranging ohmmeter using arduinoThe figure above shows the circuit diagram of a simple resistance measurement scheme. Rx is the resistance to be measured. R1 is the input resistance. i is the current passing through the loop and 5V is the supply voltage. To find the unknown resistance Rx, the voltage across Rx is measured first. let the voltage across R1 be VR1. Then VR1=5-Vx. The current i=VR1/R1=(5-Vx)/R1. Since R1 and Rx are connected in series, the current through them will be equal. So the unknown resistance Rx= Vx/i. The voltage across the unknown resistance is measured using the ADC of the arduino. To be precise, analog channel A5.

Anyway this method have a drawback. If there is great difference between the input resistance and the Rx, the result will be extremely inaccurate. This is because almost all of the input voltage will drop across the larger resistance and this provides very less information.
Suppose R1=10K and Rx=100 ohm. Then the voltage across R1 will be 4.95v and voltage across Rx will be 50mV and this gives less information. The sensitivity of the arduino is 4.889mV. So when we read 50mV using the arduino ADC the result will be 10. When converted it into voltage the result will be 10 x 4.889mV =48.89mV. Then Rx= 0.0488/((5V-48.89mV)/10000) = 98.7 ohm.
Suppose R1=10 and Rx=220 ohm. Then the voltage across R1 will be 4.89V and voltage across Rx will be 107mV. The corresponding digital reading will be 21. When we convert it into voltage the result will be 21 x 4.889mV=102mv. Following the calculations used in the previous case, Rx=208 ohm. In the above two cases you can see accuracy issues. The most accurate result occurs when the Rx and R1 are as close as possible.

Auto ranging.

A scheme for estimating the value of Rx roughly and then putting a matching resistor in place of R1 is what we need here and this method is called auto ranging. The circuit given below demonstrates auto ranging. 
Resistances R1 to R7 are the input resistors. In this scheme the free end of one resistor is held high and the free ends of other resistors are held low. The the voltage across the unknown resistance Rx is measured. Diodes D1 to D7 are used to prevent the back flow of current towards the low ends. Suppose free end of R1 is held low. If R1 and Rx are equal, then the voltage drop across Rx will be (5-0.7)/2 = 2.15 where 0.7 is the diode drop. If the voltage across Rx is less than or equal to 2.15, we can assume that Rx is less than or equal to 220 ohms. The closest value possible for the input resistance is 220 ohms and so this loop is considered for calculation. If the above condition is not satisfied, the above steps are repeated with the succeeding input resistors until we get a solution.
Circuit diagram.

Full circuit diagram of the auto ranging ohmmeter using arduino is shown in the figure above. Digital pins 1, 6, 7, 8, 9, 10, 13 of the arduino are used to switch the input resistors R1, R2, R3, R4, R5, R6, R7 respectively. Resistors D1 to D7 are used to prevent the back flow of current through the corresponding path. D8 is the power ON indicator LED. POT R10 is used for contrast adjustment of the LCD. Resistor R9 limits the back light LED current.

Program.
#include<LiquidCrystal.h>
int vin=A5;
int t=1;
int u=6;
int v=7;
int w=8;
int x=9;
int y=10;
int z=13;

int at;
int au;
int av;
int aw;
int ax;
int ay;
int az;
int a;
double vx;
float rx;
double i;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(vin,INPUT);
lcd.begin(16,2);

pinMode(t,OUTPUT);
pinMode(u,OUTPUT);
pinMode(v,OUTPUT);
pinMode(w,OUTPUT);
pinMode(x,OUTPUT);
pinMode(y,OUTPUT);
pinMode(z,OUTPUT);

digitalWrite(t,LOW);
digitalWrite(u,LOW);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(x,LOW);
digitalWrite(y,LOW);
digitalWrite(z,LOW);
}
void loop()
{

digitalWrite(t,HIGH);
digitalWrite(u,LOW);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(x,LOW);
digitalWrite(y,LOW);
digitalWrite(z,LOW);
delay(100);
at=analogRead(vin);




digitalWrite(t,LOW);
digitalWrite(u,HIGH);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(x,LOW);
digitalWrite(y,LOW);
digitalWrite(z,LOW);
delay(100);
au=analogRead(vin);
digitalWrite(t,LOW);
digitalWrite(u,LOW);
digitalWrite(v,HIGH);
digitalWrite(w,LOW);
digitalWrite(x,LOW);
digitalWrite(y,LOW);
digitalWrite(z,LOW);
delay(100);
av=analogRead(vin);



digitalWrite(t,LOW);
digitalWrite(u,LOW);
digitalWrite(v,LOW);
digitalWrite(w,HIGH);
digitalWrite(x,LOW);
digitalWrite(y,LOW);
digitalWrite(z,LOW);
delay(100);
aw=analogRead(vin);


digitalWrite(t,LOW);
digitalWrite(u,LOW);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(x,HIGH);
digitalWrite(y,LOW);
digitalWrite(z,LOW);
delay(100);
ax=analogRead(vin);


digitalWrite(t,LOW);
digitalWrite(u,LOW);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(x,LOW);
digitalWrite(y,HIGH);
digitalWrite(z,LOW);
delay(100);
ay=analogRead(vin);



digitalWrite(t,LOW);
digitalWrite(u,LOW);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(x,LOW);
digitalWrite(y,LOW);
digitalWrite(z,HIGH);
delay(100);
az=analogRead(vin);

if(az>=450)
{
vx=az*0.00489;
i=(5-vx-0.55)/22000;
rx=(vx/i);
}
if(ay>=450 && az<450)
{
vx=ay*0.00489;
i=(5-vx-0.55)/10000;
rx=(vx/i);
}
if(ax>=448 && ay<448 && az<448)
{
vx=ax*0.00489;
i=(5-vx-0.55)/4700;
rx=(vx/i);
}

if(aw>=439 && ax<439 && ay<439 && az<439)
{
vx=aw*0.00489;
i=(5-vx-0.55)/2200;
rx=(vx/i);
}

if(av>=439 && aw<439 && ax<439 && ay<439 && az<439)
{
vx=av*0.00489;
i=(4.8-vx-0.55)/1000;
rx=(vx/i);
}

if(au>=430 && av<430 && aw<430 && ax<430 && ay<430 && az<430)
{
vx=au*0.00489;
i=(4.5-vx-0.55)/560;
rx=(vx/i);
}

if(at>=430 && au<430 && av<430 && aw<430 && ax<430 && ay<430 && az<430 )
{
vx=at*0.00489;
i=(4.5-vx-0.55)/220;
rx=(vx/i);
}

if(at<430 && au<430 && av<430 && aw<430 && ax<430 && ay<430 && az<430 )
{
vx=at*0.00489;
i=(4.5-vx-0.55)/220;
rx=(vx/i);
}
lcd.setCursor(0,0);

if(vx>4.8)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("----INFINITY----");
}
else
{
if(rx<1000)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(rx);
lcd.setCursor(7,0);
lcd.print((char)244);
}
else
{
lcd.clear();
rx=rx/1000;
lcd.setCursor(0,0);
lcd.print(rx);
lcd.setCursor(6,0);
lcd.print("k");
lcd.print((char)244);
}
}
lcd.setCursor(0,1);
lcd.print("Arduino Ohmmeter");
}

sourse: www.circuitstoday.com
Read More...

9/11/2014

Arduino 3W Stereo Amp

Leave a Comment
This article just promote for free whis project. Original article sourse www.adafruit.com/products/1788

Arduino 3W Stereo Amp



Read More...