/*Header
Writing a code to measure the voltage --> Use Analog Pin A0
within an LED-resistor ciruit
can measure before LED, after resistor, and between LED-Resistor
With measured voltage we can use Ohms law (V = IR)
To calcualte
Current through component/circuit
Voltage drop across any component
Wire up three different LED-resistor circuits
1 Red LED (Digital Pin 5) - 220 Ohm
1 Red LED (Digital Pin 6) - 1k Ohm
1 Red LED (Digital Pin 7) - 10 kOhm
*/
//Global variable and pins
int VoltReading; //integer called volt reading with no initial value
int LEDPin1 = 5;//integer for each LED pin being used
int LEDPin2 = 6;
int LEDPin3 = 7;
void setup() {
// put your setup code here, to run once:
//how are we using what pins
pinMode(LEDPin1,OUTPUT);//hey arduin LEDpin1 ~5 is an actuator
pinMode(LEDPin2,OUTPUT);
pinMode(LEDPin3,OUTPUT);
//can do pinMode for analog pin BUT all analog pins by default are inputs
//for debuggin ALWAYS start our serial monitor
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
//turn LEDs on
digitalWrite(LEDPin1,HIGH);//turn pin 1 on --> give it 5v
digitalWrite(LEDPin2,HIGH);
digitalWrite(LEDPin3,HIGH);
//probe our circuit --> check some voltages
VoltReading = analogRead(A0);//read voltage value from A0 pin and assign to variable
//gotta print to see and debug
Serial.println(VoltReading);
delay(500);//1/2s
//expected volts before LED = 5V --> print 1023
//expected volts after resistor = 0V --> print 0
//expected volts after LED = 3.3V --> ~700 Evan 552
//limitation of simulation --> Wokwi
//Wokwi does not simulate current --> 0V after ANY component
}