Wanting a quick help, please!

:weary:[code]
const int in1 = 8;
const int in2 = 9;
const int ENA = 10;
int speed1;
const int ldrpin=A1;
const int sensorpin = 3;
int timer = 5000;
int sensorMax=1023;
int sensorMin=0;
int sensorvalue=0;
void clockwise()//will help in completing the clockwise motion of the motor by giving one pin of the motor low and the other pin high
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(25000);
}
void counterclockwise()//will help in completing the counterclockwise motion of the motor by giving one pin of the motor low and the other pin high
{
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(25000);
}
void wait()//the wait interrupt will wait to display the ads on the billboard with the given delay with both the pin of the motor pin going low
{
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(timer);//as delay time is indicated as timer with 5second
}
void setup()
{
pinMode(8, OUTPUT); //l298n input pin 1 to arduino pin8
pinMode(9, OUTPUT); //l298 input pin 2 to the arduino pin 9
pinMode(10, OUTPUT); //l298n ENABLE pin 1to the arduino 1o pin
pinMode(3, INPUT);//light sensor input to the arduino pin 3
pinMode(A1,INPUT);
Serial.begin(9600); // put your setup code here, to run once:
}
void loop()
{
{
while(analogRead(A1)==LOW)
{
calibrate();
}
sensor value=analogRead(A1);
sensor value=map(sensor value,sensorMax,sensorMin,0,255);
sensor value=constrain(sensor value,0,255);
}
void calibrate()
{
if (digitalRead(sensorpin) == HIGH) //when a high input is detected at the sensor pin then the motor will start to rotate in clockwise or counterclockwise depending on the revolution completed
clockwise();
else if (digitalRead(sensorpin) == LOW)
wait();
}
speed1 = analogRead(A0); //this is the control pin to control the speed of the motor varying from 0 to 1023
speed1 = speed1 * 0.2492668622; //a default value for the potentiometer
analogWrite(ENA, speed1); //the potentiometer pin A0 will directly control the enable pin or pwm output varying voltage from 0 to 255
}

// put your main code here, to run repeatedly:
[/code]
the program must function in such a way that
whenever the the ir sensor detect a moving obstacle the motor must rotate for 5 second and wait for 5 second
The potentiometer is to control the speed of the dc motor
(firstly i thought of a laser receiving sensor but i couldn’t effort a simulating software for it so i shift to ir sensor
And finally the LDR will control the whole operation of the program
This project is an outdoor project so it must get ‘on’ when there is no light and automatically ‘off’ when there is light
I did the simulation and coding in tinker cad this is what the errors are


Please help me out this is my second project and i really would have to push myself in order to pass this semester, anyone please hear my cry :cry:
please With best regard
Lucky

The code you have in TinkerCad doesn’t match the code you shared here. We’ll never be able to help you if you don’t get more organized.

1 Like

The code that you tried to post is not the code that you posted a picture of. Please do not post pictures of code or error messages

Start by posting your code properly. Select all of it and copy it to the clipboard. Start a new post here, click the </> icon and post your code where indicated. Do the same with the full error messages

1 Like

Sir i just had copy and paste the program i created in the arduino ide to tinker cad how could that be different .
Now i am more confused
What do i do now?

[code]
const int in1 = 8;
const int in2 = 9;
const int ENA = 10;
int speed1;
const int ldrpin=A1;
const int sensorpin = 3;
int timer = 5000;
int sensorMax=1023;
int sensorMin=0;
int sensorvalue=0;
void clockwise()//will help in completing the clockwise motion of the motor by giving one pin of the motor low and the other pin high
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  delay(25000);
}
void counterclockwise()//will help in completing the counterclockwise motion of the motor by giving one pin of the motor low and the other pin high
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  delay(25000);
}
void wait()//the wait interrupt will wait to display the ads on the billboard with the given delay with both the pin of the motor pin going low
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  delay(timer);//as delay time is indicated as timer with 5second
}
void setup()
{
  pinMode(8, OUTPUT); //l298n input pin 1 to arduino pin8
  pinMode(9, OUTPUT); //l298 input pin 2 to the arduino pin 9
  pinMode(10, OUTPUT); //l298n ENABLE pin 1to the arduino 1o pin
  pinMode(3, INPUT);//light sensor input to the arduino pin 3
  pinMode(A1,INPUT);
  Serial.begin(9600);  // put your setup code here, to run once:
}
void loop()
{
  {
  while(analogRead(A1)==LOW)
  {
  calibrate();
}
sensor value=analogRead(A1);
sensor value=map(sensor value,sensorMax,sensorMin,0,255);
sensor value=constrain(sensor value,0,255);
}
void calibrate()
   {
    if (digitalRead(sensorpin) == HIGH) //when a high input is detected at the sensor pin then the motor will start to rotate in clockwise or counterclockwise depending on the revolution completed
      clockwise();
    else if (digitalRead(sensorpin) == LOW)
      wait();
  }
  speed1 = analogRead(A0); //this is the  control pin to control the speed of the motor varying from 0 to 1023
  speed1 = speed1 * 0.2492668622; //a default value for the potentiometer
  analogWrite(ENA, speed1); //the potentiometer pin A0 will directly control the enable pin or pwm output varying voltage from 0 to 255
}


