Faseehpp
Published © GPL3+

Arduino Voltage Meter using Serial Monitor

Read the voltage in the analog with a switch

BeginnerFull instructions provided7,275
Arduino Voltage Meter using Serial Monitor

Things used in this project

Story

Read more

Schematics

Circuit

Instruction File

Code

Source Code

Arduino
/*
Arduino Voltage Meter using Serial Monitor
by Faseeh Padinjarathil
*/
const int buttonPin = 2; 
const int ledPin = 13; 
int buttonPushCounter = 0; 
int buttonState = 0; 
int lastButtonState = 0; 


void setup() {

pinMode(buttonPin, INPUT);

pinMode(ledPin, OUTPUT);

Serial.begin(9600);
}

void loop() {

buttonState = digitalRead(buttonPin);
int sensorValue = analogRead(A0);

float voltage = sensorValue * (5.0 / 1023.0);

if (buttonState != lastButtonState) {

if (buttonState == HIGH) {

buttonPushCounter++;
Serial.println("on");
Serial.print("CURRENT VOLTAGE: ");
Serial.println(voltage);
} else {

Serial.println("off");
}

delay(50);
}

lastButtonState = buttonState;

if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

}

Credits

Faseehpp

Faseehpp

0 projects • 1 follower

Comments