Author Topic: voltmeter  (Read 1151 times)

aishen

  • Newbie
  • *
  • Posts: 30
    • View Profile
voltmeter
« on: 2016-December-17 10:27:58 am »
Any help ?
I tried to reproduce this voltmeter in visualino, but it doesn't work, can you guide me ?

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;
void setup(){
   pinMode(analogInput, INPUT);
   lcd.begin(16, 2);
   lcd.print("DC VOLTMETER");
}
void loop(){
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 5.0) / 1024.0; // see text
   vin = vout / (R2/(R1+R2));
   if (vin<0.09) {
   vin=0.0;//statement to quash undesired reading !
}
lcd.setCursor(0, 1);
lcd.print("INPUT V= ");
lcd.print(vin);
delay(500);
}

aishen

  • Newbie
  • *
  • Posts: 30
    • View Profile
Solution : how to insert partenthesis
« Reply #1 on: 2016-December-17 12:16:19 pm »
R1+R2 have tw parenthesis otherwise it doesn't work but how to put patenthesis in visualino (if it's possible ? )
#include <Wire.h>
#include <LiquidCrystal.h>

/***   Global variables   ***/
float vout;
float vin;
float R1;
float R2;
int value=0;
int analogInput=0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

/***   Function declaration   ***/

void setup()
{
  vout=0.0;

  vin=0.0;

  R1=100000.0;

  R2=10000.0;


  lcd.begin(16, 2);
  lcd.clear();
  Serial.begin(9600);
  pinMode(analogInput,INPUT);
  // value=analogRead(analogInput);
  lcd.print("VOLTMETRE");

}


void loop()
{
    //pinMode(analogInput,INPUT);
    value=analogRead(analogInput);
    vout=value * 5.01 / 1024.01;
    vin=vout / (R2 / (R1 + R2));
    if (vin < 0.09) {
      vin=0.0;
     }
    lcd.setCursor(0,1);
    lcd.print("ENTREE V = ");
    lcd.print(vin);
    delay(500);
    lcd.clear();
}

Víctor R. Ruiz

  • Administrator
  • Jr. Member
  • *****
  • Posts: 91
    • View Profile
Re: Solution : how to insert partenthesis
« Reply #2 on: 2016-December-17 12:34:20 pm »
R1+R2 have tw parenthesis otherwise it doesn't work but how to put patenthesis in visualino (if it's possible ? )

Interesting. Nope, currently it's not possible. There is no block for that.

aishen

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: voltmeter
« Reply #3 on: 2016-December-17 01:33:31 pm »
I found a solution...
I created a float res=0
then
res=(R2/(R1+R2));
and vin=vout/res;

That's the logic ! lol
I read you message few times ago you were answering how to make it in an execute "text" very strong command !

Víctor R. Ruiz

  • Administrator
  • Jr. Member
  • *****
  • Posts: 91
    • View Profile
Re: voltmeter
« Reply #4 on: 2016-December-17 10:58:29 pm »
I read you message few times ago you were answering how to make it in an execute "text" very strong command !

Yes, Execute is a wildcard. It solves most of these problems :-)