Sunday, March 6, 2016

The Sodium Launcher Arduino/Xbee Sketch...

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
  }

   }

}
}

Friday, March 4, 2016

sodium launcher with xbee's


Fun little project. Sodium blowup demonstration covers a lot of ground in chemistry: molarity, acid/base, logarithms,ph, periodic trends, stoichiometry. We work out the predicted ph of the bucket of water after the sodium reacts and makes sodium hydroxide. Thought it would be fun to put together a simple radio controlled sodium launcher with a pair of xbee's signalling a servo motor to drop the sodium - for safety, of course.







           Launcher.  Servo run by arduino receives command via xbee.