C8: Arduino Basic + Sensor Interfacing

Aim:
To create a digital smart room in Tinkercad that can automatically turn ON/OFF lights and fan using sensors.

Requirements:

  • Computer with Internet access

  • Tinkercad Circuits

  • Arduino Uno

  • LED (represents room light)

  • DC Fan

  • LDR (Light Dependent Resistor) – senses brightness

  • Temperature sensor (LM35 or TMP36) – senses heat

  • Resistors and wires

Steps:

Step 1: Build the circuit

  1. Open Tinkercad → Circuits → Create New Circuit.

  2. Drag Arduino Uno and a breadboard.

  3. Place an LDR on the breadboard. Connect:

    • One side to 5V with a resistor going to GND.

    • The junction point → A0 (Analog pin on Arduino).

  4. Place the temperature sensor (LM35). Connect:

    • VCC → 5V

    • GND → GND

    • Output → A1.

  5. Add an LED (room light) to pin 9 (with resistor).

  6. Add a DC Fan to pin 10 using a transistor as a switch (just like in Lesson 4).

Step 2: Write the code

int ldr = A0;          // LDR sensor pin

int tempSensor = A1;   // Temperature sensor pin

int led = 9;           // LED pin

int fan = 10;          // Fan pin

 

void setup() {

  pinMode(led, OUTPUT);

  pinMode(fan, OUTPUT);

  Serial.begin(9600);

}

 

void loop() {

  // Read LDR value

  int lightValue = analogRead(ldr);

  

  // Read temperature

  int tempValue = analogRead(tempSensor);

  float voltage = tempValue * (5.0 / 1023.0);

  float temperature = voltage * 100;  // Convert to Celsius

 

  // Print values

  Serial.print(“Light: “);

  Serial.print(lightValue);

  Serial.print(” | Temp: “);

  Serial.println(temperature);

 

  // Smart Light Control

  if (lightValue < 500) {     // Dark condition

    digitalWrite(led, HIGH);  // Light ON

  } else {

    digitalWrite(led, LOW);   // Light OFF

  }

 

  // Smart Fan Control

  if (temperature > 30) {     // If hot

    digitalWrite(fan, HIGH);  // Fan ON

  } else {

    digitalWrite(fan, LOW);   // Fan OFF

  }

 

  delay(500);

}

 

Step 3: Run Simulation

  • Start simulation and open Serial Monitor.

  • Adjust the light slider to make the room dark or bright → the LED will turn ON/OFF.
  • Adjust the temperature slider → the fan will automatically turn ON above 30°C.
Fill in the form for S’O’A Fablab Orientation 2021.