Code for water level indicator

I want to make an water level indicator using 2 arduino uno (transmitter and receiver), nrf24l01 modules , ultrasonic sensor and a 6pin OLED display. I tried writing code for it but I doesn't seem to work.
Someone please help me to write code for transmitter and receiver.

Forum members are happy to help you solve problems with your code. For hints on how to get that help, please read and follow the instructions in the "How to get the best out of this forum" post.

Otherwise, you can hire someone to write code by posting on the Jobs and Paid Collaborations forum section.

Please read the how to get the most from the forum post. The post contains information on what we need to know in order to help you.

A good place to start with the rf24 radios is Robin2's simple rf24 radio tutorial. If you carefully follow that tutorial you should be able to make them work.

Chat GPT generated this:

Model: Default (GPT-3.5)
I asked:
I want to make an water level indicator using 2 arduino uno (transmitter and receiver), nrf24l01 modules , ultrasonic sensor and a 6pin OLED display. I tried writing code for it but I doesn't seem to work. can you please help me to write code for transmitter and receiver.

It responded:
Sure, here is an example code for the transmitter and receiver using 2 Arduino Uno boards, nrf24l01 modules, ultrasonic sensor, and a 6-pin OLED display. Please note that you may need to modify the code to fit your specific hardware setup.

Transmitter code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Ultrasonic.h>

#define trigPin 9
#define echoPin 10

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

Ultrasonic ultrasonic(trigPin, echoPin);

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

void loop() {
  delay(1000);
  float distance = ultrasonic.read();
  int level = map(distance, 0, 200, 0, 100);
  radio.write(&level, sizeof(level));
}

Receiver code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Water Level");
  display.display();

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    int level;
    radio.read(&level, sizeof(level));

    display.clearDisplay();
    display.setTextSize(2);
    display.setCursor(0,0);
    display.print(level);
    display.println("%");
    display.display();
  }
}

This code uses the Ultrasonic library to read the distance from the ultrasonic sensor and map it to a percentage value for the water level. The transmitter sends this value to the receiver using the nrf24l01 module. The receiver displays the water level on the OLED display.

There's your start
Z

Did you test sketch, didn´t you?

I don't have the parts to test his project, but the concept is simple enough that @
blackout_9656 should be able to adapt it or ask for further assistance from those who do have the parts.

Nor try the code that ChatGPT gave you, or even, it seems, offer a scintilla of an iota of an opinion about its plausibility.

If all you can do is offer untested artificial intelligence written code, I suggest you to sit on your hands and watch actual people offer real help.

In particular, sharing untested NRF24L01 code is more like harmful.

@blackout_9656 has been advised to get the radio set working following a known good tutorial that has stood the tests of time.

Until the radios are functioning stand alone, it is pointless and a distraction to go for the final project goal.

a7

1 Like

YMMD :+1:

No one was going to help he didn't provide any starting code. The only replies were admins telling him that. So no harm done right? My internet was to show him another tool like Google search. Where most others are referred to.
Z

Here's a list of tutorials that could help

  1. nRF24L01 module tutorial: https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/
  • This tutorial covers how to use the nRF24L01 module for wireless communication with Arduino.
  1. Ultrasonic sensor tutorial: https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
  • This tutorial covers how to use the HC-SR04 ultrasonic sensor with Arduino.
  1. Adafruit SSD1306 OLED display tutorial: Arduino Library & Examples | Monochrome OLED Breakouts | Adafruit Learning System
  • This tutorial covers how to use the Adafruit SSD1306 OLED display with Arduino.

Each of these tutorials provides step-by-step instructions and code examples for working with the specific component. I hope this helps!

And my internet was to suggest that ChatGPT is more harmful than helpful.

a7

My internet tells me that ChatGPT is selling old wine in new bottles. It´s like the man who is selling snake oil for all daily events.

No worries. I'm sure there was someone else out there that was willing to spend a few hours writing code for free, testing it and teaching him how to use it.
I'm not going around picking on posts that have 5 or so responders having a great discussion on topics that they love. I spotted this one out of the pits of What would literally be called dead posts and decided to revive it. Interesting that we're having a discussion on another topic than what the original post was about.
I also find it funny that I spent what... one minute helping this person discover a new tool whether it be snake oil or not while everybody else's posting has spent 15-20 minutes shooting it down.
Good day, and I wish you all good luck.

The code in Robin2's tutorial is written, mainly, using functions. So once the simpleRX and simpleTX codes are working it is pretty easy to insert that code into an existing program with a few minor changes.

But that is moot until the radios are known to work. There is more than firmware to making those units talk.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.