0% found this document useful (0 votes)
53 views3 pages

Code For Python

This document contains an Arduino sketch for controlling a motor based on acceleration input and speed limits. It utilizes a LiquidCrystal display to show the current acceleration, speed limit, and final speed. The code reads inputs from various pins to adjust motor speed accordingly and displays relevant information on the LCD screen.

Uploaded by

Sumit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Code For Python

This document contains an Arduino sketch for controlling a motor based on acceleration input and speed limits. It utilizes a LiquidCrystal display to show the current acceleration, speed limit, and final speed. The code reads inputs from various pins to adjust motor speed accordingly and displays relevant information on the LCD screen.

Uploaded by

Sumit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<LiquidCrystal.

h>

LiquidCrystal lcd(13,12,11,10,9,8);

int motor=6;
int accel=A0;
int d1=A1;
int d2=A2;
int d3=A3;
int d4=A4;

int speedx,limit;
int ACC;
int currentSpeed=-1;

void setup() {

Serial.begin(9600);
pinMode(d1,INPUT);
pinMode(d2,INPUT);
pinMode(d3,INPUT);
pinMode(d4,INPUT);
pinMode(7,INPUT);

pinMode(motor,OUTPUT);

lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Car Speed RF");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Acc:000 Lim:000");
lcd.setCursor(0,1);
lcd.print("FinalSpeed :000");

}
void loop() {

Serial.print(currentSpeed);
Serial.print(" ");
Serial.println(analogRead(A0));

limit=100;
//if(digitalRead(7)==HIGH)
//{
if(digitalRead(d1)==LOW)
limit=20;
else if(digitalRead(d2)==LOW)
limit=40;
else if(digitalRead(d3)==LOW)
limit=60;
else if(digitalRead(d4)==LOW)
limit=80;
//}

ACC=analogRead(accel)/10.23;
lcd.setCursor(4,0);
lcd.print(ACC/100);
lcd.print((ACC/10)%10);
lcd.print(ACC%10);

lcd.setCursor(12,0);
lcd.print(limit/100);
lcd.print((limit/10)%10);
lcd.print(limit%10);

if(ACC>limit)
ACC=limit;

lcd.setCursor(12,1);
lcd.print(ACC/100);
lcd.print((ACC/10)%10);
lcd.print(ACC%10);
//analogWrite(motor, 255-(ACC*2.55) );

if(currentSpeed==-1)
currentSpeed=ACC;

if(currentSpeed!=ACC)
{
if(currentSpeed>ACC)
for(int i=currentSpeed;i>ACC;i--)
{
lcd.setCursor(12,1);
lcd.print(i/100);
lcd.print((i/10)%10);
lcd.print(i%10);
analogWrite(motor, 255-(i*2.55) );
delay(15);
}
if(currentSpeed<ACC)
for(int i=currentSpeed;i<ACC;i++)
{
lcd.setCursor(12,1);
lcd.print(i/100);
lcd.print((i/10)%10);
lcd.print(i%10);
analogWrite(motor, 255-(i*2.55) );
delay(15);
}
currentSpeed=ACC;
}
}

You might also like