Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
Outputs analog voltage with a scaling factor of(Vcc/512) per inch. A supply of 5V yields ~9.8mV/in.and 3.3V yields ~6.4mV/in. The output is bufferedand corresponds to the most recent range data.
int ultraAn = 0; // select the input pin for the ultrasonic sensorint val = 0; // variable to store the value coming from the sensorint dist = 0; // variable to store the converted distance in inchesvoid setup() { Serial.begin(9600); // setup the serial port to send the values back to the computer}void loop() { val = analogRead(ultraAn); // read the value from the sensor Serial.println(val); // print the value to the serial port dist = (val/9.77); // converts the analog value to distance in inches Serial.println(dist); // prints the distance in inches delay (2000); // delays 2 secconds in between readings}
103103331021010011029971029981029991021001102
TX – Delivers asynchronous serial with an RS232 format,except voltages are 0-Vcc. The output is an ASCIIcapital “R”, followed by three ASCII character digitsrepresenting the range in inches up to a maximum of255, followed by a carriage return (ASCII 13). Thebaud rate is 9600, 8 bits, no parity, with one stop bit.Although the voltage of 0-Vcc is outside the RS232standard, most RS232 devices have sufficient marginto read 0-Vcc serial data. If standard voltage levelRS232 is desired, invert, and connect an RS232converter such as a MAX232.
I'm trying to use the analog output from it to measure the distance in inches.
Code: [Select]void loop() { val =analogRead(ultraAn); // read the value from the sensor dist = (val/9.77); // converts the analog value to distance in inches}
void loop() { val =analogRead(ultraAn); // read the value from the sensor dist = (val/9.77); // converts the analog value to distance in inches}