Nano 33 BLE Sense Project

We are trying to setup a system that when an external (we will have to figure out how to hard wire) electrical current is detected it sends a signal via Bluetooth to our Android tablet. We have a prototype, but we are NOT utilizing the Bluetooth rather we are using a button to simulate this action.

Application Related

  1. Mobile Application (MA). This code runs on the Android tablet devices and communicates with the Arduino device through Bluetooth. It also pushes completed routes up to the desktop application.
  2. Arduino Source Code (AA). This code runs on the Arduino device and sends a signal via bluetooth when the device detects voltage.
    Technologies
  3. Arduino: Assumed hardware device: Nano 33 BLE Sense
  4. Bluetooth, for communicating with the Arduino device while in the field
  5. Very basic knowledge of circuits and microcontrollers, for constructing the peripheral Arduino device. Voltage divider, led, and breadboards
    Programming Languages
  6. C (very little) for the Arduino BLE Sense device
    Structure of code
  7. The source code for the Arduino device is in /arduino
    Notes on the Arduino device:
    • I used a Nano 33 BLE Sense
    o Provides BLE pairing and communication. The MA expects to communicate with the hardware through the react-native-ble-manager library (see /mobile/useBleDeviceNew.js)
    o Can read a voltage through an analog/digital converter.

The code in this folder is for the spray detect device. This is a Arduino BLE Sense device that simply measures the voltage on a pin and posts that information as a bluetooth service.

Key parameters in the code are:

  • INPIN, which defines the pin to read on
  • NAME, which defines what this BLE device is called when viewed on other devices
  • uid, defines the UUID of the services.

Compiling the code

This aduino source code needs to be compiled with Ardunio desktop.

  • Download the desktop
  • Install ArduinoBLE package
From the file, “SprayDetectBLE.ino”
#include <ArduinoBLE.h>
#define INPIN 2 // 2 = D2
#define OUTPIN 5
#define LOOKINGPIN 4
#define SPRAYPIN 6
#define TIMESTEP 100 // mseconds
#define NAME "Mosquito"
#define uid "4A98aaaa-1CC4-E7C1-C757-F1267DD021E8"
BLEService sprayService(uid);
BLEIntCharacteristic sprayChar(uid, BLERead|BLENotify);
BLEDescriptor sprayDesc("2901", "test spray");
bool sprayState = HIGH; // pullup; HIGH is actually 0V
bool readState(){
bool state = digitalRead(INPIN);
digitalWrite(SPRAYPIN, state);
return state;
}
void setup() {
// put your setup code here, to run once:
delay(1000);
Serial.begin(9600);
Serial.println("Starting");
// set up BLE BT
pinMode(INPIN, INPUT);
pinMode(OUTPIN, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SPRAYPIN, OUTPUT);
pinMode(LOOKINGPIN, OUTPUT);
if(!BLE.begin()){
Serial.println("starting BLE failed");
while (1);
}
String address = BLE.address();
Serial.print("Local address is: ");
Serial.println(address);
BLE.setLocalName(NAME);
BLE.setDeviceName(NAME);
BLE.setAdvertisedService(sprayService);
sprayService.addCharacteristic(sprayChar);
BLE.addService(sprayService);
sprayChar.addDescriptor(sprayDesc);
BLE.advertise();
sprayChar.broadcast();
Serial.println("Bluetooth device active, waiting for connections...");
digitalWrite(LOOKINGPIN, HIGH);
}
bool oldState = sprayState;
int i = 0;
void loop() {
// put your main code here, to run repeatedly:
BLEDevice central = BLE.central();
if(central){
if(central.connected()){
Serial.print("connected to central: ");
Serial.println(central.address());
digitalWrite(OUTPIN, HIGH);
digitalWrite(LOOKINGPIN, LOW);
while (central.connected()){
sprayState = readState();
if(oldState != sprayState){
if(sprayState){
Serial.println("Turned On");
sprayChar.writeValue((byte)0x01);
} else{
Serial.println("Turned Off");
sprayChar.writeValue((byte)0x00);
}
oldState = sprayState;
}
delay(TIMESTEP);
i +=1;
if(i==10){
sprayChar.writeValue(sprayState);
i=0;
}
}
}
digitalWrite(OUTPIN, LOW);
digitalWrite(LOOKINGPIN, HIGH);
digitalWrite(SPRAYPIN, LOW);
}
//Serial.print("Disconnected from centeral: ");
//Serial.println(central.address());
}

Please edit your post to add code tags.

Do you have a question for the forum, or is this purely informational?

1 Like

Sorry I am new and do not understand what code tags are.

We had a programmer start this project for us and unfortunately due to Covid his company no longer had staff to finish. I was hoping for insight on how to finish this project or better yet find someone (preferablly a company so we can pay) who knows how to do this and would be willing to complete project.

It's explained in this link: How to get the best out of this forum - Using Arduino / Installation & Troubleshooting - Arduino Forum

Please tell me if I added code tags correctly. Sorry for not understanding and thank you for the link to the guide

Yes. The revised initial posting looks good. People will now be able to take a good look at your code.

What issues are you having?

Looks fine.

You can use the flag button (lower right corner of the post) to ask a moderator to move it to the Jobs and Paid Collaborations forum section, and hopefully someone will take up the task.

We have a half completed project that we need finished in the next 1-2 months and we have no idea how to do this stuff. I was hoping that I could make contact with someone who could complete project and or help me to compete. This project is for our local mosquito control district in WA State.

AWESOME!! Thank you for the advice

