Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. void setup(){
  2. Serial.begin(9600);
  3. }
  4.  
  5. void loop(){
  6. Serial.print("Temperatura: ");
  7. float temperatura = readTempInCelsius(10,0);
  8. Serial.print(temperatura);
  9. Serial.print(" ");
  10. Serial.write(176);
  11. Serial.println("C");
  12. delay(200);
  13. }
  14.  
  15. float readTempInCelsius(int count, int pin) {
  16. float temperaturaMediata = 0;
  17. float sumaTemperatura = 0;
  18. for (int i =0; i < count; i++) {
  19. int reading = analogRead(pin);
  20. float voltage = reading * 5.0;
  21. voltage /= 1024.0;
  22. float temperatureCelsius = (voltage - 0.5) * 100 ;
  23. sumaTemperatura = sumaTemperatura + temperatureCelsius;
  24. }
  25. return sumaTemperatura / (float)count;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement