Robots are computer controlled machines. They are often described as electro-mechanical machines because they blend electronics (sensors and computer programs) with mechanics (the way a robot is built and how it moves). Mechanics and electronics are both important parts of how robots perform tasks.
Robots need step-by-step instructions to do a job. They can only do what humans program them to do. Programming tells a robot what to do, when to do it, and under what conditions.
In this picture, the robot (welding arm) is programmed to move its welding arm forward until the touch sensor detects the panel. When detected, it will stop moving and begin to weld. When the temperature sensor detects 6000oF, it will stop welding and move its arm back to the starting position.
A program tells the robot what do based on input from its environment. Sensors provide that environmental information and signals are then sent to the mechanical parts to carry out the physical task.