Robot Counter

I have been playing with Arduino UNO R3 board for a while. It is included in a starter kit I purchased from eBay, and with its free tutorial lessons, it is quite easy to code in Arduino IDE to control those components in the kit.

PIR sensor as counter

Arduino UNO R3 board

Below is the program in Arduino IDE to make it work.

#include<LiquidCrystal.h>


LiquidCrystal lcd(12,11,5,4,3,2);


int IntialisingTime = 1;

//the time when the sensor outputs a low impulse

long unsigned int lowIn;


//the amount of milliseconds the sensor has to be low

//before we assume all motion has stopped

long unsigned int pause = 5000;

boolean LockLow = true;

boolean pass = true;


int PIRPin = 6; //the digital pin connected to the PIR sensor's output

int LEDPin = 13;

int x = 0;


void setup(){

lcd.begin(16,2);

pinMode(PIRPin, INPUT);

pinMode(LEDPin, OUTPUT);

digitalWrite(PIRPin, LOW);

//give the sensor some time to calibrate

lcd.print("INITIALISING...");

delay(1000);

lcd.clear();

for(int i = 10; i > IntialisingTime; i--){

lcd.setCursor(0,0);

lcd.print("ROBOT");

lcd.setCursor(0,1);

lcd.print("ACTIVATING");

delay(1000);

lcd.clear();

}

}


void loop(){

if(digitalRead(PIRPin) == HIGH){

digitalWrite(LEDPin, HIGH); //the led visualizes the sensors output pin state

if (pass){

x = x+1;

pass = false;

}

if(LockLow){

//makes sure we wait for a transition to LOW before any further output is made:

LockLow = false;

lcd.setCursor(0,0);

lcd.print(" Welcome to ");

lcd.setCursor(0,1);

lcd.print("No.Passing: ");

lcd.print(x);

delay(50);

}

}

if(digitalRead(PIRPin) == LOW){

digitalWrite(LEDPin, LOW); //the led visualizes the sensors output pin state

lcd.setCursor(0,0);

lcd.print(" MakerSpace ");

lcd.setCursor(0,1);

lcd.print("No.Passing: ");

lcd.print(x);

delay(50);

if(!LockLow && !pass){

LockLow = true;

x = x+1;

pass = false;

}

}

}

Project made by William Tseng and Andy Yeh.

This Arduino project was later installed into a Cardboard Robot by Mitchell, displayed at Robotronica.