Kenneth Yang
Published © GPL3+

5vCircuitPowerMeter

Make a power meter for 5v circuits using material from the Arduino Starter Kit

IntermediateFull instructions provided2,668
5vCircuitPowerMeter

Things used in this project

Story

Read more

Schematics

Main Project

Main Project

Breadboard View

LCD Setup

How to setup a 16x2 LCD

Code

PowerMeter

Arduino
Main code
#include <LiquidCrystal.h>

//Include^
//Init
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//Global Var
int pot = 0;
int index = 0;

const int out = A1;
const int in = A2;
const int mm = A0;
const int li = 6;
void setup() {//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  lcd.begin(16, 2);
  // put your setup code here, to run once:
  pinMode(li, OUTPUT);
  pinMode(out, OUTPUT);
  pinMode(in, INPUT);
  pinMode(mm, INPUT);
  pinMode(8, OUTPUT);
  off(8);
  on(li);
  lcd.print("   PowerMeter");
  delay(1000);
  lcd.clear();


}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop() {//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // put your main code here, to run repeatedly:
  pot = analogRead(mm);
  index = map(pot, 0, 1023, 1, 5);

  if (index == 1) {
    off(li);
    on(8);
  }
  if (index == 2) {
    lcd.clear();
    on(li);
    off(8);
    lcd.print(" DC Volt Meter");
    while (true) {
      float vv = analogRead(in) * (5.0 / 1023.0);
      lcd.setCursor(0, 1);
      lcd.print(vv);

      pot = analogRead(mm);
      index = map(pot, 0, 1023, 1, 5);
      if (index != 2)
        break;
    }
  }
  if (index == 3) {
    lcd.clear();
    on(li);
    off(8);
    lcd.print(" Analog R/W Val");
    while (true) {
      int aR = analogRead(in);
      int aW = map(aR, 0, 1023, 0, 255);
      lcd.setCursor(0, 1);
      lcd.print("R:" + String(aR) + "     W:" + String(aW)+"    ");

      pot = analogRead(mm);
      index = map(pot, 0, 1023, 1, 5);
      if (index != 3)
        break;
    }
  }
  if (index == 4) {
    lcd.clear();
    on(li);
    off(8);
    lcd.print("      Ohms");
    while (true) {
      float vv = analogRead(in) * (5.0 / 1023.0);
      float rr = vv / 20.0;
      lcd.setCursor(0, 1);
      lcd.print(rr);

      pot = analogRead(mm);
      index = map(pot, 0, 1023, 1, 5);
      if (index != 4)
        break;
    }
  }
  if (index == 5) {
    lcd.clear();
    on(li);
    off(8);
    lcd.print("  Conductivity");
    while (true) {
      on(out);
      lcd.setCursor(0, 1);
      if (digitalRead(in) == HIGH)
        lcd.print("Connect         ");
      else
        lcd.print("Disconnect      ");

      pot = analogRead(mm);
      index = map(pot, 0, 1023, 1, 5);
      if (index != 5)
        break;
    }
  }
}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//Functions
//New~~~~~~~~~~~~~~~~


//Back~~~~~~~~~~~~~~~~~~
void on(int pin) {
  digitalWrite(pin, HIGH);
}
void off(int pin) {
  digitalWrite(pin, LOW);
}

Credits

Kenneth Yang

Kenneth Yang

8 projects • 100 followers
Maker, developer, 3D content creator

Comments