Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int rosu=2;
- int buton=4;
- int verde=7;
- int senTem=A0;
- int galben=5;
- int contor=0;
- void setup() {
- // put your setup code here, to run once:
- pinMode(rosu,OUTPUT);
- pinMode(buton,INPUT);
- pinMode(verde,OUTPUT);
- // pinMode(galben,OUTPUT);
- digitalWrite(rosu,HIGH);
- Serial.begin(9600);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- if(digitalRead(buton)==HIGH && contor==0)
- {
- digitalWrite(verde,HIGH);
- digitalWrite(rosu,LOW);
- Serial.print("Temperatura: ");
- float temp=fctTemp(10,senTem);
- Serial.print(temp);
- Serial.print(" ");
- Serial.print(176);
- Serial.println("C");
- delay(2000);
- if(temp>=27 && temp<28)
- {
- analogWrite(galben,50);
- }
- if(temp>=28 && temp<29)
- {
- analogWrite(galben,150);
- }
- if(temp>=29 && temp<30)
- {
- analogWrite(galben,200);
- }
- if(temp>=30)
- {
- analogWrite(galben,250);
- }
- contor=1;
- delay(1000);
- }
- if(contor==1 && digitalRead(buton)==HIGH)
- {
- digitalWrite(verde,LOW);
- digitalWrite(rosu,HIGH);
- }
- }
- float fctTemp(int c,int p){
- float tempMediata=0;
- float sumaTemp=0;
- for(int i=0;i<c;i++)
- {
- int reading=analogRead(p);
- float v=reading*5.0;
- v /=1024.0;
- float tempCelsius=(v -0.5)*100;
- sumaTemp=sumaTemp+tempCelsius;
- }
- return sumaTemp/(float)c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement