0% found this document useful (0 votes)
19 views9 pages

Code

The document contains an Arduino sketch for controlling four servos based on temperature and distance measurements. It uses a thermistor to monitor temperature and an ultrasonic sensor to measure distance, activating servos and an LED based on the readings. If the temperature exceeds 100°C, a buzzer is activated and the LED remains on.

Uploaded by

Arduino Basic
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)
19 views9 pages

Code

The document contains an Arduino sketch for controlling four servos based on temperature and distance measurements. It uses a thermistor to monitor temperature and an ultrasonic sensor to measure distance, activating servos and an LED based on the readings. If the temperature exceeds 100°C, a buzzer is activated and the LED remains on.

Uploaded by

Arduino Basic
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

#include <Servo.

h>

Servo LF;

Servo RF;

Servo LH;

Servo RH;

int pos = 90;

const int trigPin = 3;

const int echoPin = 4;

long duration;

int distance;

int safetyDistance;

const int LedPin = 5;

int ThermistorPin = 0;

int Vo;

float R1 = 10000;

float logR2, R2, T;

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

const int Buzzer = 6;

void setup()

[Link](9);

[Link](8);

[Link](10);

[Link](11);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPin, INPUT);// Sets the echoPin as an Input

pinMode(LedPin, OUTPUT); //Sets the LedPin as an Output

pinMode(Buzzer, OUTPUT); //Sets the Buzzer as an Output

[Link](9600); // Starts the serial communication

void loop() {

int pos = 90;

[Link](pos);

[Link](pos);

[Link](pos);

[Link](pos); //Initialized position for else condition

Vo = analogRead(ThermistorPin); //read data from thermistor

R2 = R1 * (1023.0 / (float)Vo - 1.0);

logR2 = log(R2);

T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));

T = T - 273.15;

[Link]("Temperature: "); //in celcius

[Link](T);

if (T <= 100) //applied the temp condition for whole [Link] will check the temperature once for a
loop

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(30);

for (pos = 90; pos <= 130; pos += 1) //1

[Link](pos);

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 90; pos >= 70; pos -= 1) //2

[Link](pos);

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);


// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 90; pos >= 70; pos -= 1) //3

[Link](pos);

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)


{

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 130; pos >= 90; pos -= 1) //4

[Link](pos);

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 90; pos >= 50; pos -= 1) //5

{
[Link](pos);

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 70; pos <= 90; pos += 1) //6

[Link](pos);

delay(50);

// Clears the trigPin


digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 70; pos <= 90; pos += 1) //7

[Link](pos);

delay(50);

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance >= 10)

digitalWrite(LedPin, LOW);

delay(150);

for (pos = 50; pos <= 90; pos += 1) //8

[Link](pos);

delay(50);

else

digitalWrite(LedPin, HIGH);

else

digitalWrite(Buzzer, HIGH);

digitalWrite(LedPin, HIGH);

You might also like