I'm having trouble researching a video that would solve my problem, but it didn't. I'm searching for a tutorial that when an Infrared Sensor detected a motion a new text will pop up at the 16x2 lcd, it's just like counting but it will show a different text.
Welcome to the forum
What you want to do sounds simple
Which Arduino board do you have ?
What type of LCD do you have ?
Can you detect a motion and print a message to the Serial monitor ?
Can you print a message to the LCD ?
Which Arduino board do you have ? I have an Arduino Uno
What type of LCD do you have ? The LCD that i have is 16x2 I2C
Can you detect a motion and print a message to the Serial monitor ? I couldn't. I wanted a code that a text1 will show at start and when the Infrared Sensor detected a motion a text2 will show but the text1 will clear
would help if you posted the code
You can start here to learn how to use the ir sensor
There are numerous LCD examples out there
I don't have the exact code sadly
What is your intention:
- Learn how to develop sketches for Arduino?
- Get support how to search the internet for information?
- Let somebody else solve your application?
It makes a big difference ...
It is unlikely that someone wrote a tutorial on exactly what you want to do.
@2112 links to somewhere to learn about the sensor. You can google and find how to use the LCD. Both as independent things.
Knowing how to use both will mean you've probably learned enough in general to combine the part that puts stuff on the LCD and the part that senses motion.
Divide and conquer. It's easy to sense motion. It's easy to write one thing, or another, on an LCD display accordian to some condition, like something you sense or whatever.
a7
For the LCD, read and follow Post #2 of the below thread. The hd44780 library is the best available.
The example is for a 4 bit parallel configuration. Let us know if you're using I2C.
This is doing a couple things at the same time:
- Change detection on the sensor
- Updating the screen
Look into the built-in state change detection example, and consider put the screen updating in the counting part.
Well, videos aren't necessarily your best option, because there are so many possible projects out there that the likelihood of finding a video worth its salt that does what you exactly want is pretty low.
That means you'll spend a lot of time going down dead end paths that lead to frustration.
What you're after is a finite state machine.
Every time your sensor detects motion, you will increment a variable of the appropriate size by one. A byte is good enough, 0-255 gives you 256 states on the machine, where each state points to a different phrase on the LCD screen.
If i was making your specific project, I would reserve 0 for the default state, as in showing nothing and I would use state 255 as the state where you clear the LCD screen and set up the cursor for states 1 to the number of phrases you have that just prints the stuff you want, but that's just how I would approach it.
To implement a finite state machine, you'll want to look at the example sketches StateChangeDetection and SwitchCase where State change detection uses a hardware event to drive a state variable defined in your code, and switch/case is the general control structure to implement the state machine (as opposed to if/else if/else).
Here's a sketch to sort of give an idea of what I mean. Uses just the millis()
clock function to automatically increment a variable that links to a function that might be reused, if you can imagine that the whole code is a really boring video game that you just watch instead of play.
/* April 03, 2024
revised December 11, 2024 to make the concept a bit more obvious
Hallowed31
State/Mode Machine - events/functions driven by built in
millis timer and nothing else
It's like a game, only much less fun. Just watch the game play itself!
Circuit: just an Arduino
Set Serial monitor to 9600 baud, no line ending
Working as intended. Tested on Uno R3
*/
byte level = 0; // you could have 0 - 255 levels if you wanted.
unsigned long currentTime;
unsigned long lastTimeAround;
void setup() {
Serial.begin(9600);
// just the sketch name so I know what's loaded on my Arduino
Serial.println(F("automaticByteDrivenStateMachine"));
delay(500);
Serial.println();
level = 0;
currentTime = 0;
lastTimeAround = 0;
}
void loop() {
// start free running timer, this never stops running in the "game"
currentTime = millis();
/* set conditional statement whose condition is to
check built in millis clock and announce what "game"
level it's on every two seconds */
if (currentTime - lastTimeAround > 2000) {
switch (level) {
case 0:
zero();
break;
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
}
// synch the time marker to the free running clock
lastTimeAround = currentTime;
}
}
void zero() {
// you might think of this as reset or awaiting players
Serial.println("level 0");
level += 1; // increment level by one, to level 1
}
void one() {
// this might be level one
Serial.println("level 1");
level += 1; // exit to level 2
}
void two() {
// level two
Serial.println("level 2");
level += 1;
}
void three() {
// and so on
Serial.println("level 3");
level += 1;
}
void four() {
Serial.println("level 4");
level = 0; // reset to level 0
}
Here's a good tutorial (not mine) on just using the PIR sensor as they can be a little unruly if you don't know how to tame them.
Another trick with these is to set them a couple inches inside a toilet paper tube or something like that to sort of give you lo-fi directionality and avoid false triggers from unintended passers by.
my intentions are Learn how to develop sketches for Arduino & Let somebody else solve my applications
try some of the example sketches on the wokwi.com simulator
So feel free to check this out...
this is the thing that i wanted to happen but i dont want it to be a counter but it will just show a new text
this is just a counter code that i got it from youtube
is it just similar to a IR Infrared Sensor??
can you explain it to me how does the each codes work?
the code slightly satisfies my problem