Hi,
I am test the circuit from:
I used a Arduino instead of a Nano, and input a 12Vdc and the unit can read any resistance, why?
Thanks
Adam
#include <Adafruit_SSD1306.h>
#include <Wire.h> // Wire Library for OLED
#define SCREEN_WIDATA_PINH 128 // OLED display Width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define LM317_REF 1.25
#define LM317_Resistance 10.1
const int numReadings = 50; // used for averaging / we will take 50 samples and average it to get ADC value
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int ADCaverage = 0; // the average
float R;
int inputPin = A0;
Adafruit_SSD1306 display(SCREEN_WIDATA_PINH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.setTextColor(WHITE); // set LCD Colour
display.setRotation(2); // it has modes 1,2,3,4
//
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
delay(500);
}
void loop() {
total = total - readings[readIndex]; // subtract the last reading:
readings[readIndex] = analogRead(inputPin); // read from the sensor:
total = total + readings[readIndex]; // add the reading to the total:
readIndex = readIndex + 1; // advance to the next position in the array:
if (readIndex >= numReadings) {
// if we're at the end of the array...
// ...wrap around to the beginning:
readIndex = 0;
}
ADCaverage = total / numReadings; // calculate the average:
Serial.print("AVG: ");
Serial.print(ADCaverage);
float voltage = ADCaverage * (5.0 / 1024.0); // Convert ADCaverage t0 Voltage
Serial.print(" \t \t"); // give me a little TAb would ya
Serial.print(voltage, 3); // Print Voltage to Serial Monitor
Serial.print(" \t \t");// give me another little TAb would ya
R = voltage / (LM317_REF / LM317_Resistance) ;
Serial.print("Resistance: ");
Serial.println(R);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(10, 10);
display.print(R,3);
display.print(" R");
display.display();
delay(50);
}
