0% found this document useful (0 votes)
16 views

Arduino LED Control

Uploaded by

Santosh Thakur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Arduino LED Control

Uploaded by

Santosh Thakur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

I2C Light Sensor Interfacing and Serial

Communication Using Tinkercad


Objective
The objective of this lab is to interface an I2C light sensor with an Arduino and send its readings
over the serial port to a computer. In this experiment, we will simulate a generic I2C light sensor
using Tinkercad.

Materials Needed
Arduino board (e.g., Arduino Uno)
USB cable to connect Arduino to a computer
Breadboard
Jumper wires
Potentiometer (used to simulate the light sensor)

Theory
I2C (Inter-Integrated Circuit) is a synchronous serial communication protocol commonly used to
connect low-speed peripherals to microcontrollers and microprocessors. It requires only two wires
for communication: SDA (Serial Data Line) and SCL (Serial Clock Line).

Circuit Diagram
We will simulate the I2C light sensor using a potentiometer connected to an analog pin on the
Arduino. This setup will help us mimic the behavior of a light sensor by varying the potentiometer
to simulate different light intensities.

Connections
1. Potentiometer:

Connect the middle pin of the potentiometer to Analog Pin A0 on the Arduino.
Connect one of the side pins to the 5V pin on the Arduino.
Connect the other side pin to the GND pin on the Arduino.

Here's a simplified diagram:

markdown Copy code


Arduino | Potentiometer ------------------------------- 5V | Side pin 1 GND | Side pin
2 A0 | Middle pin

Implementation Steps
1. Build the circuit on a breadboard as per the circuit diagram.
2. Connect the Arduino to your computer using a USB cable.
3. Write and upload the Arduino sketch to read the simulated light sensor data
(potentiometer) and send it over the serial port.

Arduino Sketch

cpp Copy code

void setup() { // Start serial communication at 9600 baud rate Serial.begin(9600); }


void loop() { // Read the analog value from the potentiometer (simulated light sensor)
int sensorValue = analogRead(A0); // Convert the analog value to a voltage (0 - 5V)
float voltage = sensorValue * (5.0 / 1023.0); // Convert the voltage to a light
intensity value (lux) // Assuming a linear relationship for simulation purposes float
lux = voltage * 200; // Example conversion factor // Print light intensity readings to
the serial monitor Serial.print("Light Intensity (Lux): "); Serial.println(lux); //
Wait for a second before reading again delay(1000); }

Explanation of the Code


1. Setup Function:

Serial.begin(9600);: Initializes serial communication with the computer at a baud rate of


9600 bits per second.

2. Loop Function:

int sensorValue = analogRead(A0);: Reads the analog value from the potentiometer
connected to pin A0.
float voltage = sensorValue * (5.0 / 1023.0);: Converts the analog value (0-1023) to a
voltage (0-5V).
float lux = voltage * 200;: Converts the voltage to a light intensity value in lux. This
conversion factor is an example and should be adjusted based on the actual sensor's
characteristics.
Serial.print("Light Intensity (Lux): "); and Serial.println(lux);: Prints the light
intensity readings to the serial monitor.
delay(1000);: Waits for a second before taking the next reading.

Questions for Students


1. Explain how the potentiometer is used to simulate a light sensor in this experiment.
2. Describe the process of reading analog values from a sensor and converting them to
meaningful units (e.g., lux).
3. Modify the code to change the conversion factor for the light intensity calculation. Provide
the modified code and explain your changes.
4. How would you adjust the circuit and code to read data from multiple simulated light
sensors connected to the Arduino?
5. Describe a real-world application where sensor interfacing and serial communication are
used.

Conclusion
By completing this lab, you have learned how to simulate an I2C light sensor using a potentiometer
and an Arduino. You have gained experience in reading analog values, converting them to
meaningful units, and sending the data over the serial port for display on a computer. This
knowledge is essential for various applications, including environmental monitoring, smart lighting
systems, and IoT (Internet of Things) projects.

This lab provides hands-on experience with sensor interfacing and serial communication,
reinforcing fundamental concepts in digital communication and sensor data processing.

You might also like