---
title: "arduino-sns-demo"
url: "https://maker.wiznet.io/gemma/projects/arduino-sns-demo/"
markdown_url: "https://maker.wiznet.io/gemma/projects/arduino-sns-demo/md"
type: "UCC: User Created Content"
author: "Shane Hopcroft"
author_url: "https://github.com/hoppy1977/arduino-sns-demo/tree/master"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Shane Hopcroft"
original_url: "https://github.com/hoppy1977/arduino-sns-demo/tree/master"
published: "2023-05-03"
language: "en"
hardware: ["Arduino Ethernet Shield"]
likes: 0
views: 365
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# arduino-sns-demo

> Sends text messages to the specified phone numbers using AWS SNS.

Original author: Shane Hopcroft (source: https://github.com/hoppy1977/arduino-sns-demo/tree/master)

## Components

- **Arduino Ethernet Shield** x 1 ([docs](https://docs.arduino.cc/retired/shields/arduino-ethernet-shield-without-poe-module))

## Article

## Arduino SNS Demo

Sends text messages to the specified phone numbers using AWS SNS.

Arduino code taken from <https://github.com/tdicola/SMS_Pet_Food_Dish.>

```cpp
#include "sha1.h"
#include <Ethernet.h>
#include <HttpClient.h>
#include <RTClib.h>

// Dependencies:
// - RTClib Library
// https://github.com/adafruit/RTClib


// ===============
// Amazon AWS configuration
#define     AWS_ACCESS_KEY         "TODO:"											// Put your AWS access key here.
#define     AWS_SECRET_ACCESS_KEY  "TODO:"						// Put your AWS secret access key here.
#define     AWS_REGION             "ap-southeast-2"													// The region where your SNS topic lives.
																									// See the table at: http://docs.aws.amazon.com/general/latest/gr/rande.html#sns_region
#define     AWS_HOST               "sns.ap-southeast-2.amazonaws.com"								// The host URL for the region where your SNS topic lives.
																									// See the table at: http://docs.aws.amazon.com/general/latest/gr/rande.html#sns_region
#define     SNS_TOPIC_ARN          "arn%3Aaws%3Asns%3Aap-southeast-2%3A244360212732%3AArduionDemo"	// Amazon resource name (ARN) for the SNS topic to receive notifications.
																									// Note: This ARN _MUST_ be URL encoded!  See http://meyerweb.com/eric/tools/dencoder/ for an example URL encoder tool.
// ===============
// SHA1 hash details
#define     SHA1_HASH_LENGTH       20

// ===============
// MAC address for your Ethernet shield
byte mac[] = { 0x96, 0x97, 0xFC, 0x1D, 0xF4, 0xA2 }; // Randomly selected

EthernetClient client;

void setup()
{
	// Set up the serial port connection.
	Serial.begin(9600);
	Serial.println("Initializing...");

	// Setting up ethernet connection
	while (Ethernet.begin(mac) != 1)
	{
		Serial.println("Error getting IP address via DHCP, trying again...");
		delay(5000);
	}

	Serial.print("IP address: ");
	for (byte thisByte = 0; thisByte < 4; thisByte++)
	{
		// print the value of each byte of the IP address:
		Serial.print(Ethernet.localIP()[thisByte], DEC);
		Serial.print(".");
	}
	Serial.println();

	Serial.println("Ready...");
}
```

**How to use this code**

1. Setup of Arduino board, Ethernet shield, and SNS account: To use AWS SNS with Arduino, you need an AWS account and an SNS topic. You also need an Arduino board and an Ethernet shield. You need to set up and connect all of them.

2. Install Arduino IDE: Install and open the Arduino IDE.

3. Copy the code: Copy this code into the Arduino IDE.

4. Enter AWS account information: Update AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_HOST, and SNS_TOPIC_ARN to match your own account.

5. Install libraries: Install the required libraries in the Arduino IDE. The libraries used in this code are HttpClient, Ethernet, RTClib, and SHA1.

6. Select Arduino board: Select the Arduino board you are using.

7. Select port: Select the USB port.

8. Upload: Upload the code to the Arduino board.

9. Publish message: When the code runs on the Arduino board, the message is published to the SNS topic.

---

Source: https://maker.wiznet.io/gemma/projects/arduino-sns-demo/
