What's better a camera or ultrasonic sensor?

Hi, i wanted to know whats the best way for a robot to see? Camera or ultrasonic sensor?

Depends what you want the robot to 'see'.

A camera would not be very good at detecting a blank white wall in front of the robot, whereas a ultrasonic sensor would be good at detecting the wall.

Both.

Ok cool so how would i code a camera on a robot so it can see its environment?

Whenever the ultrasonic gives you a hit, take a pic and see if you can figure out what it is. Extra points if you have adaptive focus and drive it to focus at the measured range to target.

A Hexapod I built I used LIDAR to allow the hexapod to "see".

Arduinos can use a camera to take a picture (one line of code). You write code to interpret the picture, and figure out what action the robot should take, if any.

So for an Arduino robot see you would use an ultrasonic sensor or LIDAR?

Ultrasonic and LIDAR sensors are great for measuring distances to objects, and work in the dark, too.

I use 2 IR imagers to allow one of my projects to 'see'.

Another project uses a camera with a RPi an Tensorflow to see.

Here is how this guy did it,

https://create.arduino.cc/projecthub/Abhinav_Abhi/arduino-lidar-917404

Most Arduinos would not be capable of processing the image from a camera, whereas an ultrasonic sensor is a relatively simple thing (that gives you much less information) that is easy for small microcontrollers to use.

So an ultrasonic sensor and LIDAR sensor are the way to go

You could use two cameras for stereoscopic vision. Then you can not only recognize objects but can also judge distances.

If you only want to check the distance of the object go for ultrasonic
But if you want recognize object with the distance go with the camera.

Both are good at their own
It's only depend on you what is your project and requirement

I'd argue that to ID an Object using LIDAR is far better than ultrasonic. A LIDAR's beam is about 1 to 2 percent detection angle at max distance where a ultrasonic detection angle is 15 degrees.

Ask yourself does your car use LIDAR or Ultrasonic with its forward looking object detection?

Camera, radar and sonar. But no LIDAR.