I am new to Arduino Programming and I have bought an Arduino UNO , Ultrasonic Sensor (HC-SR04), A Piezo Buzzer, IR Receiver (VS1838B) and a RGB LED....
I wrote a program to Calculate Distance form the Ultrasonic Sensor to an object and a Processing Sketch to Display the results which I am attaching below:-(Distance_Sensor_v4.ino and Distance_Sensor_v4.pde)
Now I want to use the IR Receiver to increase the Distance Threshold which makes the buzzer beep...I mean I want to press 1 in my remote to keep the distance about 5 cm after which the buzzer beeps, and when I press 2 the distance becomes 10 cm and so on...I want to stop everything when I press 0 in my remote...
I have already found out the hex codes of my remote buttons but the program makes the task harder...
Please help me with the program that I have already written :-(Distance_Sensor_v5.ino and Distance_Sensor_v6.ino).
I am using the "IRremote.h" and "NewTone.h" Libraries....
The main problem is that the "irrecv.resume();" pauses the program and waits for the IR input but I want the program to run continuously till I give an IR Input...
Start small. Have you written a program that does nothing else except detect the IR codes and display them on the Serial Monitor?
Then extend that program so it sets the value of a variable to 5 when one button is pressed and sets it to 10 when another button is pressed and display the value of the variable on the Serial Monitor.
When you can do that you will have 80% of your problem solved.
If your program is organized as a series of short single-purpose functions and if the learning-code I have suggested is also written as a short function that can be dropped into the bigger program you will have 90% of the job done. Maybe have a look at Planning and Implementing a Program
...R
PS ... it's much easier for people to help you if you include short programs in your Post using the Code button </>
Yeah I have done it but the main problem is the " irrecv.resume(); " command waits and pauses the program till the IR receiver gets another IR code..
I want to loop a series of codes till another IR code is detected by the IR Sensor but it does not happen. Instead the programs stops executing till I press another button in the IR remote...
resume() does not block. Your code only does things if the IR library has successfully decoded something because of your initial if() statement. If you want the code to continue, it needs to be outside of that if() statement. You also are calling .resume() every time through the loop but you should only call it after a successful decode().
To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.
To go back and put your code in a code box, in the bottom right of your post, select "more" and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.
But now the problem is I need to press the IR Remote button two times because when I press once the program moves to the "irrecv.resume();" command and waits for another IR Input and I need to press the button again.