Bem-vindo, Visitante
Nome do utilizador: Senha: Memorizar
Eletronica Digital, Microcontroladores, Robótica e Automação

TÓPICO: DS18B20 Termómetro con Arduino & 4 Digits 7 Segment Display

DS18B20 Termómetro con Arduino & 4 Digits 7 Segment Display 04 Dez. 2020 05:14 #1

Hola e montado este circuito en el Arduino y cuando quiero leer la temperatura en el programa de Arduino monitor serie no me sale nada , el sensor lo probado con otro código y si me funciona puede ser que este programa tenga algo mal diseñado le pongo el código y fotos del circuito .
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;

const int ledPin = 13;// LED connected to digital pin 13
const int latchPin = 8;//Pin connected to ST_CP of 74HC595
const int clockPin = 9;//Pin connected to SH_CP of 74HC595
const int dataPin = 10;//Pin connected to DS of 74HC595

const int digitPins[4] = {
3,4,5,6}; //pins to control the 4 common anode pins of the display

const byte digit[10] = //seven segment digit bits
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};

int digitBuffer[4] = {
0};
int digitScan = 0;
int soft_scaler = 0;
float tempC, tempF;
int tmp;

void setup() {
TCCR2A = 0;
TCCR2B = (1<<CS21);
TIMSK2 = (1<<TOIE2);
TCNT2 = 0;

pinMode(ledPin, OUTPUT);
for(int i=0;i<4;i++)
{
pinMode(digitPins,OUTPUT);
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);

sensors.begin();
sensors.getAddress(insideThermometer, 0);
}

ISR(TIMER2_OVF_vect) {
soft_scaler++;
if(soft_scaler==15)
{
refreshDisplay();
soft_scaler = 0;
}
};

void refreshDisplay()
{
for(byte k=0;k<4;k++)
{
digitalWrite(digitPins[k], LOW);
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
digitalWrite(latchPin, HIGH);
delayMicroseconds(400);
digitalWrite(digitPins[digitScan], HIGH);

digitalWrite(latchPin, LOW);
if(digitScan==2)
{
shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000));
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
}
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan>3) digitScan=0;
}

void loop()
{
digitalWrite(ledPin, HIGH);
sensors.requestTemperatures();
tempC = sensors.getTempC(insideThermometer);
tempF = DallasTemperature::toFahrenheit(tempC);
tmp = int(tempF*100);
digitBuffer[3] = tmp/1000;
digitBuffer[2] = (tmp%1000)/100;
digitBuffer[1] = (tmp%100)/10;
digitBuffer[0] = (tmp%100)%10;

digitalWrite(ledPin, LOW);
delay(50);
}

Pesquisar Esquemas | Dicas Defeito | Equivalência Componentes | Modelo v Chassis | Service Mode |
Enviar Esquema