'How to access the output value coming from Arduino JSN-SR04T sensor through Python?
I've been trying to get the data from my arduino to pycharm IDE. The sensor I'm using is JSN-SR04T. However, when I'm trying to get the data from arduino, there are multiple values. How can I get the first value (i.e. the distance measured by the sensor)? The second value (266) is a constant sent by the arduino.
#include <NewPing.h>
#include <MedianFilter.h>
#include <Wire.h>
#include <cvzone.h>
#include <Servo.h>
#define pinTrigger 12
#define pinEcho 11
#define maxDistance 450
Servo servo1;
SerialData serial(2,3);
int valueRec[2];
int valueSend[1];
NewPing sonar(pinTrigger, pinEcho, maxDistance);
MedianFilter filter(31,0);
void setup() {
Serial.begin(9600);
servo1.attach(9);
}
void loop() {
delay(100);
unsigned int o,uS = sonar.ping();
filter.in(uS);
o = filter.out();
int sonar_data = o/US_ROUNDTRIP_CM;
valueSend[0] = sonar_data;
serial.Send(valueSend);
Serial.print("Ping: ");
Serial.print(sonar_data);
Serial.println("cm");
}
Hope you can help me. Thank you in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|