//Reading an analog sensor (Potentiometer; Light Dependant Resister; IR Ranger; Thermister etc) //And writing an 'analog' output using Pulse Width Modulation int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 // outside leads to ground and +5V int val = 0; // variable to store the value read void setup() { Serial.begin(115200); // setup serial pinMode(11,OUTPUT); // Set pin 11 to be an output because we're going to use it for PWM } void loop() { val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value analogWrite(11,val/4); // divide the potentiometer reading by 4 because its values are between // 0 & 1023 - but the PWM values can only be upto 255! }