Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/*
* Arduino Anti-GPS Silliness
* by Connor Nishijima 2016
*
* By reading the frequency of AC cycles in your house using an open analog pin,
* I can tell you for sure what countries you AREN'T in. Pretty god damn useless,
* but fun, nonetheless.
*
* You'll need an Arduino Mega to fit the array of Strings below, Uno doesn't cut it
* even with use of PROGMEM. The Sketch is also written to use the Seeed Studio TFT
* sheild, but if you remove all "TFT" lines from the sketch you can just see the output
* in the Serial Monitor. An antenna (just a breadboard jumper) on A7 might be necessary.
*
*/
#include <TFTv2.h>
#include <SPI.h>
const String FiftyHz_countries[149] = {
"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Argentina",
"Armenia", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh",
"Barbados", "Belarus", "Belgium", "Benin", "Bhutan", "Bolivia", "Bosnia",
"Botswana", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
"Cameroon", "Cape Verde", "Central African Republic", "Chad", "Chile",
"China", "Comoros", "Congo", "Croatia", "Curacao",
"Cyprus", "Czech Republic", "Denmark", "Dominica", "Egypt",
"Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
"Fiji", "Finland", "France", "French Guiana", "Gabon",
"Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece",
"Greenland", "Grenada", "Guadeloupe", "Guernsey", "Guinea", "Hong Kong",
"Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland",
"Isle of Man", "Israel", "Italy", "Jamaica", "Jordan", "Kazakhstan",
"Lebanon", "Lesotho", "Libya", "Lithuania", "Liechtenstein",
"Luxembourg", "Macau", "Madagascar", "Malawi", "Malaysia",
"Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique",
"Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Caledonia",
"New Zealand", "Nigeria", "Norway", "Oman", "Pakistan", "Papua New Guinea",
"Paraguay", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda",
"Saint Helena", "St. Lucia", "The Grenadines", "Samoa",
"San Marino", "Senegal", "Serbia", "Seychelles", "Sierra Leone",
"Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia",
"South Africa", "Spain", "Sri Lanka", "Sudan", "Swaziland", "Sweden",
"Switzerland", "Syria", "Tajikistan", "Tanzania", "Thailand", "Togo",
"Tonga", "Tunisia / Tatooine", "Tuvalu", "Uganda",
"Ukraine", "United Arab Emirates", "United Kingdom", "Uruguay",
"Uzbekistan", "Vanuatu", "Vietnam", "Yemen", "Zambia", "Zimbabwe"
};
const String SixtyHz_countries[39] = {
"American Samoa", "Anguilla", "Antigua", "Aruba", "Bahamas", "Belize",
"Bermuda", "Brazil", "British Virgin Islands", "Canada", "Cayman Islands",
"Colombia", "Costa Rica", "Cuba", "Dominican Republic", "Ecuador",
"El Salvador", "Guam", "Guatemala", "Haiti", "Honduras", "Mexico",
"Micronesia", "Montserrat", "Nicaragua", "Palau", "Panama", "Peru",
"Philippines", "Puerto Rico", "St. Martin", "Saudi Arabia", "South Korea",
"Suriname", "Taiwan", "Trinidad", "United States", "Virgin Islands", "Venezuela"
};
byte lastRead = 0;
bool isRising = false;
bool lastState = false;
unsigned int peaks = 0;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(A7)); // Makes sure the countries appear in random orders each boot
TFT_BL_ON; // turn on the background light
Tft.TFTinit(); // init TFT library
Tft.drawString("WHERE AM",10,10,3,YELLOW);
Tft.drawString("I NOT?",10,50,3,YELLOW);
Serial.println("'Where Am I Not?' you ask?\n");
}
// the loop routine runs over and over again forever:
void loop() {
takeReading();
}
void takeReading() {
unsigned long start = millis();
bool done = false;
peaks = 0;
while (done == false) {
byte reading = analogRead(A7) / 4; // Divide 10-bit value by 4 to fit it in an 8-bit byte variable to save RAM.
// This looks for rising an falling of AC wave
if (reading > lastRead) {
isRising = true;
}
else if (reading < lastRead) {
isRising = false;
}
// This looks for high and low peaks
if (isRising == true && lastState == false) {
peaks++;
}
else if (isRising == false && lastState == true) {
peaks++;
}
lastState = isRising;
lastRead = reading;
delay(1);
if (millis() - start >= 500) { // Only grab 0.5 seconds of data.
done = true;
}
}
int frequency = peaks; // since we counted high AND low peaks in 0.5 seconds, the peak count should equal our AC Hz.
// Used to see which standard our reading is closest to
int sixtyDiff = abs(frequency - 60);
int fiftyDiff = abs(frequency - 50);
// If the reading seems to be in the range of AC frequency:
if (sixtyDiff > -5 && sixtyDiff < 30) {
// If we're in a 60Hz country:
if (sixtyDiff < fiftyDiff) {
int countryNum = random(0, 149);
char buf[25] = {};
String country = FiftyHz_countries[countryNum];
country.toCharArray(buf,25);
Tft.drawString("You are NOT in:",10,120,2,CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.fillRectangle(10, 145, 250, 250, BLACK);
Tft.drawString(buf,10,145,2,YELLOW); // draw string: "hello", (0, 180), size: 3, color: CYAN
Serial.print(countryNum);
Serial.print(" You are not in ");
Serial.print(FiftyHz_countries[countryNum]);
Serial.println(".");
}
// If we're in a 50Hz country:
else if (sixtyDiff > fiftyDiff) {
int countryNum = random(0, 39);
char buf[25] = {};
String country = SixtyHz_countries[countryNum];
country.toCharArray(buf,25);
Tft.drawString("You are NOT in:",10,120,2,CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.fillRectangle(10, 145, 250, 250, BLACK);
Tft.drawString(buf,10,145,2,YELLOW); // draw string: "hello", (0, 180), size: 3, color: CYAN
Serial.print(countryNum);
Serial.print(" You are not in ");
Serial.print(SixtyHz_countries[countryNum]);
Serial.println(".");
}
}
// If not, too bad.
else {
Tft.drawString("You are NOT in:",10,120,2,CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.fillRectangle(10, 145, 250, 250, BLACK);
Tft.drawString("NO FUCKING CLUE",10,145,2,RED); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.drawString("WHERE YOU ARE",10,170,2,RED); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.drawString("SORRY NOT SORRY",10,195,2,RED); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.drawString("PAY YOUR",10,220,2,RED); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.drawString("ELECTRIC BILL",10,245,2,RED); // draw string: "hello", (0, 180), size: 3, color: CYAN
Serial.println("NO FUCKING CLUE WHERE YOU ARE. SORRY NOT SORRY PAY YOUR ELECTRIC BILL.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment