标签:
arduino 套件使用说明书V1.0.pdf,
步进电机
DHT11
传感器另外一脚要接A0
/* Web client This sketch connects to a website (http://www.google.com) using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen */ #include <SPI.h> #include <Ethernet.h> #define DHT11_PIN 1 // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // if you don‘t want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) char server[] = "192.168.1.95"; // name address for Google (using DNS) // Set the static IP address to use if the DHCP fails to assign IPAddress ip(192,168,99,177); // Initialize the Ethernet client library // with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): EthernetClient client; void uploadData(String c,String h){ // if you get a connection, report back via serial: if (client.connect(server, 6543)) { Serial.println("connected"); // Make a HTTP request: client.println("GET /DHT11Data.ashx?C="+c+"&h="+h+" HTTP/1.1"); client.println("Host:192.168.1.95"); client.println("Connection: close"); client.println(); delay(10); // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); Serial.print(c); } } else { // kf you didn‘t get a connection to the server: Serial.println("connection failed"); } // if the server‘s disconnected, stop the client: if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); // do nothing forevermore: } } byte read_dht11_dat() { byte i = 0; byte result = 0; for(i=0;i<8;i++) { while(!(PINC&_BV(DHT11_PIN))); delayMicroseconds(30); if(PINC&_BV(DHT11_PIN)) result|=(1<<(7-i)); while((PINC&_BV(DHT11_PIN))); } return result; } void setup() { DDRC|=_BV(DHT11_PIN); PORTC|=_BV(DHT11_PIN); // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip); } // give the Ethernet shield a second to initialize: delay(1000); Serial.println("Ready"); } void loop() { byte dht11_dat[5]; byte dht11_in; byte i; PORTC &= ~_BV(DHT11_PIN); delay(18); PORTC|=_BV(DHT11_PIN); delayMicroseconds(40); DDRC &= ~_BV(DHT11_PIN); delayMicroseconds(40); dht11_in = PINC & _BV(DHT11_PIN); if(dht11_in) { Serial.println("dht11 start condition 1 not met"); return; } delayMicroseconds(80); dht11_in=PINC & _BV(DHT11_PIN); if(!dht11_in) { Serial.println("dht11 start condition 2 not met"); return; } delayMicroseconds(80); for(i=0;i<5;i++) dht11_dat[i]=read_dht11_dat(); DDRC|=_BV(DHT11_PIN); PORTC|=_BV(DHT11_PIN); byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3]; if(dht11_dat[4]!=dht11_check_sum) { Serial.println("DHT11 checksum error"); } uploadData(String(dht11_dat[2]) +"." +String(dht11_dat[3]),String(dht11_dat[0]) +"." +String(dht11_dat[1]) ); Serial.print("Current humdity= "); Serial.print(String(dht11_dat[0])); Serial.print("."); Serial.print(dht11_dat[1],DEC); Serial.print("%"); Serial.print("temperature = "); Serial.print(dht11_dat[2],DEC); Serial.print("."); Serial.print(dht11_dat[3],DEC); Serial.println("C"); delay(1000); }
标签:
原文地址:http://www.cnblogs.com/wdfrog/p/4334236.html