Flashing Light Prize (5) IoT Pacing


1. NodeMCU ESP-12E
2. Arduino Uno
3. HC-06 Bluetooth Module
4. (2) Momentary Buttons
5. 5V Relay
6. NPN Transistor
7. 1K Resistor
8. Alligator Clips


  1. // Flashing Light Prize (5) IoT Pacing
  2. // Step Code
  3. // pkvi
  4. // NodeMCU ESP-12E 1.0
  5. #include <ESP8266WiFi.h>
  6. #include <ESP8266HTTPClient.h>
  7. // WIFI Network Access
  8. const char* ssid = "networkID";
  9. const char* password = "networkpassword";
  10. WiFiServer server(80);
  11. // Buttons
  12. const int left = D2;
  13. const int right = D3;
  14. // Buttons State
  15. int lstate;
  16. int rstate;
  17. int state = 0;
  18. int led = D0;
  19. void setup() {
  20. pinMode(left, INPUT);
  21. pinMode(right, INPUT);
  22. pinMode(led, OUTPUT);
  23. Serial.begin(9600);
  24. while (WiFi.status() != WL_CONNECTED) {
  25. WiFi.begin(ssid, password);
  26. delay(5000);
  27. }
  28. Serial.println("Connected");
  29. digitalWrite(led, HIGH);
  30. server.begin();
  31. }
  32. void loop() {
  33. // Read Buttons
  34. lstate = digitalRead(left);
  35. rstate = digitalRead(right);
  36. // Declare Task
  37. HTTPClient http;
  38. int httpCode;
  39. if (lstate == HIGH && rstate == LOW) {
  40. // Prevent Excess
  41. if (state == 0) {
  42. Serial.println("L");
  43. // Load .php that writes to .txt
  44. http.begin("http://website.com/flp/flp.php?state=1");
  45. httpCode = http.GET();
  46. http.end();
  47. state = 1;
  48. } else {
  49. // Nothing
  50. }
  51. } else if (rstate == HIGH && lstate == LOW) {
  52. if (state == 1) {
  53. Serial.println("R");
  54. http.begin("http://website.com/flp/flp.php?state=0");
  55. httpCode = http.GET();
  56. http.end();
  57. state = 0;
  58. } else {
  59. // Nothing
  60. }
  61. } else if (lstate == HIGH && rstate == HIGH) {
  62. // Zilch
  63. } else if (lstate == LOW && rstate == LOW) {
  64. // Nope
  65. }
  66. delay(100);
  67. }

Arduino Doodle
  1. // Flashing Light Prize (5) IoT Pacing
  2. // pkvi
  3. // Relay Pin
  4. int relay = 2;
  5. // Serial Data
  6. char data;
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode(relay, OUTPUT);
  10. }
  11. void loop() {
  12. // Communication?
  13. if (Serial.available() > 0) {
  14. // Whad' It Say?!
  15. data = Serial.read();
  16. // Off?
  17. if (data == 'F') {
  18. digitalWrite(relay, HIGH);
  19. }
  20. // On?
  21. if (data == 'U') {
  22. digitalWrite(relay, LOW);
  23. }
  24. }
  25. }

Processing Process
  1. // Flashing Light Prize (5) IoT Pacing
  2. // Processing to Bluetooth
  3. // pkvi
  4. import processing.serial.*;
  5. Serial port;
  6. void setup() {
  7. println(Serial.list());
  8. port = new Serial(this, "COM3", 9600);
  9. frameRate(4);
  10. }
  11. void draw() {
  12. // Internet Address .txt File
  13. String onoroff[] = loadStrings("http://website.com/flp/flp.txt");
  14. // Prints .txt File Contents
  15. print(onoroff[0]);
  16. if (onoroff[0].equals("1") == true) {
  17. println("Flash");
  18. port.write('F');
  19. } else if (onoroff[0].equals("0") == true) {
  20. println("Unflash");
  21. port.write('U');
  22. } else {
  23. }
  24. }

PHP-p-ing
  1. $onoroff = $_GET["state"];
  2. $textfile = "flp.txt";
  3. $fileLocation = "$textfile";
  4. $fh = fopen($fileLocation, 'w') or die("Crap!");
  5. $stringToWrite = "$onoroff";
  6. fwrite($fh, $stringToWrite);
  7. fclose($fh);

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,363 miters
123 tenons
Subscribe
0.0179