Professional Documents
Culture Documents
ساخت مولتی متر توسط آردوینو
ساخت مولتی متر توسط آردوینو
//@kollectors//
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "logo.h"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int select_button = 2;
const int right_button = 3;
const int OhmMeter = A0;
const int CapacitancMeter = A1;
const int VoltMeter = A2;
const int Ammeter = A3;
const int R3 = 6;
const int R2 = 5;
const int R1 = 4;
const int ChargePin = 13;
const int DischargePin = 11;
boolean is_select = false;
int navigator = 0;
int flag = 0;
float R = 0.00;
float V = 0.00;
float I = 0.00;
float C = 0.00;
boolean nano = false;
boolean kilo = false;
boolean mili = false;
void OLED_init() {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
diplay_logo(15, 3, Electropeak, F_LOGO_WIDTH, F_LOGO_HEIGHT);
display.display();
delay(2000);
display_clear();
}
void display_clear() {
display.clearDisplay();
display.display();
}
void diplay_logo(int x, int y, const uint8_t *bitmap, int w, int h) {
display.drawBitmap(x, y, bitmap, w, h, WHITE);
}
void display_text(int sz, int x, int y, String str) {
display.setTextSize(sz);
display.setTextColor(WHITE);
display.setCursor(x, y);
display.println(str);
}
void display_number(int sz, int x, int y, double num) {
display.setTextSize(sz);
display.setTextColor(WHITE);
display.setCursor(x, y);
display.println(num);
}
void calculate_resistor() {
float v_ref = 4.94;
float r1 = 0.00;
float r_ref1 = 1000.00;
float adc_value1 = 0.00;
float voltage1 = 0.00;
float r2 = 0.00;
float r_ref2 = 10000.00;
float adc_value2 = 0.00;
float voltage2 = 0.00;
float r3 = 0.00;
float r_ref3 = 100000.00;
float adc_value3 = 0.00;
float voltage3 = 0.00;
pinMode(R1, OUTPUT);
pinMode(R2, INPUT);
pinMode(R3, INPUT);
digitalWrite(R1, HIGH);
for (int i = 0; i < 20 ; i++)
{
pinMode(R1, INPUT);
pinMode(R2, OUTPUT);
pinMode(R3, INPUT);
digitalWrite(R2, HIGH);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(R3, OUTPUT);
digitalWrite(R3, HIGH);
delay(3);
r1 = r1 / 1000;
r2 = r2 / 1000;
r3 = r3 / 1000;
else if (r1 > 2 && r2 < 101 && r3 < 1001) R = r2;
else if (r1 > 2 && r2 > 101 && r3 < 2000) R = r3;
else R = 0.00;
if (R < 1)
R = R * 1000;
kilo = false;
else
kilo = true;
}
}
void calculate_capacitance() {
float microFarads;
float nanoFarads;
digitalWrite(ChargePin, HIGH);
start_time = millis();
if (microFarads > 1)
C = microFarads;
nano = false;
}
else
C = nanoFarads;
nano = true;
digitalWrite(ChargePin, LOW);
pinMode(DischargePin, OUTPUT);
digitalWrite(DischargePin, LOW);
pinMode(DischargePin, INPUT);
void calculate_voltage() {
float R1 = 10000.00;
float R2 = 4700.00;
delay(3);
V = voltage / resistor_ratio;
void calculate_current() {
int adc_value = 0;
delay(2);
I = pure_voltage / sensitivity;
if (I < 1)
I = I * 1000;
mili = true;
else
mili = false;
}
void setup() {
Serial.begin(9600);
OLED_init();
pinMode(right_button, INPUT_PULLUP);
pinMode(select_button, INPUT_PULLUP);
pinMode(ChargePin, OUTPUT);
digitalWrite(ChargePin, LOW);
}
void loop() {
if (digitalRead(right_button) == 0)
{
navigator++;
delay(5);
Serial.println(navigator);
if ( digitalRead(select_button) == 0)
is_select = true;
if (navigator == 0)
display.clearDisplay();
diplay_logo(0, 0, RightArrow, F_LOGO_WIDTH, F_LOGO_HEIGHT);
display.display();
while (is_select)
display.clearDisplay();
display_text(1, 0, 0, "Resistor");
display.display();
calculate_resistor();
if ( digitalRead(select_button) == 0)
is_select = false;
if (navigator == 1)
{
display.clearDisplay();
display.display();
while (is_select)
display.clearDisplay();
display_text(1, 0, 0, "Voltage");
display.display();
calculate_voltage();
if ( digitalRead(select_button) == 0)
is_select = false;
if (navigator == 2)
{
display.clearDisplay();
display.display();
while (is_select)
display.clearDisplay();
display_text(1, 0, 0, "Current");
display.display();
calculate_current();
if ( digitalRead(select_button) == 0)
is_select = false;
if (navigator == 3)
{
display.clearDisplay();
display.display();
while (is_select)
display.clearDisplay();
display_text(1, 0, 0, "Capacitor");
display.display();
calculate_capacitance();
if ( digitalRead(select_button) == 0)
is_select = false;
}
}