Electronics and Programming

From Medialab Prado

Jump to: navigation, search

Electronics

Things you need

2 Arduino Modules [www.arduino.cc]

2 XBEE Arduino Shields

1 Temperature Sensor

1 GPS Shield for Arduino

1 General Air quality Sensor

Any other sensor you want to add to Arduino.


Software

Processing [get it from http://www.processing.org]

EEML Library for Processing [get it here]

Sign up and get an account at Pachube.com


Other

A connection to the Internet


Building the Hardware

Let's call the two Arduino'sArduino(Transmittor) and Arduino(Recievor).

Mount the XBEE and the sensors on Arduino(Transmittor) and mount the other XBEE on the Arduino(Recievor).

When you mount it on XBEE reciver, make sure you remove the Mircroprocesor on the Arduino Board.

Switch the Jumper settings on Arduiono(Recievor) to USB.

Switch the Jumper settings on Arduino(Transmittor) to XBEE.

Connect the GPS sensor, Temperature sensor and other sensors to Arduino(Transmittor).

Load Firmata on Arduino(Transmittor). See this tutorial here on how to do this ---> [1]

The XBEE on the Arduino(Recievor) needs to have its address configured. The tutorial above will show you how to do this


Test if the communication between the arduino's works, you can load this simple program to processing and check.

connect a LED to pin 13 of Arduino(Transmitor) and see if it blinks when you upload the code below to Processing.


----------------------------------------------------------------------------------------------------------

import processing.serial.*; import cc.arduino.*;
Arduino arduino; int ledPin = 13;
void setup() {
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0]); // v2
//arduino = new Arduino(this, Arduino.list()[0], 57600); // v1
arduino.pinMode(ledPin, Arduino.OUTPUT);
}
void draw() {
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
}
________________________________________
If the LED Blinks then the two XBEE's are talking to each other!
For the next step you need to connect all the sensors to the Arduino(Transmitor) and then make the appropriate changes in the code given below
________________________________________


// This piece of Code sends out values from the Globos device to Pachube. // Globus communicates with another arduino connected to the Internet using XBEE.


import processing.serial.*;
import cc.arduino.*;
import eeml.*;
Arduino arduino; int ledPin = 13; // This is a test LED that makes sure Data is being transmitted
int CarbonMonoxidePin = 0; // We don't have a specific CarbonMonoxide Pin but as of now, we're measuring general air quality
int CarbonMonoxideValue = 0; // This is the actual value that we're reading from the Pin
int TempHumidityDataPin = 6; // This is the Data Pin for the SHTI5 temperature and humidity sensor
int TempHumidityClockPin = 7; // This is the Clock Pin for the SHT15 temperature and humidity sensor int TestPin = 1; // This is a test Pin
to make sure that everything is working
int TestPinValue = 0; // This is the value of the test Pin
int TemperatureValue = 20;
String GPSValue = "4140.000,N,00053.000,W,0197,22,10,2007,11,40,00" ;// Test GPS Value

int GPSrxPin = 2; // The rx Pin for the GPS module
int GPStxPin = 3; // The tx Pin for the GPS module

// These are the various variables for the GPS modules
byte byteGPS = 0;
int i = 0;
int[] indices = new int[13];
int cont = 0; int conta = 0; char[] inBuffer = new char[300]; int k = 0;

DataOut dOut; // This opens up the connection to Pachube


void setup() {
//println(Arduino.list());
//arduino = new Arduino(this, Arduino.list()[0]); // v2

arduino = new Arduino(this, Arduino.list()[0], 9600); // v1 // XBEE needs to transmit at 9600 bytes
arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(CarbonMonoxidePin, Arduino.INPUT);
dOut = new DataOut(this, 5210);
dOut.addData(0,"CarbonMonoxide Level, device:Globus0,Location:MediaLabPrado, Madrid");// This sends the CarbonMonoxide level through Pachune and EEML
dOut.addData(1,"Temperature, device:Globus0,Location:MediaLabPrado, Madrid"); //" " " Temperature " " "
dOut.addData(2,"GPS Readings, device:Globus0,Location:MediaLabPrado, Madrid");// " " " Humidity " " "
// Setup the GPS sensor for reading and writing
arduino.pinMode(GPSrxPin,Arduino.INPUT);
arduino.pinMode(GPStxPin,Arduino.OUTPUT);
println("Configurando GPS...");
delay(1000);
println("$PSTMNMEACONFIG,0,4800,1,1"); // configure NMEA sentences to show only GGA sentence
delay(1000);

// command for setting time and position
println("$PSTMINITGPS,4140.000,N,00053.000,W,0197,22,10,2007,11,40,00");
// "4140.000,N" means: Latitude 41º40'00.0" North
// "00053.000,W" means: Longitude 0º53'00.0" West
// "0197" means 197 m elevation
// "22,10,2007,11,40,00" means date and time (October 22, 2.007 - 11h 40min 00sec UTC time)
}
void draw() {
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
CarbonMonoxideValue=arduino.analogRead(CarbonMonoxidePin);
println(" The Value of Carbon dioxide is: " +CarbonMonoxideValue);
println(" The Position of Globus is at: " + GPSValue);
println(" The Temperature outside is: " + TemperatureValue);
// Reading and Priniting the Values from the GPS sensor /* byteGPS = 0;
i = 0;
while(byteGPS != 42){ // read the GGA sentence
byteGPS = byte(arduino.digitalRead(GPSrxPin)); // don't know if this will work
inBuffer[i]=char(byteGPS);
i++;
}

k = 1;
while(inBuffer[k] != 42){
print(inBuffer[k]); // write the GGA sentence
k++;
}
println();
delay(3000);

/
}
// Down Here, We update the Values for Pachube
void onReceiveRequest(DataOut d){
d.update(0,CarbonMonoxideValue);
d.update(1,TemperatureValue);
d.update(2,GPSValue);

}
----------------------------------------------------------------------------------------------------------



Personal tools