材料清單
AmbiMate MS4多傳感器模塊
面包板和跳線
Arduino IDE(軟件)
什么是AmbiMate MS4?
AmbiMate傳感器模塊MS4系列集成了一套傳感器,用于樓宇自動化和連接家庭應用到PCB組件上。它在即用型PCB組件上提供了一組專用傳感器,可輕松集成到主機產品中。
傳感器包括運動,光線,溫度,濕度,VSO(揮發性有機化合物),CO2和聲音檢測。通過捕獲VOC濃度來增加監測空氣質量的能力。有許多MS4系列傳感器可用 - 我建議您選擇帶有嵌入式麥克風的傳感器來增強運動檢測或者能夠收聽聲音事件。
所有MS4系列傳感器模塊都可以靈活地共享一個通用的七位連接。這使得設計人員可以布置單個PCB封裝,以適應生產中所有可用的傳感器配置。
MS4應用
室內照明
能源管理
樓宇自動化
工作空間舒適度
區域環境控制
自動化
空氣質量測量系統
MS4規范
在MS4版本1中-2314291-2有九個傳感器用于:
運動(PIR)
溫度
濕度
光
運動(PIR)
溫度
聲音(麥克風)
VOC
CO2
MS4 Pinout
將ESP32連接到MS4
按如下方式將MS4連接到ESP32:
使用Arduino IDE設置ESP32
按照下面的屏幕截圖所示的步驟使用Arduino IDE對ESP32進行編程。
單擊文件》首選項
添加URL鏈接。您可以通過逗號分隔其他鏈接。
https://dl.espressif.com/dl/package_esp32_index.json
單擊 確定 。
單擊工具》板》板管理器
搜索 ESP32 并安裝包。
再次轉到 工具 并選擇 ESP32板 和 COM端口。
上傳源代碼
復制下面的源代碼,將其粘貼到Arduino IDE中,然后上傳。您可能需要在上傳過程中長按ESP32板上的啟動按鈕。
#include
unsigned char buf[20];
unsigned char opt_sensors;
int incomingByte = 0;
int loopCount = 0;
char showTemp = 0, showHum = 0, showLight = 0, showSound = 0, degCorf = 0, showCO2 = 0, showVOC = 0, showPwr = 0, showEvents = 0;
String sampPeriodTxt;
float sampPeriod = 1;
void setup() {
// put your setup code here, to run once:
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output monitor
}
void restart_info() {
// Data and basic information are acquired from the module
Wire.beginTransmission(0x2A); // transmit to device
Wire.write(byte(0x80)); // sends instruction to read firmware version
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(0x2A, 1); // request byte from slave device
unsigned char fw_ver = Wire.read(); // receive a byte
Wire.beginTransmission(0x2A); // transmit to device
Wire.write(byte(0x81)); // sends instruction to read firmware subversion
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(0x2A, 1); // request byte from slave device
unsigned char fw_sub_ver = Wire.read(); // receive a byte
Wire.beginTransmission(0x2A); // transmit to device
Wire.write(byte(0x82)); // sends instruction to read optional sensors byte
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(0x2A, 1); // request byte from slave device
opt_sensors = Wire.read(); // receive a byte
delay(1000);
//If device contains additional CO2 and audio sensor, it is indicated here
Serial.print(“AmbiMate sensors: 4 core”);
if (opt_sensors & 0x01)
Serial.print(“ + CO2”);
if (opt_sensors & 0x04)
Serial.print(“ + Audio”);
Serial.println(“ ”);
Serial.print(“AmbiMate Firmware version ”);
Serial.print(fw_ver);
Serial.print(“。”);
Serial.println(fw_sub_ver);
Serial.print(“Select which sensors to receive data from: ”);
Serial.print(“Temperature [Y/N]: ”);
while (Serial.available() == 0);
showTemp = Serial.read();
Serial.println(showTemp);
Serial.print(“deg C or F [C/F]: ”);
while (Serial.available() == 0);
degCorf = Serial.read();
Serial.println(degCorf);
Serial.print(“Humidity [Y/N]: ”);
while (Serial.available() == 0);
showHum = Serial.read();
Serial.println(showHum);
Serial.print(“Ambient Light [Y/N]: ”);
while (Serial.available() == 0);
showLight = Serial.read();
Serial.println(showLight);
if (opt_sensors & 0x04)
{
Serial.print(“Audio [Y/N]: ”);
while (Serial.available() == 0);
showSound = Serial.read();
Serial.println(showSound);
}
if (opt_sensors & 0x01)
{
Serial.print(“eCO2 [Y/N]: ”);
while (Serial.available() == 0);
showCO2 = Serial.read();
Serial.println(showCO2);
Serial.print(“VOC [Y/N]: ”);
while (Serial.available() == 0);
showVOC = Serial.read();
Serial.println(showVOC);
}
Serial.print(“Power [Y/N]: ”);
while (Serial.available() == 0);
showPwr = Serial.read();
Serial.println(showPwr);
Serial.print(“PIR and Motion Events [Y/N]: ”);
while (Serial.available() == 0);
showEvents = Serial.read();
Serial.println(showEvents);
Serial.print(“ ”);
Serial.print(“Sample Interval[Secs]: ”);
while (Serial.available() == 0);
sampPeriodTxt = “”;
while (Serial.available() 》 0)
{
int inChar = Serial.read();
sampPeriodTxt += (char)inChar;
}
Serial.println(sampPeriodTxt);
sampPeriod = sampPeriodTxt.toFloat();
if (sampPeriod 《 0.5)
{
sampPeriod = 0.5;
Serial.print(“Input exceeds limits, Sample period set to minimum, 0.5 seconds ”);
}
sampPeriod = sampPeriod * 1000; // convert to mSecs
}
//Top line of headings are printed using the following
void printLabels(void) {
Serial.println(“ ”);
Serial.println(“ ”);
// Construct the first line of the headings
if ((showTemp == ‘Y’) || (showTemp == ‘y’))
Serial.print(“Temperature ”);
if ((showHum == ‘Y’) || (showHum == ‘y’))
Serial.print(“Humidity ”);
if ((showLight == ‘Y’) || (showLight == ‘y’))
Serial.print(“Light ”);
if (opt_sensors & 0x04)
{
if ((showSound == ‘Y’) || (showSound == ‘y’))
Serial.print(“Audio ”);
}
if (opt_sensors & 0x01)
{
if ((showCO2 == ‘Y’) || (showCO2 == ‘y’))
Serial.print(“eCO2 ”);
if ((showVOC == ‘Y’) || (showVOC == ‘y’))
Serial.print(“VOC ”);
}
if ((showPwr == ‘Y’) || (showPwr == ‘y’))
Serial.print(“Power ”);
if ((showEvents == ‘Y’) || (showEvents == ‘y’))
Serial.print(“Event ”);
else
Serial.print(“ ”);
// Construct the second line of the headings
if ((showTemp == ‘Y’) || (showTemp == ‘y’))
{
if ((degCorf == ‘F’) || (degCorf == ‘f’))
Serial.print(“deg F ”);
else
Serial.print(“deg C ”);
}
if ((showHum == ‘Y’) || (showHum == ‘y’))
Serial.print(“% ”);
if ((showLight == ‘Y’) || (showLight == ‘y’))
Serial.print(“Lux ”);
if (opt_sensors & 0x04)
{
if ((showSound == ‘Y’) || (showSound == ‘y’))
Serial.print(“dB ”);
}
if (opt_sensors & 0x01)
{
if ((showCO2 == ‘Y’) || (showCO2 == ‘y’))
Serial.print(“PPM ”);
if ((showVOC == ‘Y’) || (showVOC == ‘y’))
Serial.print(“PPB ”);
}
if ((showPwr == ‘Y’) || (showPwr == ‘y’))
Serial.print(“volts”);
Serial.print(“ ”);
}
//Loop starts here
void loop() {
if (loopCount == 0)
{
restart_info();
loopCount = 1;
}
if (loopCount == 1)
{
printLabels();
loopCount = 2;
}
// All sensors except the CO2 sensor are scanned in response to this command
Wire.beginTransmission(0x2A); // transmit to device
// Device address is specified in datasheet
Wire.write(byte(0xC0)); // sends instruction to read sensors in next byte
Wire.write(0xFF); // 0xFF indicates to read all connected sensors
Wire.endTransmission(); // stop transmitting
// Delay to make sure all sensors are scanned by the AmbiMate
delay(100);
Wire.beginTransmission(0x2A); // transmit to device
Wire.write(byte(0x00)); // sends instruction to read sensors in next byte
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(0x2A, 15); // request 6 bytes from slave device
// Acquire the Raw Data
unsigned int i = 0;
while (Wire.available()) { // slave may send less than requested
buf[i] = Wire.read(); // receive a byte as character and store in buffer
i++;
}
// convert the raw data to engineering units, see application spec for more information
unsigned int status = buf[0];
float temperatureC = (buf[1] * 256.0 + buf[2]) / 10.0;
float temperatureF = ((temperatureC * 9.0) / 5.0) + 32.0;
float Humidity = (buf[3] * 256.0 + buf[4]) / 10.0;
unsigned int light = (buf[5] * 256.0 + buf[6]);
unsigned int audio = (buf[7] * 256.0 + buf[8]);
float batVolts = ((buf[9] * 256.0 + buf[10]) / 1024.0) * (3.3 / 0.330);
unsigned int co2_ppm = (buf[11] * 256.0 + buf[12]);
unsigned int voc_ppm = (buf[13] * 256.0 + buf[14]);
if ((showTemp == ‘Y’) || (showTemp == ‘y’))
{
if ((degCorf == ‘F’) || (degCorf == ‘f’))
Serial.print(temperatureF, 1);
else
Serial.print(temperatureC, 1);
Serial.print(“ ”);
}
if ((showHum == ‘Y’) || (showHum == ‘y’))
{
Serial.print(Humidity, 1);
Serial.print(“ ”);
}
if ((showLight == ‘Y’) || (showLight == ‘y’))
{
Serial.print(light);
Serial.print(“ ”);
}
if (opt_sensors & 0x04)
{
if ((showSound == ‘Y’) || (showSound == ‘y’))
{
Serial.print(audio);
Serial.print(“ ”);
}
}
if (opt_sensors & 0x01)
{
if ((showCO2 == ‘Y’) || (showCO2 == ‘y’))
{
Serial.print(co2_ppm);
Serial.print(“ ”);
}
if ((showVOC == ‘Y’) || (showVOC == ‘y’))
{
Serial.print(voc_ppm);
Serial.print(“ ”);
}
}
if ((showPwr == ‘Y’) || (showPwr == ‘y’))
{
Serial.print(batVolts);
Serial.print(“ ”);
}
if ((showEvents == ‘Y’) || (showEvents == ‘y’))
{
if (status & 0x80)
Serial.print(“ PIR_EVENT”);
if (status & 0x02)
Serial.print(“ AUDIO_EVENT”);
if (status & 0x01)
Serial.print(“ MOTION_EVENT”);
}
Serial.print(“ ”);
// all sensors except the CO2VOC sensor are scanned at this rate.
// CO2/VOC sensor is only updated in AmbiMate every 60 seconds
delay(sampPeriod - 100);
incomingByte = Serial.read();
if ((incomingByte == ‘R’) || (incomingByte == ‘r’))
{
//Serial.print(“Got R ”);
loopCount = 0;
}
}
上傳代碼后,點擊串行監視器。
選擇你想要的傳感器喜歡通過輸入‘ Y ’來選擇它。
您現在可以看到傳感器數據進來。
我希望這個超級傳感器模塊能夠為您未來的項目提供便利!
-
Arduino
+關注
關注
188文章
6479瀏覽量
188612 -
ESP32
+關注
關注
18文章
985瀏覽量
17872
發布評論請先 登錄
相關推薦
【AI技術支持】ESP32-S3外掛FLASH不能設置為80MHz問題處理

ESP32-S3-WROOM-1/ESP32-S3-WROOM-1U技術規格書
esp32和esp8266代碼共用嗎
esp8266和esp32區別是什么
esp32用什么軟件編程
ESP32-WROOM-32E、ESP32-WROOM-32D、ESP32-WROOM-32U 有什么區別?ESP32-WROOM-32 后綴字母代表的意思是?

ESP32能取代STM32嗎?哪個更好?

評論