Advertisement
dfso

Sensor DS18B20 Saída serial

Jun 12th, 2017
3,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Pinagem  
  3.  * -> Sensor DS18B20
  4.  *      pino central (dados) - Pin 7
  5.  */
  6.  
  7. //*****************************
  8. // bibliotecas do DS18B20
  9. #include <OneWire.h>
  10. #include <DallasTemperature.h>
  11. //*****************************
  12.  
  13.  
  14. //***********************************************************************************
  15. // porta digital do arduino em que o pino de dados do sensor DS18B20 está ligado
  16. #define ONE_WIRE_BUS 7
  17. //***********************************************************************************
  18.  
  19. // Prepara uma instancia de oneWire para se comunicar com um dispositivo OneWire
  20. OneWire oneWire(ONE_WIRE_BUS);
  21. // Passa nossa referencia oneWire para Dallas Temperature.
  22. DallasTemperature sensors(&oneWire);
  23. //************************************************************************************
  24.  
  25.  
  26. // pra calcular a temp.
  27. float tempC = 0.0;
  28.  
  29.  
  30. void setup() {
  31.     sensors.begin();
  32.     Serial.begin(9600);
  33. }
  34.  
  35.  
  36. void loop() {
  37.  
  38.     // envia um comando para obter a temperatura
  39.     sensors.requestTemperatures();
  40.     tempC = sensors.getTempCByIndex(0);
  41.  
  42.     Serial.print(tempC);
  43.     //Serial.write(176); // simbolo de grau º
  44.     Serial.println("°C");
  45.  
  46.     delay(1000);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement