C8: Arduino Basic + Sensor Interfacing

Aim:
To make a fan turn ON when the temperature crosses 30°C and turn OFF when below 30°C.

Requirements:

  • Computer with Tinkercad Circuits

  • Arduino Uno

  • Breadboard

  • Temperature sensor (LM35 or TMP36 in Tinkercad)

  • Small DC Fan + Transistor + Resistor

  • Wires

Steps:

Step 1: Setup the circuit in Tinkercad

  1. Open Tinkercad → Circuits → Create New Circuit.

  2. Drag Arduino Uno and a breadboard to the workspace.

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

    • VCC → 5V

    • GND → GND

    • Output pin → A0 (Analog Pin 0 on Arduino).

Step 2: Connect the fan with Arduino

  1. Place a DC Fan in the workspace.

  2. Use a transistor as a switch (Fan → Transistor → Arduino pin 9).

  3. Add a resistor at the base of the transistor.

  4. Power the fan using Arduino’s 5V & GND.

Step 3: Write the code

int tempSensor = A0;   // Temperature sensor pin

int fan = 9;           // Fan connected to pin 9

int tempValue = 0;

 

void setup() {

  pinMode(fan, OUTPUT);       // Set fan as output

  Serial.begin(9600);         // Start serial monitor

}

 

void loop() {

  tempValue = analogRead(tempSensor);          // Read sensor value

  float voltage = tempValue * (5.0 / 1023.0);  // Convert to voltage

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

 

  Serial.println(temperature);                 // Print on monitor

 

  if (temperature > 30) {                      // If temp > 30°C

    digitalWrite(fan, HIGH);                   // Fan ON

  } else {

    digitalWrite(fan, LOW);                    // Fan OFF

  }

 

  delay(500);   // Small delay

}

 

Step 4: Run Simulation

  • Start simulation and open Serial Monitor.

  • Drag the temperature slider in Tinkercad.

Watch the fan turn ON above 30°C and OFF below 30°C.

Fill in the form for S’O’A Fablab Orientation 2021.