Professional Documents
Culture Documents
Roll No. : 2
Class : 7CE-A
Experiment No. : 1
20SOECE11004_Krupa Bhalani 1
1. What is Tinkercad?
Code:
void setup()
{
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(13, HIGH);
delay(1000); //Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
digitalWrite(13, LOW);
delay(1000); //Wait for 1000 millisecond(s)
}
Output:
20SOECE11004_Krupa Bhalani 2
3. Write a program to control brightness of the led in.
Code:
int del = 5;
int a = 0;
void setup()
{
pinMode(3, OUTPUT); // LED control pin is 3, a PWM capable pin
}
void loop()
{
for (a = 0 ; a < 256 ; a++)
{
analogWrite(3, a);
delay(del);
}
for (a = 255 ; a >= 0 ; a--)
{
analogWrite(3, a);
delay(del);
}
delay(200);
}
Output:
20SOECE11004_Krupa Bhalani 3
4. Write a program to run motor in Tinkercad.
Code:
// Motor control pins
const int motorPin = 9;
const int enablePin = 10;
void setup()
{
// Initialize motor control pins as outputs
pinMode(motorPin, OUTPUT);
pinMode(enablePin, OUTPUT);
// Set the enablePin high to enable the motor
digitalWrite(enablePin, HIGH);
}
void loop()
{
// Run the motor in one direction
motorOn();
delay(2000); // Run the motor for 2 seconds
// Stop the motor
motorOff();
delay(1000); // Pause for 1 second
// Run the motor in the opposite direction
motorReverse();
delay(2000); // Run the motor in reverse for 2 seconds
// Stop the motor
motorOff();
delay(1000); // Pause for 1 second
}
// Function to turn on the motor
void motorOn()
{
digitalWrite(motorPin, HIGH);
}
// Function to turn off the motor
void motorOff()
{
digitalWrite(motorPin, LOW);
}
// Function to run the motor in the reverse direction
void motorReverse()
{
digitalWrite(motorPin, LOW); // Turn off the motor
20SOECE11004_Krupa Bhalani 4
digitalWrite(enablePin, LOW); // Reverse the motor by changing the direction of
current flow
digitalWrite(motorPin, HIGH); // Turn on the motor in reverse direction
}
Output:
20SOECE11004_Krupa Bhalani 5