// A test for the Discord channel.
// Original: https://wokwi.com/projects/432367544589072385
// Removed everything except the test for sensor detect.
// Specific order to avoid a spike.
// First the pin is set as input,
// then the pullup resistor is enabled.
#define lineRelease() \
DDRD &= ~(1<<PD2); \
PORTD |= (1<<PD2);
// Very specific order to avoid a spike.
// First the bit for the output level is set,
// then the pin is turned into a output.
#define lineLow() \
PORTD &= ~(1<<PD2); \
DDRD |= (1<<PD2);
// returns bool
#define lineRead() ((PIND & (1<<PD2)) != 0)
void setup() {
Serial.begin(115200);
Serial.println("Test sensor detection");
// At power on, all pins are input.
// But it does not hurt to set it again.
DDRD &= ~(1<<PD2);
// Enable pullup
PORTD |= (1<<PD2);
// Wait before using the 1-Wire.
// Let the signal settle for some time.
delay(1000);
}
void loop()
{
if(resetSensor())
{
Serial.println("Found.");
}
else
{
Serial.println("Nothing here.");
}
delay(2000);
}
bool resetSensor()
{
lineLow();
delayMicroseconds(480);
lineRelease();
delayMicroseconds(70);
bool present = !lineRead();
delayMicroseconds(410);
return present;
}
Loading
ds18b20
ds18b20
Use the switch to runtime
connect and disconnect
the sensor.