Introduction: Adopteer Een Schaap

What do we want to create?

We want to give the Wijkpark in Rotterdam a new, refreshing and enjoyable atmosphere. We want to strengthen the park and give it a positive vibe. There's not a lot of visitors in this park and we want to change that with our Project: Adopteer een Schaap.

To give the park more interaction we decided to make a score scavenger path in the park itself. We figured that if we place sensors, that can detect when someone passes it, all over the place we can make a person achieve points for walking through every sensor. After you get enough points, you'll be able to win a prize in the park by redeeming all the points on your web application.

Today I want to start creating the Arduino scoreboard prototype. We're going to start with making a prototype on Tinkercad.com

My task in this project is to create the Arduino sensor path, the moment something passes a sensor they'll get a point on a scoreboard. I will show you how to do it in this tutorial.

We want a sensor at:

- The gate, for if you walk into the park - Near the playground, if you interact with the various "attractions" you will get points too - Near the animal farm, for interaction with all the animals.

So we will be looking at 3 sensors, each placed at three different places. Obviously we want to avoid cheating: Someone could easily cheat the system if they keep earning points by walking through a single sensor-path over and over again. So that's why we're going to implement a "maximum points achieved" code in our Arduino code.

Step 1: We’re Going to Start Building a Prototype in Tinkercad:

First we will try to get a LCD screen on the Arduino where we can display our scoreboard.


#include

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

void setup() { lcd.begin(16, 2); lcd.print("hello, world!"); }

void loop() {

// This is the code we use to activate the LCD screen //

Step 2: Hello World

As you can see, we connected the LCD screen to the Arduino and we gave it a “Hello world” function. Now that we have the display running let’s try to make a scoreboard with a simple button. Each button click should add a score to the scoreboard.

Step 3: First We Add the Button and Now We’re Going to Write the Following Code:

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

int button = 7; int buttonState = 0;

int count = 0;

void setup() { lcd.begin(16,2); pinMode(button, INPUT); }

void loop() { buttonState = digitalRead(button); if(buttonState == LOW) {

lcd.setCursor(0,0); lcd.print(count++);

} }

Step 4: Last Tweak.

Now we can see that we set the button up that it counts the moment you press on it. Obviously it’s not buttonState == LOW but HIGH when you use it in real life, but something’s wrong with the button and that is that it’s always ON for some reason on this Site. So be in mind! On line 20 it’s supposed to be buttonState == HIGH when you’re going to create this with real life components.

Step 5: So What Do We Have Now?

We have a small scoreboard with a button. The moment you push the button you will achieve a point on the scoreboard until you release the button. In reality we want 2 counters, one that keeps track of all score collected and one that resets after it hits a certain amount of score. Why do we want this? We don’t want someone to constantly get points throughout one day. We want to give them a “cooldown” before achieving more points, thus making it more enjoyable to go to the park everyday to collect your daily amount of points.
We will have to add a delay to our code. Whenever someone achieves a certain amount of points one of the counters will reset to 0 while the maximum count stays the same number it was before. To avoid people from trying to get more points after the counter reset to 0 we will add a delay of a day to our code:

const long oneSecond = 1000; // a second is a thousand milliseconds
const long oneMinute = oneSecond * 60; const long oneHour = oneMinute * 60; const long oneDay = oneHour * 24;

We will switch a button with a touch sensor, 2 touch sensors and this will be the definite code:

#include

int count = 0;

int countTotal = 0;

int TouchSensor = 3;

int TouchSensor2 = 9;

int led = 2;

const long oneSecond = 1000; // a second is a thousand milliseconds

const long oneMinute = oneSecond * 60;

const long oneHour = oneMinute * 60;

const long oneDay = oneHour * 24;

LiquidCrystal lcd(12, 11, 5, 4, 6, 7);

void setup()

{

lcd.begin(16,2);

Serial.begin(9600);

pinMode(led, OUTPUT);

pinMode(TouchSensor2, INPUT);

pinMode(TouchSensor, INPUT);

lcd.setCursor(0,0);

lcd.print("Score:");

}

void loop(){

int touchState = digitalRead(TouchSensor);

int touchState2 = digitalRead(TouchSensor2);

if(touchState2 ==HIGH || touchState ==HIGH) //Read Touch sensor signal

{

digitalWrite(led, HIGH); // if Touch sensor is HIGH, then turn on Serial.println(count++);

Serial.println(countTotal++);

lcd.setCursor(15,1);

lcd.print(countTotal++);

lcd.setCursor(15,0);

lcd.print(count++);

delay(500); if(count == 100)

{

digitalWrite(led, LOW); count = 0; delay(oneDay);

}

} else {

digitalWrite(led, LOW); // if Touch sensor is LOW, then turn off the led }

}