This time we got rid of one Arduino and hooked a sensor directly to an XBee, while using the other XBee in API mode.
The idea: a noise sensor placed at a certain location is checking whether the sound is above a certain threshold, and if so, a message is displayed on an LCD that is placed at a different location, asking to lower the noise..
How to do it? A digital noise sensor is hooked to one of XBee's digital input pins(DIO0), which samples the data every 255ms and sends it to another XBee.
The other XBee is connected to an Arduino that has an LCD and that displays a message based on the input it receives.
We've encountered some problems with the Xbee reading the noise sensor and sending the data but in the end it seemed the problem was solved by connecting both the Xbee and the noise sensor to a 5-volt power source instead of 3.3V, and inverting the readings(1 for no noise, 0 for noise).
Video
Schematics
Materials used
- 1 Arduino Uno
- 2 XBees Explorer
- 2 XBee
- 2 Breadboards
- 1 Sound/Noise Sensor
- 1 LCD screen
Software needed
- X-CTU software: http://ftp1.digi.com/support/utilities/40003026_A.exe
Steps
- Set one XBee to Coordinator API mode
- Connect this Xbee to Arduino
- Connect the Arduino to LCD
- Set PAN ID to BBBB
- Set one XBee to Router AT mode
- Set PAN ID to BBBB in XTCU
- Set Destination address to Coordinator XBee in XTCU
- Set DIO-0 to Digital Input in XTCU
- Set Sampling Rate to 255 ms in XTCU
- Enable Channel Verification in XTCU
- Connect "Output" pin of Noise/Sound Sensor to Digital Input Output pin 0(DIO-0) of this Xbee
- Connect Xbee and Noise/Sound Sensor to 5V power source
- Code Arduino
Arduino Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// set the LCD address to 0x27 for a 20
chars 4 line display
// Set the pins on the I2C chip used for
LCD connections:
// addr,
en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5,
6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup() {
Serial.begin(9600);
lcd.begin(16, 2); // initialize the lcd for 16 chars 2
lines, turn on backlight
// Quick 3 blinks of backlight
for (int i = 0;
i < 3; i++) {
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); // finish with backlight on
// Write characters on the display
// Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0, 0); //Start at character 4 on line 0
lcd.print("Hello, noiseless");
lcd.setCursor(4, 1); //Start at character 4 on line 0
lcd.print("world !");
delay(1000);
}
void loop() {
// make sure everything we need is in the buffer
if (Serial.available() >= 21) {
// look for the start byte
if (Serial.read() == 0x7E) {
// read the variables that we're not
using out of the buffer
for (int i = 1; i <= 19; i++)
{
byte
discard = Serial.read();
Serial.print(i);
Serial.print(":");
Serial.println(discard,
HEX);
}
Serial.println();
// int
analogHigh = Serial.read();
// int
analogLow = Serial.read();
// int
analogValue = analogLow + (analogHigh * 256);
byte
digitalReading = Serial.read(); //hopefully 0 or 1 depending on value of reading
if (digitalReading == 0) { //Noise sensor triggered
lcd.clear();
lcd.setCursor(0,
0);
lcd.print("Quiet!! You'll ");
lcd.setCursor(0,
1);
lcd.print("wake up the baby !");
delay(3000);
} else
{
lcd.clear();
// Write characters on the display
// Cursor Position: (CHAR, LINE) start
at 0
lcd.clear();
lcd.setCursor(0,
0); //Start at character 4
on line 0
lcd.print("Hello, noiseless");
lcd.setCursor(4,
1); //Start at character 4
on line 0
lcd.print("world !");
}
}
}
}

No comments:
Post a Comment