rhandycan1

BATTERY MONITORING TRANSMITTER(ESP32_2WAY

Dec 14th, 2025 (edited)
124
0
Never
14
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.46 KB | Source Code | 0 0
  1. /* Program by: RANDY N. CAÑADA, DEC. 2025
  2. ESP32 wiring (VSPI example)
  3. MOSI -> GPIO23
  4. MISO -> GPIO19
  5. SCK  -> GPIO18
  6. CSN  -> GPIO5
  7. CE   -> GPIO17
  8.  
  9. ESP32 (Transmitter + Feedback Receiver)
  10.  
  11. OLED 1306 CONNECTIONS:
  12. -can be operated in 3.3vdc / 5 vdc
  13. sda=21,scl=22
  14. */
  15. #include <SPI.h>
  16. #include <nRF24L01.h>
  17. #include <RF24.h>
  18. #include <Wire.h>
  19. #include <Adafruit_GFX.h>
  20. #include <Adafruit_SSD1306.h>
  21.  
  22. // --- RF24 setup ---
  23. RF24 radio(17, 5); // CE, CSN
  24. const byte address[][6] = {"00001", "00002"}; // ESP32->Arduino, Arduino->ESP32
  25.  
  26. int buttonPin = 13;
  27.  
  28. // --- OLED setup ---
  29. #define SCREEN_WIDTH 128
  30. #define SCREEN_HEIGHT 64
  31. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
  32.  
  33. // --- Battery thresholds ---
  34. const float VBAT_MIN = 1.45;   // cutoff
  35. const float VBAT_MAX = 1.50;   // full charge
  36.  
  37. void setup() {
  38.   Serial.begin(9600);
  39.   pinMode(buttonPin, INPUT_PULLUP);
  40.  
  41.   // --- Radio init ---
  42.   radio.begin();
  43.   radio.setPALevel(RF24_PA_MIN);
  44.   radio.openWritingPipe(address[0]);   // Send commands to Arduino
  45.   radio.openReadingPipe(1, address[1]); // Listen for feedback
  46.  
  47.   // --- OLED init ---
  48.   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
  49.     Serial.println("SSD1306 allocation failed");
  50.     while (1);
  51.   }
  52.   display.clearDisplay();
  53.   display.setTextSize(3);
  54.   display.setTextColor(SSD1306_WHITE);
  55.   display.setCursor(20,0);
  56.   display.println("Remote");
  57.   display.setCursor(20,35);
  58.   display.println("Ready!");
  59.   display.display();
  60.   delay(1500);
  61. }
  62.  
  63. void loop() {
  64.   // --- Send command ---
  65.   radio.stopListening();
  66.   if (digitalRead(buttonPin) == LOW) {
  67.     const char text[] = "LED ON";
  68.     radio.write(&text, sizeof(text));
  69.     Serial.println("Sent: LED ON");
  70.   } else {
  71.     const char text[] = "LED OFF";
  72.     radio.write(&text, sizeof(text));
  73.     Serial.println("Sent: LED OFF");
  74.   }
  75.  
  76.   // --- Switch to RX mode and wait for feedback ---
  77.   radio.startListening();
  78.   unsigned long start_time = millis();
  79.   while (!radio.available()) {
  80.     if (millis() - start_time > 500) {
  81.       Serial.println("No feedback received.");
  82.       display.clearDisplay();
  83.       display.setTextSize(2);
  84.       display.setCursor(0,0);
  85.       display.println("OFFLINE!");
  86.       display.display();
  87.       return;
  88.     }
  89.   }
  90.  
  91.   char feedback[32] = "";
  92.   radio.read(&feedback, sizeof(feedback));
  93.   Serial.print("Battery feedback: ");
  94.   Serial.println(feedback);
  95.  
  96.   // --- Parse feedback (format: "V=1.45V I=1.4mA") ---
  97.   float busVoltage = 0.0, current_mA = 0.0;
  98.   sscanf(feedback, "V=%fV I=%fmA", &busVoltage, &current_mA);
  99.  
  100.   // Calculate power and battery percentage
  101.   float power_mW = busVoltage * (current_mA / 1000.0) * 1000.0; // mW
  102.   int pct = batteryPercent(busVoltage);
  103.  
  104.   // --- Serial Monitor output (same format as OLED) ---
  105.   Serial.print("V: "); Serial.print(busVoltage, 3); Serial.println(" V");
  106.   Serial.print("I: "); Serial.print(current_mA, 2); Serial.println(" mA");
  107.   Serial.print("P: "); Serial.print(power_mW, 2); Serial.println(" mW");
  108.   Serial.print("Batt: "); Serial.print(pct); Serial.println("%");
  109.   Serial.println("-----------------------------");
  110.  
  111.   // --- OLED output (same format as INA219 sketch) ---
  112.   display.clearDisplay();
  113.   display.setCursor(0,0);
  114.   display.setTextSize(2);
  115.   display.print("V: "); display.print(busVoltage, 3); display.println(" V");
  116.   display.print("I: "); display.print(current_mA, 2); display.println(" mA");
  117.   display.print("P: "); display.print(power_mW, 2); display.println(" mW");
  118.  
  119.   // ✅ Battery line
  120.   display.fillRect(0, 48, 128, 16, SSD1306_BLACK);
  121.   display.setCursor(0,48);
  122.   char buffer[12];
  123.   sprintf(buffer, "Batt:%3d%%", pct);
  124.   display.print(buffer);
  125.  
  126.   // ✅ Two warning levels
  127.   if (pct >=15 && pct <=20) {
  128.     display.clearDisplay();
  129.     display.setTextSize(2);
  130.     display.setCursor(28,0);
  131.     display.print("Charge");
  132.     display.setCursor(42,20);
  133.     display.print("Your");
  134.     display.setCursor(28,40);
  135.     display.print("Battery");
  136.     Serial.println("⚠️ Battery Low!");
  137.   } else if (pct <= 5) {
  138.     display.clearDisplay();
  139.     display.setTextSize(2);
  140.     display.setCursor(52,1);
  141.     display.print("LOW");
  142.     display.setCursor(28,32);
  143.     display.print("BATTERY!");
  144.     Serial.println("❌ Battery Depleted!");
  145.   }
  146.  
  147.   display.display();
  148.   delay(1000);
  149. }
  150.  
  151. int batteryPercent(float vbat) {
  152.   if (vbat <= VBAT_MIN) return 0;
  153.   if (vbat >= VBAT_MAX) return 100;
  154.   return (int)((vbat - VBAT_MIN) * 100.0 / (VBAT_MAX - VBAT_MIN));
  155. }
  156.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Icximpa
    38 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
  • Frokimky
    24 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
  • User was banned
  • Veronyd
    13 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=rkdasdagov
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment