Closed JakobRoseke closed 4 years ago
- Which line of code exhibits this behavior? Link to it.
- Did this sensor used to behave as expected before? If yes, when was that?
I don't quite understand the question.. The code I have posted in the issue gives a correct reading from the sensor, i.e it outputs more than a 0 when I hover an object in front of the car. https://github.com/DIT112-V20/group-05/blob/finalizeCar/src/smartCar/smartCar.ino this is the code that always gives a 0 in reading.
Yes, the sensor/car worked fine used last Saturday and we did not really change anything in the code up until yesterday. As I said, the sensor still works with the code posted in the issue, but whenever I upload the code that is in branch 'finalizeCar' -> src/smartCar/smartCar.ino the reading ALWAYS gives a 0.
Please provide a link to the line(s) of code that have the problem. front_sensor
is not used at only one place.
Please provide a link to the line(s) of code that have the problem.
front_sensor
is not used at only one place.
Use a different pin for FRONT_ECHO_PIN
if you want to also keep using the on-board LED. LED_BUILTIN
is a constant that has the value of 2
in the ESP32 DOIT devkit v1 board that you have. In other words, pin D2
is also connected to the on-board LED.
Software-wise, the "echo" pin of a SR04 sensor has to be an INPUT
. Setting this pin to an input, when provided to an SR04
constructor is taken care of by the Smartcar library. In your case you set its mode/direction to be an OUTPUT
in setup()
and then controlling its state, which clearly messes the measurements up.
Thank you very much, it works now!
I changed the echo pin from 2 to 16 and added pinMode for the echo and trigger.
added pinMode for the echo and trigger.
No, you shouldn't (or rather don't need to do this) since as I mentioned it is taken care of by the Smartcar library.
ahh okay, it worked anyways but I will remove them.
@platisd Hi again... hopefully last time I will have to ask for some answers.
In the branch, 'finalizeCar' -> src/smartCar/smartCar, the sensor won't give any reading other than 0.. The sensor works fine when we use this code;
I do not know why it won't work in our regular code!! Do you see anything that would indicate it not working as it should?