Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include VirtualWire library
- #include <VirtualWire.h>
- #include <SoftwareSerial.h>
- SoftwareSerial SIM900(2, 3); // configure software serial port
- // Pins definition
- const int receive_pin = 9;
- int minSecsBetweenCalls = 30; // 0.5 min
- long lastSend = -minSecsBetweenCalls * 1000l;
- void setup()
- {
- SIM900.begin(19200);
- Serial.begin(19200);
- delay(20000); // give time to log on to network.
- digitalWrite(6, HIGH);
- delay(1000);
- digitalWrite(6, LOW);
- // software equivalent of pressing the GSM shield "power" button
- // Initialise the IO and ISR
- vw_set_rx_pin(receive_pin);
- vw_setup(4000); // Transmission rate
- // Start the receiver PLL
- vw_rx_start();
- // Set LED pin and Buzzer
- }
- void loop()
- {
- long now = millis();
- uint8_t buf[VW_MAX_MESSAGE_LEN];
- uint8_t buflen = VW_MAX_MESSAGE_LEN;
- // Check if a message was received
- if (vw_get_message(buf, &buflen))
- {
- if(buf[0]=='1')
- {
- if (now > (lastSend + minSecsBetweenCalls * 1000l))
- {
- Serial.println("Motion detected!");
- SIM900.println("ATD + +47xxxxxxxx;"); // dial number (language code between + and your phone number)
- lastSend = now;
- delay(100);
- SIM900.println();
- delay(30000); // wait for 30 seconds...
- SIM900.println("ATH"); // hang up
- }
- if(buf[0]=='0')
- {
- Serial.println("Motion ended!");
- delay(300);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement