#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
// Data wire is conntec to the Arduino digital pin 23
#define ONE_WIRE_BUS 23
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
const int trigPin = 53;
const int echoPin = 50;
long duration;
int distance;
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// Init
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
//lcd.setCursor(2, 1);
//lcd.print("Wokwi Online IoT");
//lcd.setCursor(5, 2);
//lcd.print("Simulator");
//lcd.setCursor(7, 3);
//lcd.print("Enjoy!");
// put your setup code here, to run once:
/*pinMode(13, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();*/
}
void loop() {
// put your main code here, to run repeatedly:
// turn light on
digitalWrite(13, HIGH);
// Ultrasonic Sensor START
//digitalWrite(trigPin, LOW);
//delay(5);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
// Ultrasonic Sensor END
// Temperature Sensor START
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0));
//delay(1000);
// Temperature Sensor END
delay(500);
digitalWrite(13, LOW);
delay(500);
}
Loading
ds18b20
ds18b20