Previous Topic Next Topic
 scott@scottelford.biz #4 Posted : Monday, January 21, 2019 10:12:23 PM(UTC) Rank: Advanced MemberGroups: Registered Joined: 5/31/2017(UTC)Posts: 67Thanks: 1 timesWas thanked: 8 time(s) in 8 post(s) Ezra, this might help you understand what I'm doing, this is the above Ardunio code but with more of the info left in, this is how I build up my code by adding in extra code with the serial print to see how it is going as I keep moving forward with adding in math etc. this is from 2016.Once I'm happy with what the math is doing I remove the serial print etc as it is no longer required. It helps me to develop what I'm building, to see the data changing in real time and I can see any problems in each section.To test this I use a 10K resistor on the input.This is the voltage dividers idea I'm using.//Analog volt read pinconst int voltPin = 0;//Variables for voltage dividerfloat denominator;int resistor1 = 32200;int resistor2 = 7500;int voltage = A0;void setup() { Serial.begin(9600); //Convert resistor values to division value // Equation is previously mentions voltage divider equation // R2 / (R1 + R2) // In this case returns 0.20 or 1/5 denominator = (float)resistor2 / (resistor1 + resistor2);} // Void Setup Closevoid loop() { float voltage; //Obtain RAW voltage data voltage = analogRead(voltPin); //Convert to actual voltage (0 - 5 Vdc) voltage = (voltage / 1024) * 5.0; //Convert to voltage before divider // Divide by divider = multiply // Divide by 1/5 = multiply by 5 voltage = voltage / denominator; //Output to serialSerial.print("Raw: "); Serial.print(voltage); Serial.print("Volts: "); Serial.println(voltage); //Delay to make serial out readable delay(500);} // void loop close