Embedded system

Requirments:-
Arduino
Breadboard
LED
Resistor



Procedure:
Edit the resistor value by adjusting it to 220 ohms in the component inspector which appears when the resistor is selected.
Now LED connect to breadboard as shown in the figure; you can place the LED in any other part of the breadboard.
Resistor connect as shown in the figure.
Now connect the wire ground pin (GND) to the negative side of the breadboard where the resistor is connected.
Connect one side of the wire to pin no.12 and the other side as shown in the figure.
You can change the cable color as required.
Go to code.
When the code editor is open, you can click the dropdown menu on the left and select "Blocks -> Text".
Code:




  
    
    Shadow Box Example
  
  
   // C++ code 
int red = 12;
void setup() {
pinMode(red, OUTPUT);
}
void loop() {
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(1000);
}
Click on Start Simulation.

Requirments:-
Arduino Uno
Photoresistor
2Resistors
Breadboard
Jumper wires
Computer with Arduino IDE or Tinkercad for simulation



Procedure:
Step 1: Set up the circuit on Tinkercad
Create a new project on Tinkercad and open the "Circuits" workspace.
Add components:
Place the Arduino Uno board on the workspace.
Add the LDR (Light Dependent Resistor).
Add a resistor at LED side
Add a 100Ω resistor.
Place a breadboard and connect the components to it.
Use jumper wires to make the connections.

Step 2: Wiring the circuit
Connect the LDR:
One pin of the LDR is connected to the 5V pin of the Arduino.
The other pin of the LDR is connected to an analog input pin of the Arduino (for example, A0).

Add the Pull-down Resistor:
Connect the second pin of the LDR (the one connected to A0) to one end of the 10kΩ resistor.
Connect the other end of the 10kΩ resistor to GND (ground) on the Arduino.

Complete the circuit:
The LDR will now form a voltage divider with the resistor. As light intensity changes, the resistance of the LDR changes, which in turn affects the voltage at the analog pin A0.

Now, open the code editor in Tinkercad or the Arduino IDE, and enter the following code:





  
    
    Shadow Box Example
  
  
   // C++ code

int sensorValue = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}

void loop()
{
sensorValue = analogRead(A0); // for reading the value
Serial.println(sensorValue); // for print the value
analogWrite(9, map(sensorValue, 0, 1023, 255, 0));
delay(100); // Delay a little bit to improve simulation performance
}
Result:-
Observe the Serial Monitor:
As the light intensity on the LDR changes, the readings will vary between 0 (dark) to 1023 (bright).
You can test this by changing the light intensity near the LDR in the Tinkercad simulation or by covering the LDR physically with your hand or an object to simulate changes in light.

Requirments:-
Arduino Uno board
TMP36 temperature sensor
LED
220-ohm resistor (for the LED)
Jumper wires
Breadboard (optional)



Connections:
Temperature Sensor:
Left Pin (VCC): Connect to the 5V pin on the Arduino.
Middle Pin (Signal): Connect to Analog Pin A0 on the Arduino.
Right Pin (GND): Connect to GND on the Arduino.
LED: Anode (long leg): Connect to Digital Pin 13 on the Arduino through a 220-ohm resistor.
Cathode (short leg): Connect to GND.
Code:




  
    
    Shadow Box Example
  
  
   // C++ code 
int red = 12;
void setup() {
pinMode(red, OUTPUT);
}
void loop() {
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(1000);
}
Click on Start Simulation.


Result:
Outputs a voltage proportional to the temperature.
The formula (voltage - 0.5) * 100 converts the voltage to Celsius.
LED Indicator: Provides a visual indication when the temperature exceeds the set threshold (30°C in this example).

Requirments:-
Arduino Uno board
Potentiometer (to simulate variable readings)
Breadboard
Jumper wires
Optional: LED or LCD for output visualization

Connections:
Use a potentiometer to simulate humidity or temperature changes.
Connect the potentiometer's middle pin to an analog pin on the Arduino (e.g., A0).
Connect the potentiometer's other pins to VCC (5V) and GND
Code:





  
    
    Shadow Box Example
  
  
   
void setup() {
Serial.begin(9600);
Serial.println("Simulated DHT11 Sensor");
}

void loop() {
int sensorValue = analogRead(A0); // Read the potentiometer
float humidity = map(sensorValue, 0, 1023, 20, 90);

Serial.print("Simulated Humidity: ");
Serial.print(humidity);
Serial.println(" %");

delay(1000); // Wait for 1 second
}
Click on Start Simulation.


