This is a walkthrough for an IoT Workshop I produced for SERAS.

Recording of the workshop:

Or Walkthrough as a video on YouTube.

int photoCellPin = 0;
int photoCellReading;
int LEDPin = 3;
int LEDBrightness;



void setup()
{
  Serial.begin(9600);
  pinMode(LEDPin, OUTPUT);
  pinMode(photoCellPin,INPUT);
}

void loop()
{
  photoCellReading = analogRead(photoCellPin);
  Serial.print("Analog reading = ");
  Serial.println(photoCellReading);
  photoCellReading = 1023 - photoCellReading;
  LEDBrightness = map(photoCellReading, 0, 1023, 0, 255);
  Serial.print("LED output = ");
  Serial.println(LEDBrightness);
  analogWrite(LEDPin, LEDBrightness);
  delay(100);
}