#define threshold 512
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int adcValue = analogRead(A0);//read the ADC value(0-1023) By default 10 bit ADC is used in arduino.
float voltage = adcValue * (5.0/1023); //converts to voltage
Serial.print("ADC value:");
Serial.println(adcValue);
Serial.print("Voltage:");
Serial.println(voltage);
if(adcValue > threshold){
digitalWrite(13, HIGH);
}
else digitalWrite(13, LOW);
delay(1000); // this speeds up the simulation
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6
pot1:GND
pot1:SIG
pot1:VCC
led1:A
led1:C