0% found this document useful (0 votes)
4 views

Arduino 1

The document contains two Arduino code snippets for temperature control systems using LCD and keypad interfaces. Arduino 1 reads temperature from a sensor and communicates the data via I2C, while Arduino 2 allows user input to set a desired temperature. Both programs include functions for setup, loop, and handling I2C communication for controlling a motor based on temperature readings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Arduino 1

The document contains two Arduino code snippets for temperature control systems using LCD and keypad interfaces. Arduino 1 reads temperature from a sensor and communicates the data via I2C, while Arduino 2 allows user input to set a desired temperature. Both programs include functions for setup, loop, and handling I2C communication for controlling a motor based on temperature readings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Arduino 1 Arduino 2

#include <LiquidCrystal.h> #include <Keypad.h>


#include <Wire.h> #include <Wire.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); const byte numRows= 4;


const byte numCols= 4;
int sensorPin =A0;
int sensorValue =0; char keymap[numRows][numCols]=
float TemperaturaC=0; {
int v_sp=0; {'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
void set_point(int sp){ {'7', '8', '9', 'B'},
lcd.setCursor(14,0); {'B', '0', 'B', 'B'}
lcd.print(sp); };
lcd.setCursor(0,0);
lcd.print("grado celcius "); byte rowPins[numRows] = {11,10,9,8};
v_sp=sp; byte colPins[numCols]= {7,6,5,4};
}
Keypad teclado =
void setup() { Keypad(makeKeymap(keymap), rowPins,
lcd.begin(16, 2); colPins, numRows, numCols );
Wire.begin();
} char tecla;
int v_sp=30;
void loop() { int v_tc=0;
sensorValue=analogRead(sensorPin); int c_pvt=0;
int motor=2;
TemperaturaC=((5*sensorValue*100.0)/1024)- float t_actR=0;
50.0; char var_tc[2]={0,0};
lcd.setCursor(0,1); char texto[3];
lcd.print(TemperaturaC);
void control (float Tact)
Wire.beginTransmission(8); {
char temBuff[4]; if (Tact>=v_sp){
dtostrf(TemperaturaC,4,2,temBuff); digitalWrite(motor,HIGH);
Wire.write(temBuff); }
Wire.endTransmission(); else{
digitalWrite(motor,LOW);
Wire.requestFrom(8,1); }
while(Wire.available()){ }
char c = Wire.read();
int a=int(c); void setup() {
if (a!=v_sp){ Wire.begin(8);
set_point(a); Wire.onReceive(receiveEvent);
} Wire.onRequest(requestEvent);
} pinMode(motor,OUTPUT);
} }
void loop(){

tecla = teclado.getKey();
if (tecla){
if (tecla=='B'){

}else{
if (tecla!='A' && c_pvt<2){
var_tc[c_pvt]=tecla;
c_pvt=c_pvt+1;

}else{
int uni=var_tc[1]-'0';
int doc=var_tc[0]-'0';
v_sp=uni+doc*10;
var_tc[1]=0;
var_tc[0]=0;
c_pvt=0;
}
}
}
}

void receiveEvent(int howMany) {


char sc[4];
int i=0;
while (1 < Wire.available()) {
char c = Wire.read();
sc[i]=c;
i=i+1;

}
sc[i]=Wire.read();

int unis=sc[1]-'0';
int docs=sc[0]-'0';
int decs=sc[3]-'0';
t_actR=docs*10+unis+decs/10.0;
control(t_actR);
}

void requestEvent() {
Wire.write(v_sp);
}

You might also like