Ардуино Уно, SIM800L, DHT11, Ethernet shield- для отслеживания температуры и вне установленного предела для отправки SMS. У меня скетч не сработал, где ошибка?
-----------
Вот:
#include SoftwareSerial.h
#include String.h
#include EEPROM.h
#include Wire.h
#include SPI.h
#include Ethernet.h
#include dht.h
// pins definition
SoftwareSerial sim800l(7, 6); // actual RX, TX pins of SIM800l board
const int TestButton = 10; // internal pull-up activated, button is wired to GND, LOW when pressed
const int LEDPowerFailure = 9;
const int LEDTemperatureFailure = 4;
const int LEDLANFailure = 11;
const int LEDDiagnostics = 13; // internal LED for diagnostics
const int PowerSenseInput= A1; // from DC adapter via a voltage divider
const int DHT11Pin = 12; // DHT11 onewire pin
// failure definitions constants - bitwise
const int StateOk = 0;
const int StatePowerDownFailure = 1;
const int StateLANFailure = 2;
const int StateTemperatureFailure = 4;
const int StateTest = 8;
float TempSensorValue; // current temperature from sensor DHT11
float PowerSenseInputValue; // voltage after divider
int PingFailure = 0; // flag
int PingCountOk; // counter
int TestButtonState; // pressed LOW
int State = StateOk; // status of the net/temp/power/test
// User configurable variables (via source recompile and upload to Arduino board again)
// pinging
byte useDhcp = true;
byte useDns = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// these valus must be changed
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is false !!!
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false !!!
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false !!!
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false !!!
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false !!!
char serverName[] = "server1.tu-plovdiv.bg"; // Only if useDns is true !!!
// thresholds
const int TemperatureAlarmValue = 36; // over 36C - alarm
const int PingCountAlarmValue = 3; // over 3 lost packets - alarm
const float DCPowerAlarmValue = 0.5; // under 0.5 volts after voltage diveider - alarm
const float DCPowerVoltage = 9.0; // voltage of the power adaptor
EthernetClient Client; // Declare client object
dht DHT; // DHT object
void setup() // initialise ports/values
{
pinMode(TestButton, INPUT_PULLUP); // LOW when pressed
// LEDs - light on HIGH
pinMode(LEDPowerFailure, OUTPUT);
pinMode(LEDTemperatureFailure, OUTPUT);
pinMode(LEDLANFailure, OUTPUT);
pinMode(LEDDiagnostics, OUTPUT);
// initialise Serial and SIM800l
sim800l.begin(9600); // initialize SIM800l module at 9600 bps
Serial.begin(9600); // debug messages to serial monitor of Arduino IDE
delay(500); // wait for proper initialization of the SIM800l 500mS
}
void loop()
{
State = StateOk;
// check
TestButtonState = digitalRead(buttonPin); // if LOW - do diagnostic (Power failure simulation)
if (TestButtonState == LOW) { // test diagnostic SMS and PowerLow LED simulation
Serial.println("Diagnostics button pressed.");
State = State | StateTest;
}
// check temperature
int chk = DHT.read11(DHT11Pin);
if (chk == DHTLIB_OK) {
TempSensorValue = DHT.temperature;
if (TempSensorValue > TemperatureAlarmValue) {
State = State | StateTemperatureFailure;
Serial.print("Temperature overflow ");
Serial.println(TempSensorValue, 1);
}
}
// check power down state, read twice after 500ms to avoid brownouts
PowerSenseInputValue = analogRead(PowerSenseInput) * (DCPowerVoltage / 2.0) / 1024;
if (PowerSenseInputValue < DCPowerAlarmValue) {
delay(500); // wait for brownout 500mS
PowerSenseInputValue = analogRead(PowerSenseInput) * (DCPowerVoltage / 2.0) / 1024;
if (PowerSenseInputValue < DCPowerAlarmValue) {
State = State | StatePowerDownFailure;
Serial.println("Power down.");
}
}
// check ping state of the server
// ..
if (PingFailure) {
State = State | StatePowerDownFailure;
Serial.println("Ping failed - server is down.");
}
// process state
if (sim800l.available()){ // is SIM800l receive SMS or status - dump it back
Serial.write(sim800l.read());
}
}
void SendTextMessage()
{
Serial.println("Sending Text Message...");
//
sim800l.print("AT+CMGF=1\r"); // Set the shield to SMS mode
delay(100);
sim800l.print("AT+CMGS=\"+3591234567\"\r"); // put actual number here
delay(200);
//
sim800l.print("Failure is: ");
// ... by State...
sim800l.print("\r"); //the content of the message
delay(500);
sim800l.print((char)26); //the ASCII code of the ctrl+z is 26 (required ^Z at end of SMS)
delay(100);
sim800l.println();
Serial.println("Text Message Sent.");
delay(500);
}