0

Newb.. With Questions
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Newb.. With Questions

by Blue_Ice on Wed Feb 24, 2016 12:32 pm

I'll give it a try and see where I get. thanks


Next question I need to monitor voltage for my fuel level is this the correct way to do it ?

Image


thanks again

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Wed Feb 24, 2016 2:53 pm

That circuit will read 5v all the time. You need a resistor between the analog pin and 5v. That will form a variable resistor divider - with Vout changing with tank level.

Since the resistance range of the sensor is pretty low, you will want a large enough value to limit the current. A 1/4w 320 ohm resistor will limit the current to about 15mA. Your Vout will range from about 150mv to 1.125v . To get better resolution on your readings you can use the Arduino's internal 1.1v reference:
https://www.arduino.cc/en/Reference/AnalogReference

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Thu Feb 25, 2016 6:08 pm

adafruit_support_bill wrote:That circuit will read 5v all the time. You need a resistor between the analog pin and 5v. That will form a variable resistor divider - with Vout changing with tank level.

Since the resistance range of the sensor is pretty low, you will want a large enough value to limit the current. A 1/4w 320 ohm resistor will limit the current to about 15mA. Your Vout will range from about 150mv to 1.125v . To get better resolution on your readings you can use the Arduino's internal 1.1v reference:
https://www.arduino.cc/en/Reference/AnalogReference


Bill,

thanks for the help It is much appreciated and get me in the right direction. As far as what resistors to use can you point me to someplace i can learn more. my initial voltage on this circuit was 12 volts but i am reducing hooking it to a 5volt supply instead to run it becuase didn't want to harm the UNO, with the calculations you show i could possible use the 12 volts I originally had and use a different size resistor between Vin and the Vout.. it would make it alot more universal for use.

Thanks

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Thu Feb 25, 2016 7:12 pm

Yes, using a 12v source, your output can be closer to the 0-5v default resolution of the ADC also. Voltage dividers are fairly straightforward ways to scale a voltage. For the general formula, and more background, see here:
https://en.wikipedia.org/wiki/Voltage_d ... _divider_2

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Mon Mar 21, 2016 7:51 pm

I want to thank everyone for help esp Adafruit Bill I have learned alot.. I have anothe question hopefully my final on this project. I'm trying to write my odometer reading to FRAM breakout and I can get it to save the long number across the fram but I am not sure hw to get it to show decimal places. See code below any help is appreciated


Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"
uint8_t FRAM_CS = 10;
uint8_t FRAM_SCK= 13;
uint8_t FRAM_MISO = 12;
uint8_t FRAM_MOSI = 11;
//Or use software SPI, any pins!
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);
uint16_t          addr = 0;

long myValue_mi00 = 12345681.25;

void setup(void) {
 
  Serial.begin(9600);
 
  // Read the starting odometer readin from FRAM and print to monitor for testing
  uint8_t test = fram.read8(0x0);
  Serial.print("Odometer Reading "); Serial.print(myValue_mi00); Serial.println(" Miles");


long long myValue_mi00;

  const int FRAM_ADDRESS = 0x0;

  for(int i = 0; i<sizeof(myValue_mi00); i++) {
    ((byte *)&myValue_mi00)[i] = fram.read8(FRAM_ADDRESS + i);
  }

  fram.writeEnable(true);
  for(int i = 0; i<sizeof(myValue_mi00); i++) {
    fram.write8(FRAM_ADDRESS + i, ((byte *)&myValue_mi00)[i]);
  }
  fram.writeEnable(false);
}
 

void loop(void) {

}

.


this does work except i am not sure on writing the .25 or displaying it when it reads..

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Tue Mar 22, 2016 5:41 am

"long" is an integer type, so any fractional part will be truncated when you do the assignment.
https://www.arduino.cc/en/Reference/Long

To preserve the fractional part, you need to use a float:
https://www.arduino.cc/en/Reference/Float

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Mon Apr 25, 2016 11:04 am

Just a bit of follow up and some advice needed,

I have about 99% of this working now thanks to the help and support of people here. I have read up on the voltage dividers and such and i'm doing pretty good..

New question on reading analog.

I have the fuel gauge hooked up like diagram below... but my readings are all over the place they range from -197 to 187 so i must be doing something wrong.
Image

here is code I'm using for reading input and printing out the results.

