/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: Car Automation
- Source Code compiled for: Arduino Uno
- Source Code created on: 2024-04-21 06:56:58
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* give a Arduino code for robotic car...... the */
/* robotic car include motor driver, ultrasonic */
/* sensor for obstacle avoiding and rotate randomly, */
/* servo motor, 2 IR sensors for line follow, buzzer */
/* for horn and LDR sensor for light emitting. all */
/* sensors are */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/ErickSimoes/Ultrasonic
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void obstacleAvoidance(void);
void lineFollowing(void);
void randomRotation(void);
void horn(void);
void lightEmitting(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Ultrasonic_sensor_HC_SR04_Echo_PIN_D3 = 3;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2 = 2;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Ultrasonic ultrasonic(Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2, Ultrasonic_sensor_HC_SR04_Echo_PIN_D3);
void setup(void)
{
// put your setup code here, to run once:
pinMode(Ultrasonic_sensor_HC_SR04_Echo_PIN_D3, INPUT);
pinMode(Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2, OUTPUT);
}
void loop(void)
{
// put your main code here, to run repeatedly:
updateOutputs(); // Refresh output data
obstacleAvoidance(); // Perform obstacle avoidance
lineFollowing(); // Perform line following
randomRotation(); // Perform random rotation
horn(); // Activate the horn
lightEmitting(); // Adjust LED lights based on LDR sensor
delay(100);
}
void updateOutputs(void)
{
digitalWrite(Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2, Ultrasonic_sensor_HC_SR04_Trigger_PIN_D2_rawData);
}
void obstacleAvoidance()
{
// Code for obstacle avoidance using ultrasonic sensor
unsigned int distance = ultrasonic.read();
if (distance < 10)
{
// Stop the car and take evasive action
// (e.g., turn, reverse, etc.)
}
}
void lineFollowing()
{
// Code for line following using IR sensors
// Read IR sensor values and adjust the car's direction accordingly
}
void randomRotation()
{
// Code for random rotation
// Rotate the car randomly to change its direction
}
void horn()
{
// Code for horn using buzzer
// Activate the buzzer to produce sound
}
void lightEmitting()
{
// Code for light emitting using LDR sensor
// Read LDR sensor values and adjust the car's LED lights accordingly
}