007 – Voltage Dividers, IR Sensors, Servo Motors

<<< Previous Lecture ––––––– Next Lecture >>>

Voltage Divider

A lot of sensors are basically just resistors that change their resistance based on some external input. The change of resistance can be converted to voltage with a voltage divider.

voltagedivider

When we read the voltage between two resistors. The balance between the two resistor defines the output voltage.

Example 1

This example reads the value from three different analog inputs: a potentiometer, a light sensor and a force resistive sensor. The values are just printed out on the serial port.

Screen Shot 2013-10-10 at 11.07.41

int potentiometer = 0;
int lightSensor = 0;
int forceSensor = 0;

void setup(){
  Serial.begin(9600);
}

void loop(){
  potentiometer = analogRead(A0);
  lightSensor = analogRead(A1);
  forceSensor = analogRead(A2);
  Serial.print("Light Sensor: ");
  Serial.println(potentiometer);
  Serial.print("Potentiometer: ");
  Serial.println(sensorVal);
  Serial.print("Force Sensor: ");
  Serial.println(forceSensor);
  delay(100);
}