New to Arduino and need help to a project

Hello everyone,

I'm pretty much new to Arduino. I thought that it would be easy to learn Arduino, but I'm having a hard time, probably because I'm getting to hold to learn...lol

I don't know if this is the right place to ask, but I'm looking for someone to help me along a project (probably small to some of you).

I've attached a Fritzing image of what I want to do. The goal of this project is to calculate the speed of an object traveling between to censors and reporting the result to the LCD.

Once it crosses the first censor it starts the timer and stops when crossing the second censor. The time value is then put into a formula with the distance between the censors and will convert the result into MPH.

This project is for model railroading, I want to know the speed of my model locomotive as if it was real.

The problem I have is that for the last 2 months I've been trying to build a sketch and I can't seem to comprehend the programming aspect of Arduino.

If anyone is willing to help, it would be greatly appreciated
Thank You
Lloyd

If you are asking for help with your code.
Always show us your current compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

Thanks Larry for the reply.
Sorry I don't have a sketch, since I have no idea about programming, that is why I'm asking for someone's help. I know about the parts, I know what I need it to do, but how is a complete mystery.

If it's not the right place to ask, is there such a place?

Thanks

Do you have any components....Arduino, LED's, jumper wires, breadboard....you know, the usual suspects?

Yes I do. I have all the parts shown in my attachment.

The problem I have is that for the last 2 months I've been trying to build a sketch and I can't seem to comprehend the programming aspect of Arduino.

The first place to start is with the tutorial Planning and Implementing an Arduino Program.

Once it crosses the first censor it starts the timer and stops when crossing the second censor. The time value is then put into a formula with the distance between the censors and will convert the result into MPH.

This is a correct approach. Please provide some documentation on the sensors.

Can you read the sensors, and can tell if there is something in front of them or not?

Do you have the lcd display and can print a "Hello World" library sketch?

Lloyd,
The key to success is taking baby steps. Define your goal then break it down into smaller pieces. If you get stuck, divide it again until you get it. I'm no expert but you will find brilliant help here on the forum if you make the effort.

I see a handful of modules in your attach. Each of them has example programs to make it work, so it's just a matter of altering that code to work together. The only part you will have to do on your own is the timing part, which for what you are doing shouldn't really be that hard.

Download the code examples for the IR sensors and lcd. make each work on it's own. Only then should you try making them work together.

Hi cattledog,

Yes I can read the sensors, I was able to do an example of the sensors and it work.
Yes I have the LCD sketch and I was also able to do the example.
The sensors I have are "IR Infrared Obstacle Avoidance Sensor Module for Arduino Smart Car Robot"

I can follow instructions for individual parts, but when I need to put a bunch of parts together, I'm totally lost.

I've watched Technology Tutorials "Arduino lessons" and "Arduino step by step 2017" from Udemy. I did learn individual stuff, but not enough to comprehend.

Yes I can read the sensors, I was able to do an example of the sensors and it work.
Yes I have the LCD sketch and I was also able to do the example.

Can you write some code which combines the two. Read a sensor and print the reading to the lcd. Post what you come up with here.

Please read this on how to post code correctly using "code tags". See section 7.

Use Ctrl+T for formatting. You can also do this with "auto format" in tools section of the ide sketch window.

Your code will be orderly, and appear in a special scrolling box which makes it easier for those who want to help you.

If the code you post does not compile, be sure to copy and paste the error messages with your post. If the code does not do what you want it to do(read a sensor and diplay the reading) please explain what it is not doing correctly.

Example of code which appears in a code box

//Your code will appear in a window like this

cattledog:
Can you write some code which combines the two. Read a sensor and print the reading to the lcd. Post what you come up with here.

I can copy a code that makes the censors work, I can copy a code for my LCD to work, but I can't write any codes that combine what so ever.

I have a civil engineering background, I can draw plans for buildings but when it comes to programming, I have no clue.

