无线传感器网络实验3

  • 格式:docx
  • 大小:305.46 KB
  • 文档页数:8
实验报告
实验名称光照温度和湿度传感器控制
课程名称无线传感器网络实验
院 系 部:专业班级:
学生姓名:学 号:
同 组 人:学 号:
指导教师:成 绩:
实验日期:2015年5月5日
华北电力大学
一、实验目的及要求
了解一下温度和湿度传感器的运行原理及数据处理过程。测定温度和湿度值的传感器。
二、实验仪器
主电脑、一个Mote设备、ISP工具、USB连接线
*/
event result_t Timer.fired() {
return call ADC.getData();
}
/**
* Signalled when the reset message counter AM is received.
* @return The free TOS_MsgPtr.
{
atomic {
currentMsg ^= 0x1;
}
call Leds.yellowToggle();
}
}
/**
* Signalled when data is ready from the ADC. Stuffs the sensor
* reading into the current packet, and sends off the packet when
packetReadingNumber = 0;
pack->lastSampleNumber = readingNumber;
}
pack->channel = 1;
pack->sourceMoteID = TOS_LOCAL_ADDRESS;
/* Try to send the packet. Note that this will return
* failure immediately if the packet could not be queued for
* transmission.
*/
if (call DataMsg.send(TOS_UART_ADDR, sizeof(struct OscopeMsg),
&msg[currentMsg]))
post dataTask();
}
}
if (data > 0x0300)
call Leds.redOn();
else
call Leds.redOff();
return SUCCESS;
}
/**
* Signalled when the previous packet has been sent.
* @return Always returns SUCCESS.
uint16_t readingNumber;
TOS_Msg msg[2];
uint8_t currentMsg;
/**
* Used to initialize this component.
*/
command result_t StdControl.init() {
call Leds.init();
includes OscopeMsg;
module OscilloscopeM
{
provides interface StdControl;
uses {
interface Timer;
interface Leds;
interface StdControl as Senso
call Leds.yellowOff(); call Leds.redOff(); call Leds.greenOff();
//turn on the sensors so that they can be read.
call SensorControl.init();
call CommControl.init();
*/
event TOS_MsgPtr ResetCounterMsg.receive(TOS_MsgPtr m) {
atomic {
readingNumber = 0;
}
return m;
}
}
五、实验现象
经USB连接,经过对程序的编译即将其下载到节点,得到以下的图片。发现改变其温度会得到波动性变化显著地图形。可见传感器对温度还是比较敏感的。
pack = (struct OscopeMsg *)msg[currentMsg].data;
pack->data[packetReadingNumber++] = data;
readingNumber++;
dbg(DBG_USR1, "data_event\n");
if (packetReadingNumber == BUFFER_SIZE) {
interface StdControl as CommControl;
interface SendMsg as DataMsg;
interface ReceiveMsg as ResetCounterMsg;
}
}
implementation
{
uint8_t packetReadingNumber;
* @return Always returns SUCCESS.
*/
command result_t StdControl.start() {
call SensorControl.start();
call Timer.start(TIMER_REPEAT, 125);
call CommControl.start();
1-4
经USB连接,经过对程序的编译即将其下载到节点,得到以下的图片。发现改变其光照会得到波动性变化显著地图形。可见传感器对光照还是比较敏感的。
1-5
六、讨论与结论
图上显示的是温度,如何将其改成湿度。修改程序的定义即可
对于已经知道波形的传感器如何衡量其温度的敏感度是否符合要求。
*/
event result_t DataMsg.sendDone(TOS_MsgPtr sent, result_t success) {
return SUCCESS;
}
/**
* Signalled when the clock ticks.
* @return The result of calling ADC.getData().
atomic {
currentMsg = 0;
packetReadingNumber = 0;
readingNumber = 0;
}
dbg(DBG_BOOT, "OSCOPE initialized\n");
return SUCCESS;
}
/**
* Starts the SensorControl and CommControl components.
三、实验原理
照度传感器通过周围关照的改变而改变其电阻值。
1-1
把可以测定周围温度及湿度值传感器直接连接在CPU上。电路原理如下图所示:
1-2
为了读取测定的传感器值,通过与CPU连接的2条线,输入一定的时钟和指令,下图显示了在CPU中能够从传感器接受以测定的数据的时钟计时器和命令的输入方式。
1-3
四、实验程序
return SUCCESS;
}
/**
* Stops the SensorControl and CommControl components.
* @return Always returns SUCCESS.
*/
command result_t StdControl.stop() {
call SensorControl.stop();
* BUFFER_SIZE readings have been taken.
* @return Always returns SUCCESS.
*/
async event result_t ADC.dataReady(uint16_t data) {
struct OscopeMsg *pack;
atomic {
call Timer.stop();
call CommControl.stop();
return SUCCESS;
}
task void dataTask() {
struct OscopeMsg *pack;
atomic {
pack = (struct OscopeMsg *)msg[currentMsg].data;