Go Down

Topic: thermometer with binary output (LM35) (fixed) (Read 759 times) previous topic - next topic

StuartL

Sinces nobody understud what i meant the firs time, im going to rewrite the topic:

The LM35, is a termic sensor that lets 10mV pass tru it for each 1ºC
if the sensor is put in a place where the temperature is 25ºC, hes analogic output will be set to 250mV (not sure if realy millivolts)

what i need is, using this sensor, i want to convert this analog imput into a digital output (A/D conversor)
lets say that i use the digital outputs from a arduino from 0 down to 7, and the temperature is 23ºC

23 to binary => 00010011,
so the output should be:
L, L, L, H, L, L, H and H
(L = low, H = High).
if 25ºC: 00010101
and so on


srry for bad inglish :smiley-roll-blue:

cyclegadget



I guess you are needing help getting a code started to light the LEDs?

Here is on part of a thread about doing a bit shift to light LEDs. Here is the important part that was submitted by CrossRoads :


Quote
I was assuming there is some clever command that passes an 8 bit integer to 8 defined output pins, "

If you had all 8 output on the same Port, you could use
PORTD = newCanByte;
for example using PORTD pins.
With an Uno, only PortD has 8 pins and if you are using Serial than 0,1 are committed.

So put your pins in an array
Code:

pinsArray[] = {2,3,4,5,6,7,8,9;}  // could be whatever group you select


and loop thru them to write each one
Code:

maskBit = 1; // start with B00000001
for (x=0; x<8; x=x+1){
if ((CANbyte & maskBit) >0){           // makes all bits but 1 low: 0000000C, next pass 000000C0, etc
digitalWrite (pinsArray
  • ,  HIGH);
    }
    else {
    digitalWrite (pinsArray
  • , LOW);
    }
    maskBit = maskBit<1;  // next bit - B00000010, B00000100, B00001000, etc up to B10000000
    } // next x

Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

dhenry

Fairly simple:

Code: [Select]

#define Vref 5000ul //Vref = 5000mv
#define ADC2MV(adc) ((Vref * (adc)) >> 10)  //turn 10-bit adc to mv
#define readLM35adc(pin) analogRead(pin) //read lm35, in adc counts
#define readLM35mv(pin) ADC2MV(readLM35adc(pin)) //read lM35, in mv
#define readLM35C(pin) (readLM35mv(pin) / 10) //read lm35, in degrees C

 ..
 tmp = readLM35C(LM35_0);  //read LM35_0 into tmp, in degrees




guix

#3
Nov 15, 2012, 03:26 am Last Edit: Nov 25, 2012, 07:16 am by guix Reason: 1
Hello and welcome,

Maybe something like that?

Code: [Select]

int8_t temperature = 23;
uint8_t pins[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
...
for ( int8_t i = 7; i >= 0; i-- )
   digitalWrite( pins[i], (temperature & (1 << i)) >> i );


This will (should) write:
0 to pin 0
0 to pin 1
0 to pin 2
1 to pin 3
0 to pin 4
1 to pin 5
1 to pin 6
1 to pin 7

(Edit: fixed a little mistake!)


guix

#5
Nov 25, 2012, 07:16 am Last Edit: Nov 25, 2012, 07:19 am by guix Reason: 1
Hello, you might be interested by this other solution:
Code: [Select]

uint8_t temperature = 23;

//invert bit order
temperature = ( (temperature * 0x0802UL & 0x22110UL) | (temperature * 0x8020UL & 0x88440UL) ) * 0x10101UL >> 16;

// here is a test for Arduino Mega:
// set pins 54 to 61 (analog inputs 0 to 7) as digital outputs
DDRF = B11111111;

// set value of pins 54 to 61
PORTF = temperature;

// verify
for (uint8_t i = 54; i <= 61; i++)
 Serial.println( digitalRead( i ) );

prints:
Code: [Select]

0
0
0
1
0
1
1
1


So if your digital pins 0 to 7 are on the same port (probably PORTD if you don't have a Arduino Mega), then this solution is for you!

Go Up