Shawn hymel
Published © CC BY-SA

Super Friends Button

Send a text with an Arduino to tell your friends that they need to ASSEMBLE!

IntermediateFull instructions provided1,169
Super Friends Button

Things used in this project

Hardware components

SparkFun Cellular Shield
×1
SparkFun RedBoard
SparkFun RedBoard
×1
Arduino Stackable Headers
×1
Cellular Duck Antenna
×1
SMA to U.FL Cable
×1
9V Wall Adapter
×1
SparkFun SIM Card
×1

Story

Read more

Schematics

Super Friends Block Diagram

How to connect the Arduino with shield to the button and LED.

Code

Super_Friends.ino

C/C++
Upload it to an Arduino with an MG2639 Cellular Shield. Attach a button to pin 4 and press it to send a text to everyone on the super_friends list.
/****************************************************************
 * SuperFriends.ino
 * Shawn Hymel @ SparkFun Electronics
 * May 11, 2015
 *
 * Send a text message to all your super friends, telling them to
 * ASSEMBLE!
 *
 * Based on the work by Jim Lindblom.
 *
 * This code is beerware; if you see me (or any other SparkFun 
 * employee) at the local, and you've found our code helpful, 
 * please buy us a round!
 *
 * Distributed as-is; no warranty is given.
 ***************************************************************/

#include <SoftwareSerial.h>
#include <SFE_MG2639_CellShield.h>

// Write a very special message to your Super Friends
char message[] = "Super Friends, ASSEMBLE!!!";

// Add your Super Friends' numbers here.
const int NUM_FRIENDS = 4;
char *super_friends[] = { "17205551234",
                          "17205551234",
                          "17205551234",
                          "17205551234"};

// Pins
const uint8_t BUTTON_PIN = 4;
const uint8_t LED_PIN = 5;

// Global variables
uint8_t ret;
uint8_t led = LOW;

void setup()
{
  
  int i;
  
  // Set up pins
  pinMode(4, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, led);
  
  // Start the Serial port for debugging
  Serial.begin(9600);
  
  // Initialize cellular module
  ret = cell.begin();
  if ( ret <= 0 )
  {
    Serial.println("Unable to communicate with shield.");
    while(1);
  }
  
  // Delay to allow module to warm up
  delay(2000);
  
  // Set SMS to text mode
  sms.setMode(SMS_TEXT_MODE);
  Serial.println("Ready to make the call");
  
  // Have button light slowly come on
  stopBlink();
}

void loop()
{
  
  int i;
  
  // Wait for a button push and release
  if ( digitalRead(BUTTON_PIN) == 0 )
  {
    do
    {
      delay(10);
    }
    while ( digitalRead(BUTTON_PIN) == 0 );
  
    // Send a text message to all your Super Friends!
    Serial.println("Dialing out to Super Friends.");
    slowBlink();
    for ( i = 0; i < NUM_FRIENDS; i++) {
      Serial.print("Sending message to: ");
      Serial.print(super_friends[i]);
      Serial.print(" ... ");
      sms.start(super_friends[i]);
      sms.print(message);
      ret = sms.send();
      if ( ret ) 
      {
        Serial.println("Success!");
      }
      else 
      {
        Serial.print("Send fail. Error: ");
        Serial.println(ret);
        fastBlink();
        delay(1000);
      }
    }
    Serial.println("Done. Now, go assemble!");
    stopBlink();
  }
}

void slowBlink()
{
  
  // Set interrupt to occur every 500 milliseconds
  // http://www.instructables.com/id/Arduino-Timer-Interrupts
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 7812;
  TCCR1B |= (1 << WGM12) | (1 << CS12) | (1 << CS10);
  TIMSK1 |= (1 << OCIE1A);
  sei();
}

void fastBlink()
{
  
  // Set interrupt to occur every 100 milliseconds
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 1562;
  TCCR1B |= (1 << WGM12) | (1 << CS12) | (1 << CS10);
  TIMSK1 |= (1 << OCIE1A);
  sei();
}

void stopBlink()
{
  
  int i;
  
  // Disable timer compare interrupt
  TIMSK1 &= ~(1 << OCIE1A);
  
  // Have LED slowly come on
  for ( i = 0; i < 256; i++ ) {
    analogWrite(LED_PIN, i);
    delay(5);
  }
  led = HIGH;
  digitalWrite(LED_PIN, led);
}

ISR(TIMER1_COMPA_vect)
{
  led = abs(led - 1);
  digitalWrite(LED_PIN, led);
}

Credits

Shawn hymel

Shawn hymel

10 projects • 77 followers
Engineering Superhero at SparkFun Electronics.

Comments