im doing a Project at school that i need some help with, im new to arduino and need some help with the code. im trying to get the display to Count when a object go past the sensor. im using an 16x2 display with a IR PIR sensor and arduino UNO plate. would love some help on how to do this!
What object is going by the sensor? A PIR sensor measures Passive Infrared. If you object is not emitting Infrared, it won't be detected, regardless of what code you write.
The PIR sensor is infrared sensor that detect motion. the sensor are working since i tried with a simpel code to detect movement using my hand and a shirt. the display works aswell since i tested with "hello world" code, so everything works!
This is the code im using right now, so the display react with number one when motion is detected. i need the display to count the number of times my hand go past the sensor. right now the number 1 pile next to eachother and doesnt add like it should, i want the number 1 to dissapear and number 2 should replace it.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int inputPin = 2;
int pirState = LOW;
int val = 0;
void setup() {
lcd.begin(16, 2);
pinMode(inputPin, INPUT);
Serial.begin(9600);
// Print a message to the LCD.
lcd.print(“Summa”);
You need to look at the state change detection example. The PIR sensor tells you that it is, or is not, detecting motion. If you keep track of the answer you got last time you asked, you can tell if motion HAS BEGUN or if motion HAS ENDED.
You decide which event is important, and increment a counter when that even occurs.
thank you so much for the code! but now i got a new problem im trying to connect another sensor on the board but dont manage to get the code right, i tried using int inputPin = 3; but it wont work.
thanks for answer!
If it compiled, you can be certain that it works. That it doesn’t do what you expect means only that your expectations are wrong.
Post the code and a schematic, and describe your expectations, as well as any observations about what the code actually does, if you want us to help you align your expectations with reality.
I will send it as soon as i got the items with me, but is it possible to copy the code and paste it under, sending the code for you to understand what i mean.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int inputPin = 2;
int inputPin2 = 3;
int hittils;
void setup() {
lcd.begin(16, 2);
pinMode(inputPin, INPUT);
pinMode(inputPin2, INPUT);
lcd.setCursor(1, 0);
lcd.print(" Summa");// Print a message to the LCD.
}
void loop()
{
digitalRead(inputPin);
while (!digitalRead(inputPin)); // vent tills 1
hittils += 1; // ök telleren
lcd.setCursor(0, 10);
lcd.print(hittils);
while (digitalRead(inputPin)); // vent tills 0
digitalRead(inputPin2);
while (!digitalRead(inputPin2)); // vent tills 1
hittils += 1; // ök telleren
lcd.setCursor(0, 10);
lcd.print(hittils);
while (digitalRead(inputPin2)); // vent tills 0
the project is to have two sensors, one is counting +1 and the other is counting +2, i dont understand what you mean with the answer im beginner on arduino so i understand if you get angry
I want one sensor to count +1 and the other +2, right now sensor number 2 dont count, (the +2 sensor) so i need a code that makes the 2 sensors count with eachother, for exampel, a item go past sensor 1, display count +1. something go past sensor 2, +2, and display show 3. ask me again if you dont understand. thanks
I don't understand how your switches are wired.
I don't understand what the code you posted actually does.
I don't understand why you currently do the same thing when either switch is pressed.
Hi again! i have changed the code but it still wont work! so the code is this: but all that is happening is that sensor one is working and the other wont count, please help!
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int inputPin = 2;
int inputPin2 = 3;
int hittils;
void setup() {
lcd.begin(16, 2);
pinMode(inputPin, INPUT);
pinMode(inputPin2, INPUT);
lcd.setCursor(1, 0);
lcd.print(" Summa");// Print a message to the LCD.
}
void loop()
{
digitalRead(inputPin);
digitalRead(inputPin2);
while (!digitalRead(inputPin));
while (!digitalRead(inputPin2)); // vent tills 1
hittils += 1; // ök telleren
lcd.setCursor(0, 10);
lcd.print(hittils);
while (digitalRead(inputPin)); // vent tills 0
while (digitalRead(inputPin2));
PaulS:
I don't understand how your switches are wired.
I don't understand what the code you posted actually does.
I don't understand why you currently do the same thing when either switch is pressed.
I will post the curcit in a minute.
the code is used for two sensors, one to count +1 and the other +2.
because im a noob on this and dont understand xD