รหัสสินค้า | SKU-00036 |
หมวดหมู่ | Sensor ( เซ็นเซอร์ ) |
ราคา | 180.00 บาท |
สถานะสินค้า | พร้อมส่ง |
ลงสินค้า | 23 ก.พ. 2557 |
อัพเดทล่าสุด | 23 ก.พ. 2557 |
คงเหลือ | ไม่จำกัด |
จำนวน | ชิ้น |
The DS18B20 comes in both a cable, an SMD, and a transistor-style package. We're only covering the cable here, but for others see the Datasheet.
Connect it up - to 0v, 3.3v, and the data line to any free signal line of your Espruino device, with a 4.7k resistor between data and the 3.3v line. There seem to be two types of cabled sensor, and each has differently coloured wires. Both are covered below:
Sensor type 1 | Sensor type 2 | Espruino | 4.7k Resistor |
---|---|---|---|
Black | Green | GND | |
Red | Red | 3.3v | 1st wire |
White | Yellow | Any GPIO | 2nd wire |
To use it (assuming you connected to pin A1), simply write the following on the right-hand side:
var ow =newOneWire(A1);var sensor =require("DS18B20").connect(ow);
setInterval(function(){
console.log(sensor.getTemp());},1000);
And the current temperature will be displayed every second. Note that the first time getTemp is called, an incorrect temperature may be returned.
=27.625
The DS18B20 communicates over a 1-Wire bus, which allows connecting multiple thermometers on the same data line.
To create an array containing three sensors, simply:
var ow =newOneWire(A1);var sensor1 =require("DS18B20").connect(ow,0);var sensor2 =require("DS18B20").connect(ow,1);var sensor3 =require("DS18B20").connect(ow,2);var sensors =[sensor1, sensor2, sensor3];
Alternatively, you can create the same array with a little help of the Array.map() function:
var sensors = ow.search().map(function(device){returnrequire("DS18B20").connect(ow, device);});
Now make a function that will be called repeatedly by Espruino:
setInterval(function(){
sensors.forEach(function(sensor, index){
console.log(index +": "+ sensor.getTemp());});},1000);
หน้าที่เข้าชม | 124,129 ครั้ง |
ผู้ชมทั้งหมด | 51,783 ครั้ง |
เปิดร้าน | 11 ธ.ค. 2556 |
ร้านค้าอัพเดท | 10 ส.ค. 2568 |