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

Include

This document contains code for an Arduino project that uses an ultrasonic sensor and servo motor to measure distances, display them on an LCD screen, and drive a robot based on the distances. The code initializes an LCD screen on pins 12-1, attaches a servo motor to pin 13, defines pins and variables for pulse timing of an ultrasonic sensor on pin 10. It takes ultrasonic readings, displays the distances on the LCD in centimeters, and has a function to convert pulse times to distances. It also contains an empty driver function to control robot movement.

Uploaded by

Dra Goen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Include

This document contains code for an Arduino project that uses an ultrasonic sensor and servo motor to measure distances, display them on an LCD screen, and drive a robot based on the distances. The code initializes an LCD screen on pins 12-1, attaches a servo motor to pin 13, defines pins and variables for pulse timing of an ultrasonic sensor on pin 10. It takes ultrasonic readings, displays the distances on the LCD in centimeters, and has a function to convert pulse times to distances. It also contains an empty driver function to control robot movement.

Uploaded by

Dra Goen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <LiquidCrystal.h> #include <Servo.

h>

Servo pingServo; int delayTime = 1000; LiquidCrystal lcd(12, 11, 8, 3, 2, 1); const int pingPin = 10; byte dir=0; byte speed1=250; //250 byte speed2=255; //255 int turn90=600; //110 int turn45=300; //55 int straight=500; int stopTime=200; int IRdistance=0; int treshold=20; void setup () { lcd.begin(16, 2); pingServo.attach(13); } void loop () { long duration, cm; pingServo.write(90); delay(delayTime); pinMode (pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds (2);

digitalWrite(pingPin, HIGH); delayMicroseconds (5); digitalWrite(pingPin, LOW); pinMode (pingPin, INPUT); duration = pulseIn(pingPin, HIGH); cm = microsecondsToCentimeters (duration);

lcd.clear(); lcd.home(); lcd.print(cm); lcd.print(" cm"); delay (1000); } long microsecondsToCentimeters (long microseconds) { return microseconds /29 /4; } void driver ()

You might also like