// put your main code here, to run repeatedly:
[/code] is this the way ,Sir! 
I was tense Not knowing what to do much.
But thank you sir for you advice, hopefully will follow you.
With lots of gratitude , From Lucky

The error screen that you posted a picture of has this line in it

pinmode(A1, INPUT);

The code that you posted does not have that line in it. Instead it has

pinMode(A1, INPUT);

They are not the same

Please post you code and error messages as I described in post #3

1 Like

This is the program Sir

[code]
const int in1 = 8;
const int in2 = 9;
const int ENA = 10;
int speed1;
const int ldrpin=A1;
const int sensorpin = 3;
int timer = 5000;
int sensorMax=1023;
int sensorMin=0;
int sensorvalue=0;
void clockwise()//will help in completing the clockwise motion of the motor by giving one pin of the motor low and the other pin high
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  delay(25000);
}
void counterclockwise()//will help in completing the counterclockwise motion of the motor by giving one pin of the motor low and the other pin high
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  delay(25000);
}
void wait()//the wait interrupt will wait to display the ads on the billboard with the given delay with both the pin of the motor pin going low
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  delay(timer);//as delay time is indicated as timer with 5second
}
void setup()
{
  pinMode(8, OUTPUT); //l298n input pin 1 to arduino pin8
  pinMode(9, OUTPUT); //l298 input pin 2 to the arduino pin 9
  pinMode(10, OUTPUT); //l298n ENABLE pin 1to the arduino 1o pin
  pinMode(3, INPUT);//light sensor input to the arduino pin 3
  pinMode(A1,INPUT);
  Serial.begin(9600);  // put your setup code here, to run once:
}
void loop()
{
  {
  while(analogRead(A1)==LOW)
  {
  calibrate();
}
sensor value=analogRead(A1);
sensor value=map(sensor value,sensorMax,sensorMin,0,255);
sensor value=constrain(sensor value,0,255);
}
void calibrate()
   {
    if (digitalRead(sensorpin) == HIGH) //when a high input is detected at the sensor pin then the motor will start to rotate in clockwise or counterclockwise depending on the revolution completed
      clockwise();
    else if (digitalRead(sensorpin) == LOW)
      wait();
  }
  speed1 = analogRead(A0); //this is the  control pin to control the speed of the motor varying from 0 to 1023
  speed1 = speed1 * 0.2492668622; //a default value for the potentiometer
  analogWrite(ENA, speed1); //the potentiometer pin A0 will directly control the enable pin or pwm output varying voltage from 0 to 255
}


// put your main code here, to run repeatedly:
[/code]

[quote="UKHeliBob, post:6, topic:858883"]
Please post you code and error messages as I described in post #3
[/quote]

And this is the errors message
Arduino: 1.8.13 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"





















C:\Users\user\Documents\Arduino\Redha_2_edit\Redha_2_edit.ino: In function 'void loop()':

Redha_2_edit:43:3: error: 'calibrate' was not declared in this scope

   calibrate();

   ^~~~~~~~~

Redha_2_edit:45:1: error: 'sensor' was not declared in this scope

 sensor value=analogRead(A1);

 ^~~~~~

C:\Users\user\Documents\Arduino\Redha_2_edit\Redha_2_edit.ino:45:1: note: suggested alternative: 'sensorMin'

 sensor value=analogRead(A1);

 ^~~~~~

 sensorMin

Redha_2_edit:46:8: error: expected ';' before 'value'

 sensor value=map(sensor value,sensorMax,sensorMin,0,255);

        ^~~~~

Redha_2_edit:47:8: error: expected ';' before 'value'

 sensor value=constrain(sensor value,0,255);

        ^~~~~