As stated, the button press is presently modeling the detection of a voltage by the Nano 33.

When tested on an Android phone with LightBlue application, the code as written is sending a 1 or 0 when the button is pressed or not.

or help me to compete.

For the Arduino side of the simple spray detection you are pretty close. Do you know how to detect the voltage? Is the Android MA detecting and connecting with the Nano 33?

We would need to splice into the sprayer control box wire that is sending the voltage telling the pump to turn on and connect it to the Arduino. When pump is on it sends a continuious 12-14 volts and amperage of 0.16 milliamps. When the sprayer is turns off it sends no current. I was reading and looks like this can be accomplished through the digital pins????
Sorry if I make no sense, I am new to this tech.

Sorry that was confusing. When turned on there is currnet sent through a wire to tell the pump to run, I'm guessing (1). When pump is off there is no current, again guessing (0). We would like to connect the wire sending the 0/1 to the Arduino and have it send signal via Bluetooth to Android tablet whether pump in on or off.

We would also like the LED indicator lights to correspond with functions. Green LED is power on, orange LED we would like to be spray on (1) and the RGB LED we would like to be blue when bluetooth is connected to tablet.

I'm unclear about the signal which tells you the pump is on or off. Can you provide a hand drawn circuit diagram, or some documentation on the pump and it controller.

Using the RGB and Orange leds of the Nano 33 BLE to indicate different things should be pretty straightforward.

I have moved the topic to the #community:jobs category as requested.

Hi.
Let me see if I understand what you're looking for:

  1. Detect external voltage signal of some kind
  2. Send voltage level reading to Android tablet.
  3. Display signal on/off detection locally using LEDs on device
  4. Display BLE connection to phone/tablet by indicating blue LED on local device
  5. You prefer that the device used to build this is a Nano 33 BLE
  6. Need an App written for Android

Questions:

  1. Do you have a preferred screen layout/look & feel for the app?
  2. Does the measuring device have any special requirements such as waterproofness? Does it need to be mounted to a sprayer or is it handheld?
  3. Does the app need to be in the Play store, or can it be sideloaded?
  4. Does the app do anything other than display this indication? Are there future plans for feature expansion?

You may have already provided most of this information in your posts above, but I find that summarizing things like this can be helpful for anyone who's interested in pursuing the project. Also helps me decide if I have time for it :slight_smile:

The SmartFlow Console is hardwired to the pump and operator can choose Cont = Continuous Flow which will send a constant current (1) or Var = Various Flow which will send a current (1) when speed perameters are met. We have identified the wire that runs from the SmartFlow Console to the pump that sends the current when the sprayer is on.
We need to splice into the identified wire on the SmartFlow and connect it to the Arduino. When current is sent from SmartFlow to pump the current will also be sent to the Arduino and recognize that and send via Bluetooth a signal to the tablet that the spray is on (1) and illuminate the orange light on the Arduino.
Our previous programmer made the pictured Arduino as a prototype with a button to mimic the Bluetooth funtionality. We would need to build a much smaller Arduino unit and have it sealed in a transparent case so the lights can be viewed by the applicator. We are debating using the usb port to power the unit (current setup) or integrate a battery and on/off switch to negate the need to plug in the unit. We will be mounting the unit with velcro or double sided tape to the SmartFlow Console that is in the cab of the truck with the applicator.
I hope this clarifies our needs for the Arduino.
We have a programmer that has been working for us for the last couple of years that is creating the web side and tablet apk of this application. Once he finishes the tablet app (playstore) we will be able to integrate the on/off data to our database as well as other data tracked through the app.

Let me see if I understand what you're looking for:

  1. Detect external voltage signal of some kind
    Yes voltage is 12 volts when pump is turned on.
  2. Send voltage level reading to Android tablet.
    Yes Via Bluetooth
  3. Display signal on/off detection locally using LEDs on device
    Yes utilizing the Orange LED
  4. Display BLE connection to phone/tablet by indicating blue LED on local device
    Yes, GRB LED will illuminate Blue when Bluetooth connection is made
  5. You prefer that the device used to build this is a Nano 33 BLE
    Current prototype is Nano 33 BLE Sense which has multiple sensors that we do not need. Nano 33 BLE would be sufficent for this project.
  6. Need an App written for Android
    App is being written by another programmer.

Questions:

  1. Do you have a preferred screen layout/look & feel for the app?
    App is being written by current progammer
  2. Does the measuring device have any special requirements such as waterproofness? Does it need to be mounted to a sprayer or is it handheld?
    We will need to mount to spray console and need it encased in a transparent case to protect against dust and potential moisture/spill
  3. Does the app need to be in the Play store, or can it be sideloaded?
    No app needed just programming for Arduino that we have partially completed (see original post)
  4. Does the app do anything other than display this indication? Are there future plans for feature expansion?
    App tracks vehicle, spray on/off (Arduino), tracks spray totals, etc

You may have already provided most of this information in your posts above, but I find that summarizing things like this can be helpful for anyone who's interested in pursuing the project. Also helps me decide if I have time for it :slight_smile:

Our previous programmer made the pictured Arduino as a prototype with a button to mimic the Bluetooth funtionality.

I don't understand this. The button mimics the sensing of the 12V. The BLE functionality of sending that sensed signal is present in the code you posted and works correctly with LightBlue. Does it work with your MMA test tablet and its App?

The Nano33 BLE inputs can not be more than 3.3V. In your environment where the 12V is automotive, I would recommend a phototransistor optocoupler instead of a voltage divider.

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