Result:
The potentiometer acts as a substitute for the DHT11, simulating varying humidity values. The readings are shown in the Serial Monitor.
Expected Output in Serial Monitor:
The values will vary as you turn the potentiometer, simulating changes in humidity.

Requirments:-
Arduino Uno board
Breadboard
Phototransistor
LED
220Ω or 330Ω Resistor (Current-limiting for LED)

Connections:
Phototransistor:
Collector → +5 V (or battery +)
Emitter → Arduino Pin 2 and GND through 10 kΩ

LED:
Anode (long leg) → Arduino Pin 13
Cathode (short leg) → GND via 220 Ω resistor

Code:





  
    
    Shadow Box Example
  
  
   
int sensorPin = 2;   // Phototransistor connected to pin 2
int ledPin = 13; // LED connected to pin 13

void setup() {
pinMode(sensorPin, INPUT); // Set sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication
}

void loop() {
int sensorValue = digitalRead(sensorPin); // Read sensor value

if (sensorValue == LOW) { // Line detected (black surface)
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Line detected!"); // Print to Serial Monitor
} else { // No line detected (white surface)
digitalWrite(ledPin, LOW); // Turn off LED
Serial.println("No line detected.");
}

delay(100); // Small delay for stability
}
Click on Start Simulation.


Result:
When the phototransistor receives light, it conducts current, pulling pin 2 HIGH.
When the phototransistor is blocked from light (e.g., detecting a black line), pin 2 goes LOW.
The code turns LED ON when the line (black surface) is detected and OFF when not detected.

Requirments:-
Arduino Uno board
Ultrasonic Sensor (HC-SR04)
Breadboard
Jumper Wires

Connections:
HC-SR04 Ultrasonic Sensor Pins:

VCC: Connect to Arduino 5V.
GND: Connect to Arduino GND.
Trig: Connect to Arduino digital pin 9.
Echo: Connect to Arduino digital pin 10.

Code:





  
    
    Shadow Box Example
  
  
   

// Define pins for the ultrasonic sensor
const int trigPin = 9;
const int echoPin = 10;

// Variables to store duration and distance
long duration;
int distance;

void setup() {
// Initialize the Serial Monitor
Serial.begin(9600);

// Set the trigPin as output and echoPin as input
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Send a 10us HIGH pulse to trigger the sensor
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Read the echoPin and calculate the duration
duration = pulseIn(echoPin, HIGH);

// Calculate distance in cm
distance = duration * 0.034 / 2; // Speed of sound = 0.034 cm/us

// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

delay(500); // Delay for readability
}
Click on Start Simulation.


Result:
If an object is placed in front of the sensor, the distance value will change accordingly.
The values update every 500ms (as per the delay in the loop() function).
When an object is far away, the readings will be higher.
When an object moves closer, the readings will decrease.
If the object is too close (<2 cm) or out of range (>400 cm), the sensor may give inaccurate values or 0 cm.

Requirments:-
Arduino Uno board
PIR (Passive Infrared) motion sensor.
LED
Resistor 220-ohms

Connections:
PIR Motion Sensor:

Connect the VCC pin to the Arduino's 5V pin.
Connect the GND pin to the Arduino's GND pin.
Connect the OUT pin to digital pin 2 on the Arduino.

LED :
Connect the longer leg (anode) of the LED to a 220-ohm resistor, then to digital pin 13.
Connect the shorter leg (cathode) to GND.
Code:





  
    
    Shadow Box Example
  
  

// PIR Motion Sensor connected to digital pin 2
const int PIR_PIN = 2;
// LED connected to digital pin 13
const int LED_PIN = 13;

void setup() {
pinMode(PIR_PIN, INPUT); // Set PIR pin as input
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
}

void loop() {
int motionState = digitalRead(PIR_PIN); // Read the PIR sensor

if (motionState == HIGH) {
// Motion detected
digitalWrite(LED_PIN, HIGH); // Turn on LED
Serial.println("Motion Detected!");
} else {
// No motion
digitalWrite(LED_PIN, LOW); // Turn off LED
Serial.println("No Motion");
}

delay(500); // Delay for stability
}
Click on Start Simulation.


Result:
Test the motion sensor:
In the simulation, hover over the PIR motion sensor, and you'll find a toggle to simulate motion detection.
Toggle it to see the LED light up and the Serial Monitor log the motion state.