I can copy a code that makes the censors work, I can copy a code for my LCD to work, but I can't write any codes that combine what so ever.

Here is a tutorial on how to combine two codes. http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Basically you will combine the global variables and other stuff which is before setup(). Then you will combine the setup() of the two codes and the loop() of the two codes. The compiler will tell you if you are going wrong.

Give it a try.

If you are totally confused, post your best effort at creating one mash up with only one setup() and one loop(). Copy and past the two codes together, and remove any obvious duplication, like the duplicated setup() function and the duplicated loop() functions. The compiler will help guide you.

EDIT:

The way I combine two sketches is to have three ide windows open. One with each of the two sketches to be combined, and a third one which starts with the bare minium example from the basic examples section of the ide. Then just copy and past the setup code from the two sketches into the new one.

//include all the libraries and declare global variables up here
//copy and paste all the stuff from before setup from each of the two sketches here

void setup() {
  // put your setup code here, to run once:
  //copy and paste the setup code from each of the two sketches here

}

void loop() {
  // put your main code here, to run repeatedly:
  //copy and paste the loop code from each of the two sketches here

}

Ok did some reading and lots of it is over my head.
But, I did combine 2 files like said and it compiled with no problems
Both the censors and LCD sketch

I also have the formula to calculate the speed between both censors and convert it to MPH
T = timestop - timestart
V = distance between the 2 censors / T
MPH = V * 4.943182 / T

Now I need help to continue. what do I do next?

Wish I had learn some programming when I was younger.

int LED = 13; // Use the onboard Uno LED
int isObstaclePin = 7;  // This is our input pin
int isObstaclePin2 = 9;  // This is our input pin
int isObstacle = HIGH;  // HIGH MEANS NO OBSTACLE
#include <LiquidCrystal.h> // include the library code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(isObstaclePin, INPUT);
  pinMode(isObstaclePin2, INPUT);
  Serial.begin(9600);
  
  lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  lcd.print("hello, world!");  // Print a message to the LCD.
}

void loop() {
  isObstacle = digitalRead(isObstaclePin);
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LED, HIGH);
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LED, LOW);
  }
  delay(20);
   isObstacle = digitalRead(isObstaclePin2);
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LED, HIGH);
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LED, LOW);
  }
  delay(20);
  
  lcd.noDisplay(); // Turn off the display:
  delay(500);  
  lcd.display(); // Turn on the display:
  delay(500);
}

Thanks for the help

Good job getting this done.

I have a civil engineering background, I can draw plans for buildings but when it comes to programming, I have no clue.

If you do that, you can program. It looks like you have some references to study and example to work with. It mostly a matter of logical thinking. The simple language syntax is easily found at Arduino - Home

I think that you have two areas to tackle next.

First, you need to gain familiarity with the lcd. There are many tutorials available. You will need to learn how to use lcd.setCursor() to control the position of what you want to print. Remember there are two rows--row0 and row1, and 16 columns 0 to 15. You will also need to learn how to print blank spaces if you want to clear an area. For example if you print a 3 digit number where there was a four digit number, you will need to clear a space.

I would try and remove the serial prints from the sketch you posted, and play around with where to print "OBSTACLE" and "clear". Try moving them to different rows, and different start stop locations.

One other thing I think will help is to change the pins connected to the lcd.

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

I think that you will want to use pins 2 and 3 for interrupts to read the ir sensors. I did not know if they were analog or digital output, but because they are digital, I would recommend reading them with interrupts. It is a simple rewiring to change pins 2 and 3 to two others. Then you will change the "constructor" to match.

LiquidCrystal lcd(12, 11, 5, 4, "new pin number", "new pin number");

Reference attachInterrupt() - Arduino Reference

You might also want to read a basic tutorial on interrupts

http://gammon.com.au/interrupts

I am leaving on a trip tomorrow noon and won't be back online until Monday. I'll try answer any questions before I go, but you will be on your own(or with help from others) until I return.