 # thermometer with binary output (LM35) (fixed)

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

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 :

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:

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

Fairly simple:

``````#define Vref 5000ul //Vref = 5000mv

..
``````

Hello and welcome,

Maybe something like that?

``````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!)

thx all of you that solved the problem :)

Hello, you might be interested by this other solution:

``````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++)
``````

prints:

``````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!