You are on page 1of 3

#include <OneWire.

h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 2 on the Arduino


#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void)
{
Serial.begin(9600);
// Inicializar la comunicación con el sensor
sensors.begin();
}

void loop(void)
{
sensors.requestTemperatures(); // Enviar la petición de temperatura al sensor
float temperatura = sensors.getTempCByIndex(0); // Leer la temperatura en grados
Celsius

// Imprimir la temperatura en el monitor serial


Serial.print("Temperatura: ");
Serial.print(temperatura);
Serial.println(" °C");

delay(1000); // Esperar 1 segundo antes de leer la temperatura nuevamente


}

#include <SoftwareSerial.h>
SoftwareSerial bt(10,11 );

void setup () {
Serial.begin(9600);
bt.begin(38400);

}
void loop(){
if (Serial.available() >0){
bt.write(Serial.read());
}
if (bt.available() >0){
Serial.write(bt.read());
}
}

/*
Software serial multiple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

Not all pins on the Leonardo and Micro support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

created back in the mists of time


modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port


mySerial.begin(38400);
mySerial.println("Hello, world?");
}

void loop() { // run over and over


if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

// Definir el pin del LED


int ledPin = 13;

void setup() {
// Inicializar el pin del LED como salida
pinMode(ledPin, OUTPUT);
// Inicializar la comunicación serial a 9600 baudios
Serial.begin(9600);
}

void loop() {
// Verificar si hay datos disponibles en el puerto serial
if (Serial.available() > 0) {
// Leer el byte recibido
char receivedChar = Serial.read();
// Verificar si el byte recibido es '1' (encender el LED)
if (receivedChar == '1') {
digitalWrite(ledPin, HIGH); // Encender el LED
Serial.println("LED encendido");
}
// Verificar si el byte recibido es '0' (apagar el LED)
else if (receivedChar == '0') {
digitalWrite(ledPin, LOW); // Apagar el LED
Serial.println("LED apagado");
}
}
}

You might also like