1. http://asynclabs.com/forums/viewtopic.php?f=18&t=174
2.http://wiring.org.co/learning/basics/airqualitymq135.html
3.and some leds like here http://asynclabs.com/forums/viewtopic.php?f=18&t=104
how these sensors can be combine all together and see the measures in firefox ???
here is the code:
1.sht15.pde
- Code: Select all
/*
* Socket App
*
* A simple socket application example using the WiShield 1.0
*/
#include <WiShield.h>
#include <MsTimer2.h>
#include <SHT1x.h>
//jonoxer SHT15 lib
//http://github.com/practicalarduino/SHT1x/
//-------------------------------------------------------------------------------------------------
//
// WiShield data
//
//-------------------------------------------------------------------------------------------------
//Wireless configuration defines ----------------------------------------
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
//Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,10}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Key 3
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//
//define(s), declaration(s) and global state data
//
//-------------------------------------------------------------------------------------------------
//#define DEBUGPRINT
//The Arduino pin numbers corresponding to the analog pins are 14 through 19.
//Arduino analog input 4 = I2C SDA (pin 18)
//Arduino analog input 5 = I2C SCL (pin 19)
#define PIN_DATA 18
#define PIN_SCLK 19
//SHT15 set up and comm class init
SHT1x sht1x(PIN_DATA, PIN_SCLK);
//timer interrupt flag
volatile boolean intTimer;
//global temp (F) and humidity data
float g_temperature;
float g_humidity;
//-------------------------------------------------------------------------------------------------
//
// ISR code/handler for MsTimer2 interrupt
//
//-------------------------------------------------------------------------------------------------
//MsTimer2 timer ISR
void timerISR() {
intTimer = true;
}
//-------------------------------------------------------------------------------------------------
//
// Arduino setup() code
//
//-------------------------------------------------------------------------------------------------
void setup()
{
#ifdef DEBUGPRINT
//setup output for debugging...
Serial.begin(57600);
#endif //DEBUGPRINT
//set up global state data
intTimer = false;
g_temperature = 0;
g_humidity = 0;
//init the WiShield
WiFi.init();
//setup the MSTimer2 timerISR
MsTimer2::set(60000, timerISR);
MsTimer2::start();
}
//-------------------------------------------------------------------------------------------------
//
// Arduino loop() code
//
//-------------------------------------------------------------------------------------------------
void loop()
{
if(true == intTimer) {
intTimer = false;
//fetch data from the SHT15 (currently only using degrees F)
g_temperature = sht1x.readTemperatureF();
//returns a % value
g_humidity = sht1x.readHumidity();
#ifdef DEBUGPRINT
Serial.print("Temperature: ");
Serial.println(g_temperature);
Serial.print("Humidity : ");
Serial.println(g_humidity);
#endif //DEBUGPRINT
}
WiFi.run();
}
2.air sensor for simple arduino
- Code: Select all
int val;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}
void loop()
{
val = analogRead(0); // read analog input pin 0
Serial.print(val, DEC); // prints the value read
Serial.print(" "); // prints a space between the numbers
delay(100); // wait 100ms for next reading
}
3.led on off
- Code: Select all
/*
* A simple sketch that uses WiServer to serve a web page !! that kim messed with.
*/
#include <WiServer.h>
#include <string.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define ledPin1 5
#define ledPin2 6
#define ledPin3 7
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = { 10,1,1,5}; // IP address of WiShield
unsigned char gateway_ip[] = { 192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = { 255,0,0,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = { "DLINK"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = { "12345678"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;
void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = '\0';
if (test)
{
strcat(returnBuffer, "On");
}
else
{
strcat(returnBuffer, "Off");
}
}
void printStates()
{
for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
boolToString(states[stateCounter], stateBuff);
Serial.print("State of ");
Serial.print(stateCounter);
Serial.print(": ");
Serial.println(stateBuff);
}
}
void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}
// This is our page serving function that generates web pages
boolean sendPage(char* URL) {
Serial.println("Page printing begun");
printStates();
writeStates();
//check whether we need to change the led state
if (URL[1] == '?' && URL[2] == 'L' && URL[3] == 'E' && URL[4] == 'D') //url has a leading /
{
ledChange = (int)(URL[5] - 48); //get the led to change.
for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];
Serial.print("Have changed ");
Serial.println(ledChange);
}
}
//after having change state, return the user to the index page.
WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
return true;
}
if (strcmp(URL, "/") == false) //why is this not true?
{
WiServer.print("<html><head><title>Led switch</title></head>");
WiServer.print("<body><center>Please select the led state:<center>\n<center>");
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 - 3 rather than 0 - 2
numAsCharBuff[1] = '\0'; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.
tmpStrCat[0] = '\0'; //initialise string
strcat(tmpStrCat, "<a href=?LED"); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = '\0'; //terminate the string properly for later.
strcat(tmpStrCat, ">Led ");
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, ": ");
boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, "</a> "); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(tmpStrCat);
}
WiServer.print("</html> ");
return true;
}
}
void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
Serial.begin(9600);
WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
}