Simple stuff, but here it is:
//Single Servo Servo controlled by Xbee after receiving character commmand
*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0;
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
void setup()
{
XBee.begin(9600);
Serial.begin(9600);
myservo.attach(9);
}
void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
while (Serial.available ()>0) {
char incomingByte = Serial.read();
Serial.println(incomingByte);
if(incomingByte=='1'){
for(pos = 90; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=90; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
}
wireless earth watchdogs
Sunday, March 6, 2016
Friday, March 4, 2016
sodium launcher with xbee's
Launcher. Servo run by arduino receives command via xbee.
Friday, December 25, 2015
Arduino Ethernet Shield and Xbee
This summer I worked with the folks at the Chattanooga Public Library's 4th Floor Lab and we've now got a basic sketch that integrates the Arduino Ethernet Shield with XBee Communication. I've searched high and low for someone to post an Arduino sketch that integrates them, but I haven't found one. Well, if you too have been looking, here it is! I used this some a few months ago to post some sensor data that was being logged several hundred feet away in the field and sent via XBee 1 to XBee 2 stacked with the Arduino Ethernet Shield. There's plenty of html code changes you can add or change to make your 1990's-looking webpage better. Hope it's useful! Merry Christmas!
#include <SoftwareSerial.h>
client.println();
*/
#include <SPI.h>
#include <Ethernet.h>#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's
Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software
TX)
SoftwareSerial XBee(2, 3); // RX, TXint ReadingNumber=0;
char
link[]="wirelessearthwatchdawgs.blogspot.com"; //link data
// Enter a MAC address and IP address for your controller
below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x90, 0xA2, 0xDA,
0x0D, 0xA8, 0x6B
};
IPAddress ip(192,168,1,120
);
//IPAddress ip(172, 16, 100, 120);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(8081);
void setup() {
// Open serial
communications and wait for port to open:
Serial.begin(1200);
XBee.begin(1200);
while (!Serial) {
; // wait for
serial port to connect. Needed for Leonardo only
}
// start the
Ethernet connection and the server:
Ethernet.begin(mac,
ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for
incoming clients
EthernetClient
client = server.available();
if (client) {
Serial.println("new client");
// an http request
ends with a blank line
boolean
currentLineIsBlank = true;
while
(client.connected()) {
if
(client.available()) {
char c =
client.read();
Serial.write(c);
// if you've
gotten to the end of the line (received a newline
// character)
and the line is blank, the http request has ended,
// so you can
send a reply
if (c == '\n'
&& currentLineIsBlank) {
// send a
standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after
completion of the response
client.println("Refresh: 5");
// refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");client.println();
//set
background to yellow
client.print("<body style=background-color:yellow>");
//send first
heading
client.println("<font color='red'><h1>My Web
Title</font></h1>");
client.println("<hr />");
client.println("<hr />");
//output
some sample data to browser
client.println("<font color='blue' size='5'>Sample
data:w/m2");
// output
the value of each analog input pin
boolean
xbeenewline = false; // initialize boolean variable to keep track if a new line
has been seen.
while
(xbeenewline == false) { //when
this is false; a new line hasn't been seen;
char c =
XBee.read (); // render it as
characters, rather than as integers.
if (c ==
'\n') { // if c hits the ASCII
symbol for new line
xbeenewline = true; // it's true
that the server sees a new line from the xbee feed
boolean
newxbeenewline = false; // initialize a
variable that will serve as the recognition of the end of a line of data
while
(newxbeenewline == false) { // keep
reading data, we arent' at the end of the line yet
char c
= XBee.read();
if (c
== '\n') { // but when we see
the symbol for end of line
newxbeenewline = true; // we're
done reading data
} else
if (c != -1) { // -1 is the value
for nothing sent by xbee, so don't print it
client.print(c);
delay (1);
}
}
client.println ("<br/>"); //(“<br
/>”);
client.println ("<hr/>");
client.println ("<font color='blue' size='5'>Link:
"); //(“<font
color=’blue’ size=’5′>Link: “);
client.print ("<a
href="); //(“<a
href=”);
client.print(link);
client.println( ">Visit
our Project Site!</a>");
//(“>Visit Scienceprog!</a>”);
client.println ("<br/>"); //(“<br />”);
client.println ("<hr/>"); //(“<hr
/>”);
}
}
client.println("</html>");
break;
}
if (c == '\n')
{
// you're
starting a new line
currentLineIsBlank = true;
}
else if (c !=
'\r') {
// you've
gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web
browser time to receive the data
delay(1);
// close the
connection:
client.stop();
Serial.println("client disconnected");
}
}
Friday, July 3, 2015
Getting those final test runs in
After a few days in the garbage pail simulation, I figured we'd get a realistic current usage for 24 hours with all the circuitry running. We put a Vernier current logger in line and took readings every 6 minutes. Vernier has a good statistics function so I could get the total consumption over the day (the integral- for all you calculus folks). Pretty much was as predicted ~.84 amps/day. Definitely puts us comfortably in the zone for leaving the station for a month with a 42 amp-hour battery (50 days, in theory). . There's enough room in the box to put two batteries in parallel for a seasonal duty cycle, but we'll hold off on that until this project proves it's mettle over a 30 day field test.
Wednesday, July 1, 2015
Water buoy-proof of concept phase
Testing it out in a municipal waste bin filled with water- water goes up and down with the rain and some occasional hose input. Decided to put the steel pipe aside and go for schedule 80 PVC held with three pieces of rebar at 120 degrees separation each driven well into the creek bed. I couldn't imagine doing this in anything bigger than very small tributaries with such a design, but that's what we're testing. Looking to get it out in a few days. Have a couple of ideas for securing the battery and for providing a bit of ventilation for the hydrogen gas that would emit.
Friday, January 30, 2015
Cutting Pipe for our Buoy Design
The idea is to have a dense foam cylinder inside a pipe in the stream that rises and falls with the stream level. The pipe is vertical, and held by rebar, big rebar. The probes will stick out of the cylinder while the cables go up into a sealed, watertight box where all the circuitry and battery are stored. I'll try to have a diagram out soon. Pipe is expensive.
Monday, December 1, 2014
Francophone readers and commenters welcome
I've noticed that a fair number of blog guests are from the Francophone world, mostly France. While I can't say that I'm an absolute master of the language (to say the least!), I d speak it fairly well and welcome any feedback or questions in the language. Ce serait avec plaisir, mais veuillez m'excuser si mon ecriture est plein de fautes grammatiques.
Subscribe to:
Posts (Atom)