Code: Select all | TOGGLE FULL SIZE
int analogPin = 3;     
int fuellevel = 0;

void setup()
{
  Serial.begin(9600);         
}

void loop()
{
  fuellevel = analogRead(analogPin);
  fuellevel = map(500, 1024, 1, 99);
  Serial.println(fuellevel);
}


Am I going about this all wrong. also it jumps around like crazy.. let me say in this part of the code (MAP) i might be off a bit on the map but i know that i cant remember the map values off the top of my head and im not at my pc right now to look at it.

I thought about smoothing with reading say 12 readings spanned over time say take reading every 10 seconds then average all 12 of them to get a smoother reading but i'm just starting to read on the smoothing stuff..

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Mon Apr 25, 2016 11:24 am

Code: Select all | TOGGLE FULL SIZE
  fuellevel = map(500, 1024, 1, 99);

The map function takes 5 parameters. I'd be surprised if this line compiles without errors.
https://www.arduino.cc/en/Reference/Map

It will be easier to debug this if you also print out the raw readings you are getting on the analog pin.

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Mon Apr 25, 2016 11:31 am

I'll give it a shot and try and capture the readings...

I see now I missed part of the map. and Im sure i missed it on the code I uploaded to the uno (btw it does compile with no errors)

Seems i might want to write it like such
Code: Select all | TOGGLE FULL SIZE
 fuellevel = map(fuellevel, 500, 1024, 1, 99);


or am I not understanding this correctly.

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Mon Apr 25, 2016 11:36 am

A raw reading lower than 500 will yield a negative number. But I don't see how that line could give you an output higher than 99. Maybe when you post the raw readings it will shed some more light on things.

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Tue Apr 26, 2016 10:11 am

Blue_Ice wrote:I'll give it a shot and try and capture the readings...

I see now I missed part of the map. and Im sure i missed it on the code I uploaded to the uno (btw it does compile with no errors)

Seems i might want to write it like such
Code: Select all | TOGGLE FULL SIZE
 fuellevel = map(fuellevel, 710, 110, 1, 99);


or am I not understanding this correctly.



I did have this constructed correctly... I checked last night.

So I pulled the gauge out of the tank. set up for serial output of the raw readings and then cycled the float from full to empty and watched the raw readings go from 110 - 710 across the range so the raw ADC is sending changes in voltage.

So i bolted it back in the tank, set the map to be correct complied the code uploaded it to the uno filled the tank and gauge reads 100, ok that's good I think so then I remove 1/2 the fuel about 2.5 gallons and the display never changed go figure i'm stumped... seems to work fine outside the tank but once in the tank its freaks out. weird very weird.

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Tue Apr 26, 2016 10:22 am

Not sure what to suggest. Make sure that nothing is getting shorted out as you insert the sensor into the tank.

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Fri Apr 29, 2016 1:04 pm

ok i have done a lot of testing..

at sending unit

empty i'm showing 1.54 volts and the analog input raw reading is 150 ish
as i sweep the arm toward the full point at about half way i am showing 0.74 volts and the raw input reading goes to 0
so my problem is i'm getting to 0 before i get to the end of my sweep to the full mark i still have voltage difference at full it reads 0.14 volts

any ideas ?

154
162
163
164
163
161
156
159
157
157
162
162
153
142
145
149
148
155
159
154
137
108
71
44
26
19
8
15
13
12
5
11
4
20
14
0
0
0
0
0
8
7
3
0

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Re: Newb.. With Questions

by adafruit_support_bill on Fri Apr 29, 2016 1:10 pm

Can you post a complete wiring diagram? It sounds like maybe a bad ground between the sensor and the processor.

adafruit_support_bill
 
Posts: 75263
Joined: Sat Feb 07, 2009 10:11 am

Re: Newb.. With Questions

by Blue_Ice on Fri Apr 29, 2016 1:32 pm

OH i may have a ground loop....

i am going from 12 thu a buck converter to 5v feeding the sensor and the board and displays, but i just looked and my ground from the sensor is grounded to the 12v side on the frame.. may be the issue.. didn't think of that

i'll give ia new wire see what happens direct to the board for the ground


.

Blue_Ice
 
Posts: 33
Joined: Wed Dec 30, 2015 3:12 pm

Please be positive and constructive with your questions and comments.