Advertisement
Guest User

loadCell

a guest
Mar 1st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include<Wire.h>
  3.  
  4. #include "HX711.h"
  5. #define DOUT D2
  6. #define CLK D3
  7. #include "SSD1306.h"
  8. SSD1306 display(0x3c,D2,D3);
  9.  
  10. String apiKey = "G48TG9O3R13EP3T7";
  11. const char* ssid = "rizkissid";
  12. const char* password = "qwertyuiop";
  13.  
  14. const char* server = "api.thingspeak.com";
  15.  
  16. HX711 scale(DOUT, CLK);
  17. float calibration_factor = 550.10;
  18. int GRAM;
  19.  
  20. WiFiClient client;
  21. void setup() {
  22. Serial.begin(9600);
  23. scale.set_scale();
  24. scale.tare();
  25. display.init();
  26. display.flipScreenVertically();
  27. display.setFont(ArialMT_Plain_10);
  28.  
  29. delay(10);
  30. WiFi.begin(ssid, password);
  31.  
  32. while(WiFi.status() !=WL_CONNECTED){
  33. delay(500);
  34. Serial.print(".");
  35. }
  36. Serial.print("");
  37. Serial.print("WiFi connected");
  38. }
  39.  
  40. void loop() {
  41. display.clear();
  42. scale.set_scale(calibration_factor);
  43. GRAM = scale.get_units(), 4;
  44. if(client.connect(server,80)){
  45. String postStr = apiKey;
  46. postStr += "&field1=";
  47. postStr += String(GRAM);
  48. postStr += "\r\n\r\n";
  49.  
  50. client.print("POST /update HTTP/1.1\n");
  51. client.print("Host: api.thingspeak.com\n");
  52. client.print("Connection: close\n");
  53. client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
  54. client.print("Content-Type: application/x-www-form-urlencoded\n");
  55. client.print("Content-Length");
  56. client.print(postStr.length());
  57. client.print("\n\n");
  58. client.print(postStr);
  59.  
  60. Serial.print("Berat : ");
  61. Serial.print(GRAM);
  62. display.drawString(0, 20,"Berat : ");
  63. display.drawString(0, 20,String(GRAM));
  64. Serial.println(" Kirim ke Thingspeak");
  65. display.drawString(0, 10, "Kirim ke Thingspeak");
  66. display.display();
  67. }
  68. client.stop();
  69.  
  70. Serial.println("Waiting .....");
  71.  
  72. for(unsigned int i=0; i<20; i++){
  73. delay(1000);
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement