Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
Happy New Year for all makers around the world.
How can we do mkr1000 as Christmas tone player? I will show you how you can do it.
You need: Arduino, mkr1000, Piezo buzzer and an Android phone.
DemoCircuitThe buzzer needs one digital pin and GND pin (see schematic below).
Code your mkr1000Download mkr1000 code and put your network SSID and password then upload your code:
Step 1: Download Evothings studio for your PC.
Step 2: Get your Cloud ID.
Step 3: Download Evothings viewer for your Android phone.
Step 4: Open your Evothings studio and create a new app.
When you create the app, download and replace the code from Github repository.
Step 5: Go to connect section and enter your cloud ID, then get your key.
Step 6: Run Evothings viewer and put the key, then connect.
Step 7: Run your app from Evothings studio by clicking RUN.
Please get the mkr1000 IP address by clicking Serial Monitor in Arduino IDE, then enter your IP.
mkr1000 code
ArduinoTools: arduino mkr1000, piezo buzzer, android phone and evothings studio.
Copyright: open source.
/*
** Project name: mkr1000 IoT christmas player.
** Tools: arduino mkr1000, piezo buzzer, android phone and evothings studio.
** Copyright: open source.
*/
// Include files.
#include <SPI.h>
#include <WiFi101.h>
// Your network SSID (network name).
// TODO: Enter the name of your wifi network here.
char ssid[] = "network name";
// Your network password.
// TODO: Enter the password of your wifi network here.
char pass[] = "network password";
// Your network key Index number (needed only for WEP).
//int keyIndex = 0;
// Server status flag.
int status = WL_IDLE_STATUS;
// Create WiFi server listening on the given port.
WiFiServer server(3300);
void setup()
{
// Start serial communication with the given baud rate.
// NOTE: Remember to set the baud rate in the Serial
// monitor to the same value.
Serial.begin(9600);
// Wait for serial port to connect. Needed for Leonardo only
while (!Serial) { ; }
// Check for the presence of the WiFi shield.
if (WiFi.status() == WL_NO_SHIELD)
{
// If no shield, print message and exit setup.
Serial.println("WiFi shield not present");
status = WL_NO_SHIELD;
return;
}
String version = WiFi.firmwareVersion();
if (version != "1.1.0")
{
Serial.println("Please upgrade the firmware");
}
// Connect to Wifi network.
while (status != WL_CONNECTED)
{
Serial.print("Connecting to Network named: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Update this line if
// using open or WEP network.
status = WiFi.begin(ssid, pass);
// Wait for connection.
delay(1000);
}
// Start the server.
server.begin();
// Print WiFi status.
printWifiStatus();
}
void loop()
{
// Check that we are connected.
if (status != WL_CONNECTED)
{
return;
}
// Listen for incoming client requests.
WiFiClient client = server.available();
if (!client)
{
return;
}
Serial.println("Client connected");
String request = readRequest(&client);
executeRequest(&client, &request);
// Close the connection.
//client.stop();
Serial.println("Client disonnected");
}
// Read the request line. The string from the JavaScript client ends with a newline.
String readRequest(WiFiClient* client)
{
String request = "";
// Loop while the client is connected.
while (client->connected())
{
// Read available bytes.
while (client->available())
{
// Read a byte.
char c = client->read();
// Print the value (for debugging).
Serial.write(c);
// Exit loop if end of line.
if ('\n' == c)
{
return request;
}
// Add byte to request line.
request += c;
}
}
return request;
}
void executeRequest(WiFiClient* client, String* request)
{
char command = readCommand(request);
int n = readParam(request);
if ('P' == command)
{
WeWishyouaMerryChristmas();
}
}
// Read the command from the request string.
char readCommand(String* request)
{
String commandString = request->substring(0, 1);
return commandString.charAt(0);
}
// Read the parameter from the request string.
int readParam(String* request)
{
// This handles a hex digit 0 to F (0 to 15).
char buffer[2];
buffer[0] = request->charAt(1);
buffer[1] = 0;
return (int) strtol(buffer, NULL, 16);
}
void sendResponse(WiFiClient* client, String response)
{
// Send response to client.
client->println(response);
// Debug print.
Serial.println("sendResponse:");
Serial.println(response);
}
void printWifiStatus()
{
Serial.println("WiFi status");
// Print network name.
Serial.print(" SSID: ");
Serial.println(WiFi.SSID());
// Print WiFi shield IP address.
IPAddress ip = WiFi.localIP();
Serial.print(" IP Address: ");
Serial.println(ip);
// Print the signal strength.
long rssi = WiFi.RSSI();
Serial.print(" Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
// We Wish you a Merry Christmas tone
int tonePin = 12;
void WeWishyouaMerryChristmas() {
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 391, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 391, 312.4995);
delay(347.221666667);
tone(tonePin, 311, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 466, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 391, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 415, 546.874125);
delay(607.637916667);
delay(86.8054166667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 391, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 391, 312.4995);
delay(347.221666667);
tone(tonePin, 311, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 466, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 391, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 415, 546.874125);
delay(607.637916667);
delay(86.8054166667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 391, 624.999);
delay(694.443333333);
tone(tonePin, 391, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 391, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 311, 546.874125);
delay(607.637916667);
delay(86.8054166667);
tone(tonePin, 466, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 622, 312.4995);
delay(347.221666667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 466, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 391, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 415, 546.874125);
delay(607.637916667);
delay(86.8054166667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 391, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 349, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 312.4995);
delay(347.221666667);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 156.24975);
delay(173.610833333);
tone(tonePin, 391, 312.4995);
delay(347.221666667);
tone(tonePin, 311, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 311, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 312.4995);
delay(347.221666667);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 523, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 311, 156.24975);
delay(173.610833333);
tone(tonePin, 349, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 466, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 391, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 415, 546.874125);
delay(607.637916667);
delay(86.8054166667);
tone(tonePin, 369, 312.4995);
delay(347.221666667);
tone(tonePin, 493, 312.4995);
delay(347.221666667);
tone(tonePin, 493, 156.24975);
delay(173.610833333);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 493, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 415, 312.4995);
delay(347.221666667);
tone(tonePin, 554, 312.4995);
delay(347.221666667);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 622, 156.24975);
delay(173.610833333);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 493, 156.24975);
delay(173.610833333);
tone(tonePin, 466, 312.4995);
delay(347.221666667);
tone(tonePin, 369, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 369, 312.4995);
delay(347.221666667);
tone(tonePin, 622, 312.4995);
delay(347.221666667);
tone(tonePin, 622, 156.24975);
delay(173.610833333);
tone(tonePin, 659, 156.24975);
delay(173.610833333);
tone(tonePin, 622, 156.24975);
delay(173.610833333);
tone(tonePin, 554, 156.24975);
delay(173.610833333);
tone(tonePin, 493, 312.4995);
delay(347.221666667);
tone(tonePin, 415, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 369, 156.24975);
delay(173.610833333);
tone(tonePin, 369, 156.24975);
delay(173.610833333);
tone(tonePin, 415, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 554, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 466, 234.374625);
delay(260.41625);
delay(86.8054166667);
tone(tonePin, 493, 546.874125);
delay(607.637916667);
}
Comments