SMS Text Temp Alerts From an ATTINY85 and A1 GSM
by scanos in Circuits > Remote Control
4284 Views, 8 Favorites, 0 Comments
SMS Text Temp Alerts From an ATTINY85 and A1 GSM
This instructable shows you how to capture the temperature from a simple temperature sensor and send it by sms text to your mobile phone. To simplify things, I send the temperature at a set interval but I also show how this can be done only by exception / alerts. The hardware is very low cost, less than 10 dollars, although there are the recurring sms costs to consider.
The heavy lifting is undertaken by the simple but powerful ATTINY 85 which captures the temperature data and then triggers an SMS to be sent through an AI-Thinker A6 GSM module.
In short, you write the ATTINY85 code in the Arduino IDE environment and burn it on the ATTINY85 using an USBASP serial/USB convertor. I have covered setting up the AI-Thinker A6 GSM module and Arduino IDE in two previous tutorials. What's different here is interfacing the ATTINY and A6 GSM module using serial communications.
https://www.instructables.com/id/How-to-Send-an-SM...
https://www.instructables.com/id/15-Dollar-Attiny8...
After programming, the ATTINY reads the temperature data from a thermometer sensor - Dallas 18B20- and then sends the data and commands by serial connection to the A6 GSM module which then sends it as an SMS text to your mobile / smart phone.
Here's what you need:
1. USBASP serial/USB convertor.
2. ATTINY 85.
3. AI-Thinker A6 GSM module version 6 (with a sim which has SMS credits).
4. 3.3v breadboard power supply for the ATTINY85.
5. 3.3.v USB power supply for the AI-Thinker A6 GSM module.
6. Dallas 18B20 temperature sensor..
7. 4.7k resistor for the 18B20 sensor.
8. Breadboard and cables.
9. Arduino IDE (I used version 1.8.5. for this).
10. Windows X laptop ( I used version 10) with a free usb port.
Programming the ATTINY 85
Here is the Arduino IDE code (You will have to change the phone number to which you want to send the SMS.)
#include <br>#include #include
// *** // *** Define the RX and TX pins. Choose any two // *** pins that are unused. Try to avoid D0 (pin 5) // *** and D2 (pin 7) if you plan to use I2C. // *** #define RX 3 // *** D3, Pin 2 #define TX 4 // *** D4, Pin 3
// *** // *** Define the software based serial port. Using the // *** name Serial so that code can be used on other // *** platforms that support hardware based serial. On // *** chips that support the hardware serial, just // *** comment this line. // ***
SoftwareSerial mySerial = SoftwareSerial(RX, TX);
// *** // *** Pinout ATtiny25/45/85: // *** PDIP/SOIC/TSSOP // *** ============================================================================================= // *** // *** (PCINT5/RESET/ADC0/dW) PB5 [1]* [8] VCC // *** (PCINT3/XTAL1/CLKI/OC1B/ADC3) PB3 [2] [7] PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2) // *** (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4 [3] [6] PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1) // *** GND [4] [5] PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0) // *** // ATTINY 85 frequency set at internal 8 MHz
// *** // *** Pin on which the OneWire data // *** wire is connected. // *** #define ONE_WIRE_BUS 1
// *** // *** Setup a oneWire instance to communicate with any OneWire // *** devices (not just Maxim/Dallas temperature ICs). // *** OneWire _oneWire = OneWire(ONE_WIRE_BUS);
// *** // *** Pass our oneWire reference to Dallas Temperature. // *** DallasTemperature _sensors = DallasTemperature(&_oneWire);
void setup() { // *** // *** Initialize the Serial port // *** mySerial.begin(115200); delay(60000);
// *** Start up the library. _sensors.begin(); }
void loop() {
// *** // *** Get the current temperature and display it. // *** _sensors.requestTemperatures(); delay(2000); double tempC = _sensors.getTempCByIndex(0); double tempF = _sensors.getTempFByIndex(0); // check for errors - sometimes at start, temp shown as 85C
if (tempC <= 14){SMS_temp(tempC," DANGEROUSLY Cold");} if (tempC > 14 && tempC <= 18) {SMS_temp(tempC," Quite Cold");} if (tempC > 18 && tempC < 23) {SMS_temp(tempC," Temp Just right");} if (tempC >= 23 && error_temperature){SMS_temp(tempC," Too warm");} }
void SMS_temp(double mytemp,String myalert) { mySerial.println("AT+CMGF=1"); //set to SMS mode delay(1000); mySerial.println("AT+CMGF=1"); //set to SMS mode delay(1000); //mySerial.println("AT+CMGS=\"+YOUR NUMBER\""); //set the phone number (wrapped in double quotes) delay(1000); mySerial.print(mytemp, 1); mySerial.print(myalert); delay(1000); mySerial.write(0x1A); // sends ctrl+z end of message delay(1000); mySerial.write(0x0D); // Carriage Return in Hex delay(1000); mySerial.write(0x0A); delay(1000000); // 17 minutes - adjust to suit your own application }
Open the Arduino IDE environment - I have described how to find you way around this in detail in my previous instructable to which I alluded earlier.
You will need the following libraries
SoftwareSerial.h
OneWire.h
DallasTemperature.h
Next, configure the RX and TX pins on the ATTINY85 which you need to connect with the A1 Thinker. The ATTINY 85 has 8 pins , four on each side and is aligned using the dot on the surface a s a reference. Pin 1 or RESET pin is beside thte dot.
(in this case I chose Pin2 and 3 - These are on the same side as the RESET pin which is beside the dot on the surface of the ATTINY 85 . Pin 2 is the next pin along from the RESET pin whilst Pin 3 is between Pin 2 and GROUND)
Next, you have to configure the temperature sensor -
#define ONE_WIRE_BUS 1
OneWire _oneWire = OneWire(ONE_WIRE_BUS);
DallasTemperature _sensors = DallasTemperature(&_oneWire);
Next set up the software serial port
mySerial.begin(115200);
delay(60000);
and then call the sensors with _sensors.begin();
Next, there is the loop, which polls around at a pre-determined time, records the temperature and sends a message / alert depending on the value. It uses a function SMS_temp which also is where you set the timing of the loop
void loop()
{ sensors.requestTemperatures(); delay(2000);
double tempC = _sensors.getTempCByIndex(0);
double tempF = _sensors.getTempFByIndex(0);
if (tempC <= 14){SMS_temp(tempC," DANGEROUSLY Cold");}
if (tempC > 14 && tempC <= 18) {SMS_temp(tempC," Quite Cold");}
if (tempC > 18 && tempC < 23) {SMS_temp(tempC," Temp Just right");}
if (tempC >= 23 && error_temperature){SMS_temp(tempC," Too warm");}
}
==============
Next, set up the Arduino IDE to prepare for uploading to the ATTINY85.
A number of things to note
1- If you don't have the ATTINY family of boards, add the following url https://raw.githubusercontent.com/damellis/attiny/... in File/Preferences/Additional Boards Manager URL,
Next, within the Arduio IDE click on Tools/Board/Board Manager and search for ATTINY and install the new board. Change the processor to Attiny85.
Uploading the Program to the ATTINY85
Also, refer to my previous instructable on this - https://www.instructables.com/id/15-Dollar-Attiny8...
The ATTINY85 has two modes, programming and operations mode, respectively.
1. PROGRAMMING MODE Firstly, identify the pins on the ATTINY85. To do this, find the little notch on the surface of the chip which is beside the RST/RESET pin. Using this as a reference point, you can identify the rest of the pins. All of this information is provided in the A85 data sheet -http://ww1.microchip.com/downloads/en/DeviceDoc/At...
The USBasp and ATTINY85 should be connected as shown in the image above.
Next, on the Arduino IDE, set the programmer to USBasp and the frequency to internal 8Mhz.
Connect the USBasp to a USB port on your laptop (On Windows 10, if you don't have the USBasp driver use Zadig as per the website http://www.fischl.de/usbasp/ )
Next, with the USBasp connected, select from the Arduino IDE Sketch/upload and hopefully you should see the upload progress shown in red letters of the Arduino IDE and ending with avrdude done. Thank you.
Any errors at this stage are usuall associated with loose cables or the wrong driver.
Running Your Program
Firstly, something about the Dallas 18b20 thermometer sensor. It has 3 pins, Ground (G), data (D) and VCC as shown in the image above. For operation, it requires bridging the D and VCC with a 4.7k resistor. G and VCC are connected to respective poles whilst D is connected to an ATTINY 85, pin - [6] PB1, as configured in the code.
Next, connect the ATTINY to A6 GSM as follows (and shown above)
ATTINY TX <------> A6 UART_RXd
ATTINY RX <------> A6 UART_TXd
ATTINY GND <------> A6 GND
and on the A6 itself,
A6 PWR <-----------> A6 VCC 5.0
A6 RST <-------------> A6 GND (Do not connect to ground yet!!!!!)
Now power up both devices, and after a few seconds, touch temporarily the A6 ground pin with the cable connected to the A6 RST pin. The A6 will power off and on and hopefully, you should soon receive temperature data on your phone.
Conclusion
This instructable may seem rather simple but the idea is to illustrate what may be achieved with low cost components. Obviously, if you have access to wi-fi or a BLE hub then there are more appropriate solutions.
I didn't cover other functionality such as sending an SMS TO the phone to initiate temperature recording / transmission etc.