Redha_2_edit:50:4: error: a function-definition is not allowed here before '{' token

    {

    ^

exit status 1

'calibrate' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Sir i was in the morning like ( i can do this by my self) now it is evening in India i almost lost hope but you came to rescue 
Thank you so much sir

Where does the loop() function end ?
Have you lost a closing } ?

sensor value=analogRead(A1);
sensor value=map(sensor value,sensorMax,sensorMin,0,255);
sensor value=constrain(sensor value,0,255);

Did you mean sensorvalue rather than sensor value ?

speed1 = analogRead(A0); //this is the  control pin to control the speed of the motor varying from 0 to 1023
speed1 = speed1 * 0.2492668622; //a default value for the potentiometer
analogWrite(ENA, speed1); //the potentiometer pin A0 will directly control the enable pin or pwm output varying voltage from 0 to 255

These 3 lines of code are not in a function but there is an extra } after them. Could it be the one that you lost earlier ?

1 Like

That part of the comment in the program must read the vale of the light intensity falling on the LDR but i am not sure how it must be written ,
any better suggestion can be given

Maybe i will try using this correction too
Thank you so much sir You really make a hope in me
I will try my best today i must make it an errors free with your help

I tried doing simulation in tinkercad but the errors shown are not even related to the line and column of the program i entered i will send a screen shot for you have a look, Sir!

Those three lines are to control the speed of the motor using a potentiometer the input connected to A1 will monitor the ENABLE pin of the l283d motor driver
Is there any alternate for it , waiting for your suggestion?

Don’t confuse the type of input you are sampling.

while(analogRead(A1)==0)

Better still, maybe:

while(analogRead(A1)<=10)


Are you connecting a 9v battery to the Arduino 5v pin ?


How exactly is the LDR connected to the Arduino ?


A schematic of your circuit would go a long way for us to understand what you are doing.

1 Like

No sir , i connected the 5v pin to the LDR

Thank you sir i will try by correcting it .
With lots of gratitude, Lucky

How exactly is the LDR connected to the Arduino ?

A schematic of your circuit would go a long way for us to understand what you are doing.


EDIT

It appears you have the potentiometer connected between the 9v+ and GND.

doing so, can damage the Arduino.

1 Like

the 1st terminal of the LDR is connected to the 5v pin of the arduino and the 2nd terminal is connected to the A1( Analog pin of the arduino)

My schematic must carry out this operation

  1. The motor will rotate displaying some sort of ads (five ads) rotating in clockwise and counterclockwise and will have a delay of 5 second to view the ads ( so people can read the ads) once it complete a displaying ads in clockwise direction it must come in counterclockwise direction again .
  2. the potentiometer is use to adjust the speed of the motor
    3)the rotation and stopping of the motor must be monitor by the ir sensor providing a 5 second delay after a motion or obstacles detected
    3)The LDR is to turn all the whole operation as it most be operated during the evening and night (when there is no present of light)
    Am i doing it correct please suggest me , i need to learnt a lot , and you guys in forum are very helpful and a very good teacher too
    Learning in forum i don’t need to go to university again
    With best regards!
    LUCKY

Let me correct that too ,sir!

You need to connect the LDR as this image shows:

image

R1 is to be selected, depending in your LDR try 1k to 10k.

1 Like

Sure Sir
I have small query is The output of the LDR directly proportional or inversely proportional to the amount of light falling on it?
Thank you so much sir for you guidance i really appreciate it!
Lucky

The resistance of a photoresistor decreases with increase in incident light intensity.


You can connect the LDR two ways.

Voltage decreases with more light:


Voltage increases with light:

1 Like

Thank you so much for the Information, i really would love to be your student ,Sir
With best regard
Lucky

Hi,

Can I suggest you forget trying to get all your code running in a simulator.
GET out your hardware and start coding and testing your hardware in the real world in stages.

You first mission (If you choose to take it Mr Phelps)
Is to connect the LDR up to your controller IN REAL LIFE and write some code to read the analog input you are connecting it to and display that analog reading to the IDE monitor.

This way your first question will be answered.
Then make some code that JUST controls your motor, just back and forth.
Then when you have that working properly, add some speed control.

Just some suggestions… Tom… :grinning: :+1: :coffee: :australia:
PS. TinkerCad may be good for teaching the basics and simple projects, but once you get to this stage, experiment in the real world helps a lot.

1 Like