Sparki the fireman

Now I’ve messed around with the temperature sensor, and learnt about how it works, it’s time to apply it something practical. Temperature sensors make me think of fire, so I made a code for Sparki to detect a fire and call for help. In the real world, there are plenty of autonomous robots that can enter a burning building and find the location of the fire.

 

#include <Sparki.h> // include the sparki library
float tempC;
float tempA;
float temp1;
float temp2;
int reading;
int tempPin = 8;

void setup()
{
analogReference(INTERNAL);
reading = analogRead(tempPin);
tempA=reading/9.31-10;
sparki.clearLCD();
sparki.print(tempA);
sparki.updateLCD();
delay(1000);
reading = analogRead(tempPin);
tempA=reading/9.31-10;
sparki.clearLCD();
sparki.print(tempA);
sparki.updateLCD();
delay(3000);
}

void fire()

{

sparki.beep();

sparki.clearLCD();
sparki.drawString(10,1,”Fire”);
sparki.updateLCD();
delay(1000);

}

void loop()
{

sparki.clearLCD();
sparki.drawString(10,1,”Checking temperatures”);
sparki.updateLCD();
delay(2000);
reading = analogRead(tempPin);
tempC=reading/9.31-10;
sparki.clearLCD();
sparki.print(tempC);
sparki.updateLCD();
delay(1000);
if (tempC>=tempA)
{
tempA=tempC;
sparki.moveForward(10);

fire();
}
else
{
sparki.moveRight(90);
delay(2000);
reading = analogRead(tempPin);
temp1=reading/9.31-10;
sparki.clearLCD();
sparki.print(temp1);
sparki.updateLCD();
delay(1000);
sparki.moveLeft(180);
delay(2000);
reading = analogRead(tempPin);
temp2=reading/9.31-10;
sparki.clearLCD();
sparki.print(temp2);
sparki.updateLCD();
delay(1000);
if (temp1>temp2)
{
tempA=temp1;
sparki.moveRight(180);
sparki.moveForward(10);

fire();

}
else if(temp1<temp2)
{
tempA=temp2;
sparki.moveForward(10);

fire();
}
}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s