//***************Arduino code used in video*******************************
/*This code demonstrates how to change the ADC voltage reference on an Arduino
* This was shown in an ADC tutorial on the ForceTronics YouTube Channel.
* This code is free and open for anybody to use at their own risk.
*/
void setup() {
Serial.begin(115200); //setup serial connection
while(!Serial);
analogReference(AR_EXTERNAL); //sets the ADC reference voltage to external (input is aRef pin)
//analogReference(AR_DEFAULT); //set the ADC reference to default which is AVCC (uses power supply voltage or VCC as reference)
//analogReference(AR_INTERNAL2V23); //uses 2.23V internal reference in SAMD21 uC
analogReadResolution(12); //Set ADC to 12bit resolution, default is 10
burn8Readings(); //make 8 readings but don't use them to ensure good reading after reference change
delay(100);
for(int i=0;i<500;i++) { //loop through a bunch of ADC readings and print them to serial plotter
Serial.println(analogRead(A0)); //Make ADC measurement at A0
}
}
void loop() {
//don't need the loop
}
//This function makes 8 ADC measurements but does nothing with them
//Since after a reference change the ADC can return bad readings at first. This function is used to get rid of the first
//8 readings to ensure an accurate one is displayed
void burn8Readings() {
for(int i=0; i<8; i++) {
analogRead(A0);
delay(1);
}
}