[SOLVED] voltmeter and ammeter problem (atmega328)

Status
Not open for further replies.

hamid159

Full Member level 3
Joined
Aug 25, 2013
Messages
176
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,298
Location
Lahore
Activity points
2,488
hy guyz,i'm working on digital voltmeter and ammeter (130V and 40A,on lcd) using atmega328.
it is working well on proteus.but not worknig on verroboard,it shows the constant voltage and current i.e, 130V and 40A(max. limits).it does not detect the adc voltage.
This is my code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
int analogInput = 0;
    int analogInput1 = 1;
    float vout = 0.0,vout1 = 0.0,vin = 0.0,vin1 = 0.0;
    float vinnew=0.0;
    float R1 = 680000.0;
    float R2 = 27000.0; 
    float R3=100000.0;
    float R4=100000.0;  
    float value = 0.0;
    float value1 = 0.0;
void setup() { 
lcd.begin(20,4);
pinMode(analogInput, INPUT);
    pinMode(analogInput1, INPUT);
    lcd.setCursor(0,2);
    lcd.print("voltmeter");
    delay(100);
}
void loop() { 
lcd.setCursor(0,0);
lcd.print("  V      A");
value = analogRead(analogInput);
    value1 = analogRead(analogInput1);
    vout = (value * 5.0) / 1024.0;
    vin = vout / (R2/(R1+R2));
   vout1 = (value1 * 5.0) / 1024.0;
    vin1 = vout1 / (R4/(R3+R4));
    lcd.setCursor(0, 1);
    if (vin<0.1)
    {
      vin=0.00;
    }  
    vinnew=4*vin1;
if (vinnew<0.1)
vinnew=0.0;
    lcd.print(vin);
    lcd.setCursor(8, 1);
    lcd.print(vinnew);
    delay(500);
}


- - - Updated - - -

it is also working well on arduino uno board.In above pdf file,crystal (16MHz)is missing..i've connected it with 9 and 10 pin of atmega328 with capacitors grounded
 

Attachments

  • volt1.pdf
    21.9 KB · Views: 123
Last edited by a moderator:

I could not see at above code any effective infinite loop routine, such as a while(1), therefore value displayed is not updating accordingly.



+++
 

but there is a predefined function loop().which is updating the values.

- - - Updated - - -

guyzz please help me.......
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…