Making a ultrasonic tape measure, using a LV Maxbotiz ez sensor.
using the following code I can output my reading IN feet or inchs. I was wondering using the arduino IdE how do I code and print my remainder so My sensor will display correctly
Example, Even though I am reading 4 foot 5 inchs from my sensor I dont know how to display 4 and X inches.
Here is the code I got from max Botix
I read something about the modulo operator, but I am unsure how to correctly integrate this into my example.
const int anPin1 = 0;
long distance1;
void setup() {
Serial.begin(9600); // sets the serial port to 9600
}
void read_sensors(){
/*
Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches
*/
distance1 = analogRead(anPin1)/2;
}
void print_all(){
Serial.print("S1");
Serial.print(" ");
Serial.print(distance1 /12);
Serial.print("feet");
Serial.println();
}
void loop() {
read_sensors();
print_all();
delay(50);
}
I will likely figure it out, but I can see there are a ton of people on here with WAY more coding time then my self.
Thanks in advance