Last active
August 21, 2017 16:50
-
-
Save urmil0071/f7d4913cf8e991ac87b9e775f9c2aa3a to your computer and use it in GitHub Desktop.
Temperature meter code to show Internal temperature after each 3 seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
byte secpass=0; | |
int adct=0,x1,x2; | |
float bintemp; | |
void setup() | |
{ | |
Serial.begin(9600); | |
ADMUX=0xC8; /// 1.1 V refrrence, Right adjust, channel 8 | |
bitWrite(ADCSRA,7,1); /// ADC Enabled | |
bitWrite(ADCSRA,5,1); /// Auto Triggering Enabled | |
ADCSRA |= B00000110; /// Pre Scaler to 1/64 // CLKAdc 250Khz | |
bitWrite(ADCSRA,6,1); ///Start Convertion | |
while (bitRead(ADCSRA,4) !=HIGH) | |
{ | |
} | |
adct=ADCW; | |
Serial.println(adct,DEC); | |
TCCR1A=0x00; /// Normal mode for TC1 | |
TCCR1B=0x00; /// Counter stop | |
TCNT1=0x48E5; /// preset value for 3sec delay | |
bitWrite(TIFR1,2,1); /// TOV1 CLEAR | |
TCCR1B=0x05; /// Counter on with 1/1024 prescaler | |
bitWrite(ADCSRA,6,1); ///Start Convertion | |
} | |
void loop() | |
{ | |
if ( bitRead(TIFR1,2)==HIGH) | |
{ | |
TCCR1B=0x00; /// Counter stop | |
bitWrite(TIFR1,2,1); /// TOV1 CLEAR | |
TCNT1=0x48E5; /// preset value for 3sec delay | |
x1=ADCL; | |
x2=ADCH; | |
adct=x2<<8|x1; | |
Serial.println(adct,HEX); | |
float x=(float)(0xEEA6D*adct-0xF863864)/pow(10,6); | |
Serial.println(x,10); | |
TCCR1B=0x05; /// Counter Start | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment