Hello guys,
i am trying to make my chainable grove LED to light on when the ultrasonic ranger reaches 20cm! how can that be achieved
Hello guys,
i am trying to make my chainable grove LED to light on when the ultrasonic ranger reaches 20cm! how can that be achieved
Welcome to the community
What have you tried so far?
Can you show some code?
// This #include statement was automatically added by the Particle IDE.
#include <Grove_ChainableLED.h>
// This #include statement was automatically added by the Particle IDE.
#include <Grove-Ultrasonic-Ranger.h>
Ultrasonic ultrasonic(D2);
ChainableLED leds(A4, A5, 1);
void setup() {
Serial.begin(9600);
leds.init();
leds.setColorHSB(1, 0.0, 0.0, 0.0);
}
void loop() {
int range;
Serial.println("Obstacle found at:");
range = ultrasonic.MeasureInCentimeters();
Serial.print(range); //0~400cm
Serial.println(" cm");
delay(250);
}
This is the current code i have, i finished the tutorial for mesh and the led but how can i create the same concept but when a certain distance is reached on the Ultrasonic ranger, and is it also possible to add a buzzer when to buzz when the same distance is reached?’
Try comparing the measured range to a set value, then act accordingly. (Hint “if (… < …){ … })
Thanks @Moors7 and @ScruffR I am also trying to create a handshake function, basically image i have a fleet of scooters and charging stations. How can i determine which scooter is at which station (ex. person take scooter 1 from station 1 and wants to return scooter two at station 2) how would the verification be to confirm like a handshake that scooter 1 is at station 2!
There is too little info about your infra structure to properly advise.
You would need some short of near field communication (NFC) to do that with certainty. Wirelessly.
Okay so basically my project is about remote scooters, i have charging stations and scooters. I am trying to use an ultrasonic ranger to confirm that the scooter has been parked and is 1 cm away, this will then turn on a green light to confirm that the scooter has been released. Along that, i am trying to add another authentication method to confirm that the scooter is really parked at the station which is the handshake between the two devices, the device in the scooter(boron) and the device in the charging station (argon).
How would you detect that at the reported 1cm distance actually is a charging station?
At 1cm NFC would be an option - as mentioned by @armor.
Will your scooters also have GPS on-board?
I am still testing with LTE but i think GPS would be more efficient. Also do you know which device jams the scooter and lower its speed if someone left the geofence?
I certainly would not use ultrasound for just range and in any case they have a minimum range of 10cm. You really need to have a handshake of some sort. RFID/NFC or you could use an IR sender and receiver although given the conditions (rain, snow, dirt) a NFC approach is the most robust. BLE possibly another approach.
@armor Thanks!!! Okay do you an example of how i can add NFC ? also how BLE work (mesh)
Not sure what you are thinking to put in each scooter and in each base station? If you put a Boron say in each scooter then you can use this to control the scooter operation wirelessly over cellular comms from the cloud. It can also support BLE (central or peripheral role) and NFC Tag. For ease of deployment you would probably want a Boron in the base station as well. For BLE - the scooter could be an iBeacon and the base station in central role could scan and know when scooters were close. If you can make a physical connection between the base station and the scooter (to recharge) then comms over the recharge link is possible with serial even.
// This #include statement was automatically added by the Particle IDE.
#include <Grove_4Digit_Display.h>
// This #include statement was automatically added by the Particle IDE.
#include <Grove-Ultrasonic-Ranger.h>
#define CLK D4
#define DIO D5
Ultrasonic ultrasonic(D2);
TM1637 disp(CLK,DIO);
int lastRange = 0;
void setup()
{
Serial.begin(9600);
disp.init();
//Options are: BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
disp.set(BRIGHT_TYPICAL);
}
void loop()
{
int range;
Serial.println("Obstacle found at:");
range = ultrasonic.MeasureInCentimeters();
int digit;
int pos = 3;
if (range != lastRange) {
lastRange = range;
**bool distance_changed;**
**distance_changed= Particle.publish('Distance Changed',PRIVATE);**
**if (range != lastRange) {**
**lastRange = range;**
**}**
// Fill display with zeros
for (int i = 0; i < 4; i++) {
disp.display(i, 0);
}
// Extract each digit from the range and write it to the display
while (range >= 1) {
// Get the current digit by performing modulo (%) division on the range
digit = range % 10;
// Remove the trailing digit by whole-number division
range /= 10;
disp.display(pos, digit);
pos--;
}
}
Serial.print(range); //0~400cm
Serial.println(" cm");
delay(250);
}
So basically this is how my current code looks like, i am trying to publish these events on google sheets, does anyone know how to publish the code in bold to google sheets (which basically means when range != lastRange --> then publish on google sheets
Click search above and type in “google sheets” - there are lots of threads discussing this very topic