[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
please With best regard
Lucky
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
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
[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
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 ?
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?
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
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 .
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
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
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...
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.